~ubuntu-branches/ubuntu/wily/sblim-sfcb/wily

« back to all changes in this revision

Viewing changes to sfcBroker.c

  • Committer: Bazaar Package Importer
  • Author(s): Guillaume BOTTEX
  • Date: 2010-06-07 11:27:00 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100607112700-xcihh864agv7gigq
Tags: 1.3.8-0ubuntu1
* New upstream release
* Packaging format changed from 1.0 to 3.0 (quilt)
* Add missing man pages for getSchema and genSslCert
* Add missing binary sfcbinst2mof
* flex and unzip added as dependencies, because needed at build time by
  configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
#include <getopt.h>
46
46
#include <syslog.h>
 
47
#include <pwd.h>
47
48
 
48
49
#ifdef HAVE_CONFIG_H
49
50
#include "config.h"
50
51
#endif
51
52
 
52
 
#ifdef HAVE_SLP
53
 
#include "cimslp.h"
54
 
static int startSLP = 1;
55
 
#endif
56
 
 
57
 
#ifdef LOCAL_CONNECT_ONLY_ENABLE
58
 
// from httpAdapter.c
59
53
int sfcBrokerPid=0;
60
 
#endif // LOCAL_CONNECT_ONLY_ENABLE
61
 
 
62
 
//#define USE_THREADS
63
 
 
64
 
// for use by thread in startHttpd, startDbpd
65
 
struct adapterThreadParams {
66
 
  int argc;
67
 
  char* argv;
68
 
  int sslMode;
69
 
  int sfcPid;
70
 
};
71
54
 
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();
81
64
 
82
65
extern int stopNextProc();
88
71
extern void uninitGarbageCollector();
89
72
 
90
73
extern TraceId traceIds[];
91
 
extern int sfcBrokerPid;
92
74
 
93
75
extern unsigned long exFlags;
94
76
static int startHttp = 0;
167
149
   return 0;
168
150
}
169
151
 
170
 
 
171
 
#ifdef USE_THREADS
172
 
// thread-based adapter functions
173
 
 
174
 
static void addStartedThreadAdapter(pthread_t tid)
175
 
{
176
 
 
177
 
   StartedThreadAdapter *sa=(StartedThreadAdapter*)malloc(sizeof(StartedThreadAdapter));
178
 
 
179
 
   sa->stopped=0;
180
 
   sa->tid=tid;
181
 
   sa->next=lastStartedThreadAdapter;
182
 
   lastStartedThreadAdapter=sa;
183
 
}
184
 
 
185
 
static int testStartedThreadAdapter(pthread_t tid, int *left) 
186
 
{
187
 
   StartedThreadAdapter *sa=lastStartedThreadAdapter;
188
 
   int stopped=0;
189
 
   
190
 
   *left=0;
191
 
   while (sa) {
192
 
     if (pthread_equal(sa->tid, tid)) stopped=sa->stopped=1;
193
 
      if (sa->stopped==0) (*left)++;
194
 
      sa=sa->next;
195
 
   }
196
 
   return stopped;
197
 
}         
198
 
 
199
 
static int stopNextThreadAdapter()
200
 
{
201
 
   StartedThreadAdapter *sa=lastStartedThreadAdapter;
202
 
   
203
 
   while (sa) {
204
 
      if (sa->stopped==0) {
205
 
         sa->stopped=1;
206
 
         pthread_exit(sa->tid);
207
 
         return sa->tid;
208
 
      }   
209
 
      sa=sa->next;
210
 
   }
211
 
   return 0;
212
 
}
213
 
#endif
214
 
 
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;
265
202
   uninitSocketPairs();
266
203
   sunsetControl();
267
204
//   uninitGarbageCollector();
268
 
   
 
205
   closeLogging();
 
206
 
269
207
   if (restartBroker) {
270
208
      char *emsg=strerror(errno);
271
209
      execvp("sfcbd",restartArgv);
406
344
 
407
345
 
408
346
#ifndef LOCAL_CONNECT_ONLY_ENABLE
409
 
#ifdef USE_THREADS
410
 
void* startHttpThread(void* params) {
411
 
  struct adapterThreadParams* p = (struct adapterThreadParams*)params;
412
 
  currentProc=getpid();
413
 
 
414
 
  httpDaemon(p->argc, p->argv, p->sslMode, p->sfcPid);
415
 
  closeSocket(&sfcbSockets,cRcv,"startHttpd");
416
 
  closeSocket(&resultSockets,cAll,"startHttpd");
417
 
 
418
 
}
419
 
#endif
420
347
 
421
348
static int startHttpd(int argc, char *argv[], int sslMode)
422
349
{
423
 
#ifdef USE_THREADS
424
 
 
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);
430
 
 
431
 
   pthread_yield();
432
 
 
433
 
   addStartedThreadAdapter(httpThread);
434
 
 
435
 
#else
436
 
 
437
 
   int pid,sfcPid=currentProc;
 
350
   int pid,sfcPid=currentProc;
 
351
   int httpSFCB,rc;
 
352
   char *httpUser;
 
353
   uid_t httpuid;
 
354
   struct passwd *passwd;
 
355
 
 
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");
 
359
     exit(2);
 
360
   } 
 
361
   if (httpSFCB) {
 
362
     // This indicates that we should use the SFCB user by default
 
363
     httpuid = -1;
 
364
   } else {
 
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");
 
368
        exit(2);
 
369
     } else {
 
370
        errno=0;
 
371
        passwd=getpwnam(httpUser);
 
372
        if (passwd) {
 
373
            httpuid=passwd->pw_uid;
 
374
        } else {
 
375
            mlogf(M_ERROR,M_SHOW,"--- Couldn't find http username %s requested in SFCB config file. Errno: %d\n",httpUser,errno);
 
376
            exit(2);
 
377
        }
 
378
     }
 
379
    }
438
380
 
439
381
   pid= fork();
440
382
   if (pid < 0) {
444
386
   }
445
387
   if (pid == 0) {
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);
 
392
          if (rc == -1) {
 
393
              mlogf(M_ERROR,M_SHOW,"--- Changing uid for http failed.\n");
 
394
              exit(2);
 
395
          }
 
396
      }
 
397
   
 
398
      if (httpDaemon(argc, argv, sslMode)) {
 
399
        kill(sfcPid, 3);          /* if port in use, shutdown */
 
400
      }
448
401
      closeSocket(&sfcbSockets,cRcv,"startHttpd");
449
402
      closeSocket(&resultSockets,cAll,"startHttpd");
450
403
   }
452
405
      addStartedAdapter(pid);
453
406
      return 0;
454
407
   }
455
 
#endif
456
408
   return 0;
457
409
}
458
410
 
485
437
 
486
438
#endif
487
439
 
488
 
#ifdef HAVE_SLP
489
 
 
490
 
static int startSLPAgent()
491
 
{
492
 
    slpAgent();
493
 
    return 0;
494
 
}
495
 
 
496
 
#endif
497
 
 
498
440
static void usage(int status)
499
441
{
500
442
    if (status != 0)
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",
522
465
                "",
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' },
583
527
           { 0, 0, 0, 0 }
584
528
       };
585
529
 
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)
587
531
   {
588
532
       switch(c)
589
533
       {
628
572
           case 'v':
629
573
               version();
630
574
 
 
575
           case 'i':
 
576
               disableDefaultProvider=1;
 
577
               break;
 
578
 
631
579
           case 'l':
632
580
            if (strcmp(optarg,"LOG_ERR")==0) {
633
581
                syslogLevel=LOG_ERR;
645
593
               usage(3);
646
594
       }
647
595
   }
648
 
   startLogging("sfcb",syslogLevel);
 
596
 
 
597
   if (optind < argc)
 
598
   {
 
599
      fprintf(stderr,"SFCB not started: unrecognized config property %s\n",argv[optind]);
 
600
      usage(1);
 
601
   }
 
602
 
 
603
   startLogging(syslogLevel);
649
604
 
650
605
   mlogf(M_INFO,M_SHOW,"--- %s V" sfcHttpDaemonVersion " started - %d\n", name, currentProc);
651
606
 
762
717
           "--- Max provider process number adjusted to %d\n", pSockets);
763
718
   }
764
719
 
765
 
   if ((enableHttp && dSockets > 0) || (enableHttps && sSockets > 0) ) {
 
720
   if ((enableHttp || enableHttps) && dSockets > 0) {
766
721
     startHttp = 1;
767
722
   }
768
723
   
769
724
   initSem(dSockets,sSockets,pSockets);
770
725
   initProvProcCtl(pSockets);
771
 
   init_sfcBroker(NULL);
 
726
   init_sfcBroker();
772
727
   initSocketPairs(pSockets,dSockets,sSockets);
773
728
 
774
729
   setSignal(SIGQUIT, handleSigquit,0);
783
738
   
784
739
#ifndef LOCAL_CONNECT_ONLY_ENABLE
785
740
   if (startHttp) {
786
 
      if (sslMode)
787
 
         startHttpd(argc, argv,1);
788
 
      if (!sslOMode)
789
 
         startHttpd(argc, argv,0);
 
741
     startHttpd(argc, argv, sslMode);
790
742
   }
791
743
#endif // LOCAL_CONNECT_ONLY_ENABLE
792
744
   
801
753
#endif  
802
754
 
803
755
 
804
 
#ifdef HAVE_SLP
805
 
   //Start SLP Agent
806
 
   if (startSLP) {
807
 
                startSLPAgent();
808
 
   }
809
 
#endif
810
 
   
811
756
   setSignal(SIGSEGV, handleSigSegv,SA_ONESHOT);
812
757
   setSignal(SIGCHLD, handleSigChld,0);
813
758