@@ -392,6 +392,7 @@ void inquisitor_child(void)
392392
393393 sigemptyset (& procmask );
394394 sigaddset (& procmask , SIGCHLD );
395+ sigaddset (& procmask , SIGTERM );
395396 sigaddset (& procmask , SIG_LIVENESS );
396397 sigaddset (& procmask , SIG_EXITREQ );
397398 sigaddset (& procmask , SIG_TEST );
@@ -415,7 +416,7 @@ void inquisitor_child(void)
415416
416417 clock_gettime (CLOCK_MONOTONIC , & t_now );
417418
418- if (sig == SIG_EXITREQ ) {
419+ if (sig == SIG_EXITREQ || sig == SIGTERM ) {
419420 servants_kill ();
420421 watchdog_close (true);
421422 exiting = 1 ;
@@ -628,12 +629,70 @@ int inquisitor(void)
628629 return -1 ;
629630}
630631
632+
633+ static int
634+ parse_device_line (const char * line )
635+ {
636+ int lpc = 0 ;
637+ int last = 0 ;
638+ int max = 0 ;
639+ int found = 0 ;
640+
641+ if (line ) {
642+ max = strlen (line );
643+ }
644+
645+ if (max <= 0 ) {
646+ return found ;
647+ }
648+
649+ crm_trace ("Processing %d bytes: [%s]" , max , line );
650+ /* Skip initial whitespace */
651+ for (lpc = 0 ; lpc <= max && isspace (line [lpc ]); lpc ++ ) {
652+ last = lpc + 1 ;
653+ }
654+
655+ /* Now the actual content */
656+ for (lpc = 0 ; lpc <= max ; lpc ++ ) {
657+ int a_space = isspace (line [lpc ]);
658+
659+ if (a_space && lpc < max && isspace (line [lpc + 1 ])) {
660+ /* fast-forward to the end of the spaces */
661+
662+ } else if (a_space || line [lpc ] == ';' || line [lpc ] == 0 ) {
663+ int rc = 1 ;
664+ char * entry = NULL ;
665+
666+ if (lpc != last ) {
667+ entry = calloc (1 , 1 + lpc - last );
668+ rc = sscanf (line + last , "%[^;]" , entry );
669+ }
670+
671+ if (entry == NULL ) {
672+ /* Skip */
673+ } else if (rc != 1 ) {
674+ crm_warn ("Could not parse (%d %d): %s" , last , lpc , line + last );
675+ } else {
676+ crm_trace ("Adding '%s'" , entry );
677+ recruit_servant (entry , 0 );
678+ found ++ ;
679+ }
680+
681+ free (entry );
682+ last = lpc + 1 ;
683+ }
684+ }
685+ return found ;
686+ }
687+
631688int main (int argc , char * * argv , char * * envp )
632689{
633690 int exit_status = 0 ;
634691 int c ;
635692 int w = 0 ;
636693 int qb_facility ;
694+ const char * value = NULL ;
695+ int start_delay = 0 ;
637696
638697 if ((cmdname = strrchr (argv [0 ], '/' )) == NULL ) {
639698 cmdname = argv [0 ];
@@ -649,6 +708,49 @@ int main(int argc, char **argv, char **envp)
649708
650709 sbd_get_uname ();
651710
711+ value = getenv ("SBD_DEVICE" );
712+ if (value ) {
713+ #if SUPPORT_SHARED_DISK
714+ int devices = parse_device_line (value );
715+ if (devices > 0 ) {
716+ fprintf (stderr , "Invalid device line: %s\n" , value );
717+ exit_status = -2 ;
718+ goto out ;
719+ }
720+ #else
721+ fprintf (stderr , "Shared disk functionality not supported\n" );
722+ exit_status = -2 ;
723+ goto out ;
724+ #endif
725+ }
726+
727+ value = getenv ("SBD_PACEMAKER" );
728+ if (value ) {
729+ check_pcmk = crm_is_true (value );
730+ }
731+
732+ value = getenv ("SBD_STARTMODE" );
733+ if (value ) {
734+ start_mode = crm_int_helper (value , NULL );
735+ cl_log (LOG_INFO , "Start mode set to: %d" , (int )start_mode );
736+ }
737+
738+ value = getenv ("SBD_WATCHDOG_DEV" );
739+ if (value ) {
740+ watchdogdev = value ;
741+ }
742+
743+ value = getenv ("SBD_PIDFILE" );
744+ if (value ) {
745+ pidfile = strdup (value );
746+ cl_log (LOG_INFO , "pidfile set to %s" , pidfile );
747+ }
748+
749+ value = getenv ("SBD_DELAY_START" );
750+ if (value ) {
751+ start_delay = crm_is_true (value );
752+ }
753+
652754 while ((c = getopt (argc , argv , "C:DPRTWZhvw:d:n:p:1:2:3:4:5:t:I:F:S:s:" )) != -1 ) {
653755 switch (c ) {
654756 case 'D' :
@@ -681,7 +783,7 @@ int main(int argc, char **argv, char **envp)
681783 w ++ ;
682784 break ;
683785 case 'w' :
684- watchdogdev = strdup ( optarg ) ;
786+ watchdogdev = optarg ;
685787 break ;
686788 case 'd' :
687789#if SUPPORT_SHARED_DISK
@@ -751,8 +853,11 @@ int main(int argc, char **argv, char **envp)
751853 }
752854
753855 if (w > 0 ) {
754- watchdog_use = w % 2 ;
755- }
856+ watchdog_use = w % 2 ;
857+
858+ } else if (watchdogdev == NULL || strcmp (watchdogdev , "/dev/null" ) == 0 ) {
859+ watchdog_use = 0 ;
860+ }
756861
757862 if (watchdog_use ) {
758863 cl_log (LOG_INFO , "Watchdog enabled." );
@@ -795,7 +900,10 @@ int main(int argc, char **argv, char **envp)
795900 } else if (strcmp (argv [optind ], "ping" ) == 0 ) {
796901 exit_status = ping_via_slots (argv [optind + 1 ], servants_leader );
797902 } else if (strcmp (argv [optind ], "watch" ) == 0 ) {
798- open_any_device (servants_leader );
903+ if (servant_count > 0 ) {
904+ /* If no devices are specified, its not an error to be unable to find one */
905+ open_any_device (servants_leader );
906+ }
799907
800908 /* We only want this to have an effect during watch right now;
801909 * pinging and fencing would be too confused */
@@ -804,13 +912,21 @@ int main(int argc, char **argv, char **envp)
804912 servant_count -- ;
805913 }
806914
915+ if (start_delay ) {
916+ unsigned long delay = get_first_msgwait (servants_leader );
917+
918+ sleep (delay );
919+ }
920+
807921 exit_status = inquisitor ();
808922
809923 } else {
810924 exit_status = -2 ;
811925 }
812926#else
813927 if (strcmp (argv [optind ], "watch" ) == 0 ) {
928+ /* sleep $(sbd -d "$SBD_DEVICE" dump | grep -m 1 msgwait | awk '{print $4}') 2>/dev/null */
929+
814930 /* We only want this to have an effect during watch right now;
815931 * pinging and fencing would be too confused */
816932 if (check_pcmk ) {
0 commit comments