45
45
#include <getopt.h>
46
46
#include <syslog.h>
48
49
#ifdef HAVE_CONFIG_H
49
50
#include "config.h"
54
static int startSLP = 1;
57
#ifdef LOCAL_CONNECT_ONLY_ENABLE
59
53
int sfcBrokerPid=0;
60
#endif // LOCAL_CONNECT_ONLY_ENABLE
64
// for use by thread in startHttpd, startDbpd
65
struct adapterThreadParams {
72
55
extern void setExFlag(unsigned long f);
73
56
extern char *parseTarget(const char *target);
74
57
extern UtilStringBuffer *instanceToString(CMPIInstance * ci, char **props);
75
extern int init_sfcBroker(char *);
58
extern int init_sfcBroker();
76
59
extern CMPIBroker *Broker;
77
60
extern void initProvProcCtl(int);
78
61
extern void processTerminated(int pid);
79
extern int httpDaemon(int argc, char *argv[], int sslMode, int pid);
62
extern int httpDaemon(int argc, char *argv[], int sslMode);
80
63
extern void processProviderMgrRequests();
82
65
extern int stopNextProc();
172
// thread-based adapter functions
174
static void addStartedThreadAdapter(pthread_t tid)
177
StartedThreadAdapter *sa=(StartedThreadAdapter*)malloc(sizeof(StartedThreadAdapter));
181
sa->next=lastStartedThreadAdapter;
182
lastStartedThreadAdapter=sa;
185
static int testStartedThreadAdapter(pthread_t tid, int *left)
187
StartedThreadAdapter *sa=lastStartedThreadAdapter;
192
if (pthread_equal(sa->tid, tid)) stopped=sa->stopped=1;
193
if (sa->stopped==0) (*left)++;
199
static int stopNextThreadAdapter()
201
StartedThreadAdapter *sa=lastStartedThreadAdapter;
204
if (sa->stopped==0) {
206
pthread_exit(sa->tid);
215
152
static pthread_mutex_t sdMtx=PTHREAD_MUTEX_INITIALIZER;
216
153
static pthread_cond_t sdCnd=PTHREAD_COND_INITIALIZER;
217
154
static int stopping=0;
408
346
#ifndef LOCAL_CONNECT_ONLY_ENABLE
410
void* startHttpThread(void* params) {
411
struct adapterThreadParams* p = (struct adapterThreadParams*)params;
412
currentProc=getpid();
414
httpDaemon(p->argc, p->argv, p->sslMode, p->sfcPid);
415
closeSocket(&sfcbSockets,cRcv,"startHttpd");
416
closeSocket(&resultSockets,cAll,"startHttpd");
421
348
static int startHttpd(int argc, char *argv[], int sslMode)
425
int pid,sfcPid=currentProc;
426
struct adapterThreadParams htparams = {argc, argv, sslMode, sfcPid};
427
pthread_t httpThread;
428
pthread_create(&httpThread, NULL, &startHttpThread, &htparams);
429
//newThread(&startHttpThread, &htparams, 0);
433
addStartedThreadAdapter(httpThread);
437
int pid,sfcPid=currentProc;
350
int pid,sfcPid=currentProc;
354
struct passwd *passwd;
356
// Get/check http user info
357
if (getControlBool("httpUserSFCB",&httpSFCB)) {
358
mlogf(M_ERROR,M_SHOW,"--- Error retrieving http user info from config file.\n");
362
// This indicates that we should use the SFCB user by default
365
// Get the user specified in the config file
366
if (getControlChars("httpUser",&httpUser)) {
367
mlogf(M_ERROR,M_SHOW,"--- Error retrieving http user info from config file.\n");
371
passwd=getpwnam(httpUser);
373
httpuid=passwd->pw_uid;
375
mlogf(M_ERROR,M_SHOW,"--- Couldn't find http username %s requested in SFCB config file. Errno: %d\n",httpUser,errno);
446
388
currentProc=getpid();
447
httpDaemon(argc, argv, sslMode, sfcPid);
389
if (httpuid != -1 ) {
390
// Set the real and effective uids
391
rc=setreuid(httpuid,httpuid);
393
mlogf(M_ERROR,M_SHOW,"--- Changing uid for http failed.\n");
398
if (httpDaemon(argc, argv, sslMode)) {
399
kill(sfcPid, 3); /* if port in use, shutdown */
448
401
closeSocket(&sfcbSockets,cRcv,"startHttpd");
449
402
closeSocket(&resultSockets,cAll,"startHttpd");
519
461
" components to trace; ? lists the available",
520
462
" components with their bitmask and exits",
521
463
" -v, --version output version information and exit",
464
" -i, --disable-repository-default-inst-prov To disable entry into the default provider",
523
466
"For SBLIM package updates and additional information, please see",
524
467
" the SBLIM homepage at http://sblim.sourceforge.net"
580
523
{ "syslog-level", required_argument, 0, 'l' },
581
524
{ "trace-components", required_argument, 0, 't' },
582
525
{ "version", no_argument, 0, 'v' },
526
{ "disable-repository-default-inst-provider", no_argument, 0, 'i' },
586
while ((c = getopt_long(argc, argv, "c:dhkst:vl:", long_options, 0)) != -1)
530
while ((c = getopt_long(argc, argv, "c:dhkst:vil:", long_options, 0)) != -1)
648
startLogging("sfcb",syslogLevel);
599
fprintf(stderr,"SFCB not started: unrecognized config property %s\n",argv[optind]);
603
startLogging(syslogLevel);
650
605
mlogf(M_INFO,M_SHOW,"--- %s V" sfcHttpDaemonVersion " started - %d\n", name, currentProc);
762
717
"--- Max provider process number adjusted to %d\n", pSockets);
765
if ((enableHttp && dSockets > 0) || (enableHttps && sSockets > 0) ) {
720
if ((enableHttp || enableHttps) && dSockets > 0) {
769
724
initSem(dSockets,sSockets,pSockets);
770
725
initProvProcCtl(pSockets);
771
init_sfcBroker(NULL);
772
727
initSocketPairs(pSockets,dSockets,sSockets);
774
729
setSignal(SIGQUIT, handleSigquit,0);
784
739
#ifndef LOCAL_CONNECT_ONLY_ENABLE
787
startHttpd(argc, argv,1);
789
startHttpd(argc, argv,0);
741
startHttpd(argc, argv, sslMode);
791
743
#endif // LOCAL_CONNECT_ONLY_ENABLE