@@ -658,53 +658,53 @@ struct command_s {
658
658
static void
659
659
help (void )
660
660
{
661
- close (2 );
662
- g_print ("\n COMMANDS:\n" );
663
- g_print (" status* : Displays the status of the given processes or groups\n" );
664
- g_print (" start : Starts the given processes or groups, even if broken\n" );
665
- g_print (" kill : Stops the given processes or groups, they won't be automatically\n" );
666
- g_print (" restarted even after a configuration reload\n" );
667
- g_print (" stop : Calls 'kill' until the children exit\n" );
668
- g_print (" restart : Restarts the given processes or groups\n" );
669
- g_print (" reload : Reloads the configuration, stopping obsolete processes, starting\n" );
670
- g_print (" the newly discovered. Broken or stopped processes are not restarted\n" );
671
- g_print (" repair : Removes the broken flag set on a process. Start must be called to\n" );
672
- g_print (" restart the process.\n" );
673
- g_print ("with ID the key of a process, or '@GROUP', with GROUP the name of a process\n" );
674
- g_print ("group\n" );
661
+
675
662
close (1 );
676
663
exit (0 );
677
664
}
678
665
666
+ static void
667
+ usage (void )
668
+ {
669
+ GOptionContext * context ;
670
+ gchar description [] =
671
+ "\n COMMANDS:\n"
672
+ " status* : Displays the status of the given processes or groups\n"
673
+ " start : Starts the given processes or groups, even if broken\n"
674
+ " kill : Stops the given processes or groups, they won't be automatically\n"
675
+ " restarted even after a configuration reload\n"
676
+ " stop : Calls 'kill' until the children exit\n"
677
+ " restart : Restarts the given processes or groups\n"
678
+ " reload : Reloads the configuration, stopping obsolete processes, starting\n"
679
+ " the newly discovered. Broken or stopped processes are not restarted\n"
680
+ " repair : Removes the broken flag set on a process. Start must be called to\n"
681
+ " restart the process.\n"
682
+ "with ID the key of a process, or '@GROUP', with GROUP the name of a process\n"
683
+ "group\n" ;
684
+ context = g_option_context_new ("(status{,2,3}|start|stop|reload|repair) [ID...]\n" );
685
+ g_option_context_add_main_entries (context , entries , NULL );
686
+ g_option_context_set_summary (context , description );
687
+ gchar * usage = g_option_context_get_help (context , TRUE, NULL );
688
+ g_print ("%s" , usage );
689
+ }
690
+
679
691
static int
680
692
main_options (int argc , char * * args )
681
693
{
682
694
GError * error = NULL ;
683
695
GOptionContext * context ;
684
696
685
697
sock_path = g_strdup (GRIDINIT_SOCK_PATH );
686
-
687
698
context = g_option_context_new ("(status{,2,3}|start|stop|reload|repair) [ID...]\n" );
688
699
g_option_context_add_main_entries (context , entries , NULL );
689
- if (!g_option_context_parse (context , & argc , & args , & error )) {
700
+ if (!g_option_context_parse (context , & argc , & args , & error )) {
690
701
g_print ("option parsing failed: %s\n" , error -> message );
691
- gchar * usage = g_option_context_get_help (context , TRUE, NULL );
692
- g_print ("%s" , usage );
693
- help ();
694
702
}
695
703
696
704
return argc ;
697
705
}
698
706
699
- static void
700
- usage (void )
701
- {
702
- GOptionContext * context ;
703
- context = g_option_context_new ("(status{,2,3}|start|stop|reload|repair) [ID...]\n" );
704
- gchar * usage = g_option_context_get_help (context , TRUE, NULL );
705
- g_print ("%s" , usage );
706
- help ();
707
- }
707
+
708
708
int
709
709
main (int argc , char * * args )
710
710
{
@@ -724,7 +724,12 @@ main(int argc, char ** args)
724
724
close (2 );
725
725
return 0 ;
726
726
}
727
-
727
+ if (!args [opt_index ]) {
728
+ usage ();
729
+ close (1 );
730
+ close (2 );
731
+ return 1 ;
732
+ }
728
733
for (cmd = COMMANDS ; cmd -> name ;cmd ++ ) {
729
734
if (0 == g_ascii_strcasecmp (cmd -> name , args [opt_index ])) {
730
735
int rc = cmd -> action (argc - (opt_index + 1 ), args + (opt_index + 1 ));
@@ -733,7 +738,7 @@ main(int argc, char ** args)
733
738
return rc ;
734
739
}
735
740
}
736
-
741
+ usage ();
737
742
close (1 );
738
743
close (2 );
739
744
return 1 ;
0 commit comments