usage now requires a global applet var instead of a define, don't prefix describe output and use generic usage for runscript.
This commit is contained in:
		| @@ -29,7 +29,7 @@ static void usage (int exit_status) | ||||
| { | ||||
| 	const char * const has_arg[] = { "", "<arg>", "[arg]" }; | ||||
| 	int i; | ||||
| 	printf ("Usage: " APPLET " [options] "); | ||||
| 	printf ("Usage: %s [options] ", applet); | ||||
| #ifdef extraopts | ||||
| 	printf (extraopts); | ||||
| #endif | ||||
| @@ -52,4 +52,3 @@ static void usage (int exit_status) | ||||
| 	} | ||||
| 	exit (exit_status); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -34,7 +34,7 @@ | ||||
| 	{ NULL,             0, NULL,  0 } | ||||
|  | ||||
| #define longopts_help_COMMON \ | ||||
| 	"Display this help output (duh)", \ | ||||
| 	"Display this help output", \ | ||||
| 	"Disable color output", \ | ||||
| 	"Run verbosely", \ | ||||
| 	"Run quietly" | ||||
|   | ||||
| @@ -29,8 +29,6 @@ | ||||
|  * SUCH DAMAGE. | ||||
|  */ | ||||
|  | ||||
| #define APPLET "fstabinfo" | ||||
|  | ||||
| #include <errno.h> | ||||
| #include <getopt.h> | ||||
| #include <libgen.h> | ||||
| @@ -89,6 +87,8 @@ static struct mntent *getmntfile (const char *file) | ||||
| } | ||||
| #endif | ||||
|  | ||||
| static const char *applet; | ||||
|  | ||||
| #include "_usage.h" | ||||
| #define getoptstring "bmop:t:" getoptstring_COMMON | ||||
| static struct option longopts[] = { | ||||
| @@ -129,6 +129,8 @@ int fstabinfo (int argc, char **argv) | ||||
| 	char *file; | ||||
| 	bool filtered = false; | ||||
|  | ||||
| 	applet = basename (argv[0]); | ||||
|  | ||||
| 	/* Ensure that we are only quiet when explicitly told to be */ | ||||
| 	unsetenv ("EINFO_QUIET"); | ||||
|  | ||||
|   | ||||
| @@ -29,8 +29,6 @@ | ||||
|  * SUCH DAMAGE. | ||||
|  */ | ||||
|  | ||||
| #define APPLET "mountinfo" | ||||
|  | ||||
| #include <sys/types.h> | ||||
|  | ||||
| #if defined(__DragonFly__) || defined(__FreeBSD__) || \ | ||||
| @@ -45,6 +43,7 @@ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include <getopt.h> | ||||
| #include <libgen.h> | ||||
| #include <limits.h> | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| @@ -57,6 +56,8 @@ | ||||
| #include "rc-misc.h" | ||||
| #include "strlist.h" | ||||
|  | ||||
| static const char *applet; | ||||
|  | ||||
| typedef enum { | ||||
| 	mount_from, | ||||
| 	mount_to, | ||||
| @@ -311,7 +312,7 @@ static regex_t *get_regex (const char *string) | ||||
| 	if ((result = regcomp (reg, string, REG_EXTENDED | REG_NOSUB)) != 0) | ||||
| 	{ | ||||
| 		regerror (result, reg, buffer, sizeof (buffer)); | ||||
| 		eerrorx ("%s: invalid regex `%s'", APPLET, buffer); | ||||
| 		eerrorx ("%s: invalid regex `%s'", applet, buffer); | ||||
| 	} | ||||
|  | ||||
| 	return (reg); | ||||
| @@ -366,6 +367,8 @@ int mountinfo (int argc, char **argv) | ||||
| 	int result; | ||||
| 	bool quiet; | ||||
|  | ||||
| 	applet = basename (argv[0]); | ||||
|  | ||||
| 	/* Ensure that we are only quiet when explicitly told to be */ | ||||
| 	unsetenv ("EINFO_QUIET"); | ||||
|  | ||||
|   | ||||
| @@ -41,7 +41,7 @@ | ||||
| #include "rc-misc.h" | ||||
| #include "strlist.h" | ||||
|  | ||||
| #define APPLET "rc-status" | ||||
| static const char *applet; | ||||
|  | ||||
| static const char *types_nua[] = { "ineed", "iuse", "iafter", NULL }; | ||||
|  | ||||
|   | ||||
| @@ -146,9 +146,9 @@ static const char * const longopts_help[] = { | ||||
| }; | ||||
| #include "_usage.c" | ||||
|  | ||||
| #define DOADD    (1 << 0) | ||||
| #define DODELETE (1 << 1) | ||||
| #define DOSHOW   (1 << 2) | ||||
| #define DOADD    (1 << 1) | ||||
| #define DODELETE (1 << 2) | ||||
| #define DOSHOW   (1 << 3) | ||||
|  | ||||
| int rc_update (int argc, char **argv) | ||||
| { | ||||
| @@ -181,6 +181,9 @@ int rc_update (int argc, char **argv) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (! action) | ||||
| 		usage (EXIT_FAILURE); | ||||
|  | ||||
| 	verbose = rc_yesno (getenv ("EINFO_VERBOSE")); | ||||
|  | ||||
| 	if ((action & DOSHOW   && action != DOSHOW) || | ||||
|   | ||||
| @@ -1024,6 +1024,7 @@ static void svc_restart (bool deps) | ||||
|  | ||||
| #include "_usage.h" | ||||
| #define getoptstring "dDsv" getoptstring_COMMON | ||||
| #define extraopts "stop | start | restart | describe | zap" | ||||
| static struct option longopts[] = { | ||||
| 	{ "debug",      0, NULL, 'd'}, | ||||
| 	{ "ifstarted",  0, NULL, 's'}, | ||||
| @@ -1031,15 +1032,11 @@ static struct option longopts[] = { | ||||
| 	longopts_COMMON | ||||
| }; | ||||
| static const char * const longopts_help[] = { | ||||
| 	"", | ||||
| 	"", | ||||
| 	"", | ||||
| 	"set xtrace when running the script", | ||||
| 	"only run commands when started", | ||||
| 	"ignore dependencies", | ||||
| 	longopts_help_COMMON | ||||
| }; | ||||
| #undef case_RC_COMMON_getopt_case_h | ||||
| #define case_RC_COMMON_getopt_case_h \ | ||||
| 	execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); \ | ||||
| eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", applet, strerror (errno)); | ||||
| #include "_usage.c" | ||||
|  | ||||
| int runscript (int argc, char **argv) | ||||
| @@ -1053,13 +1050,15 @@ int runscript (int argc, char **argv) | ||||
| 	char *svc; | ||||
|  | ||||
| 	/* Show help if insufficient args */ | ||||
| 	if (argc < 2) { | ||||
| 		execl (RCSCRIPT_HELP, RCSCRIPT_HELP, (char *) NULL); | ||||
| 		eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", argv[0], | ||||
| 				 strerror (errno)); | ||||
| 	if (argc < 2 || ! exists (argv[1])) { | ||||
| 		fprintf (stderr, "runscript is not meant to be to run directly\n"); | ||||
| 		exit (EXIT_FAILURE); | ||||
| 	} | ||||
|  | ||||
| 	applet = xstrdup (basename (argv[1])); | ||||
| 	if (argc < 3) | ||||
| 		usage (EXIT_FAILURE); | ||||
|  | ||||
| 	if (*argv[1] == '/') | ||||
| 		service = xstrdup (argv[1]); | ||||
| 	else { | ||||
| @@ -1075,14 +1074,6 @@ int runscript (int argc, char **argv) | ||||
| 	/* Change dir to / to ensure all init scripts don't use stuff in pwd */ | ||||
| 	chdir ("/"); | ||||
|  | ||||
| 	/* Show help if insufficient args */ | ||||
| 	if (argc < 3) { | ||||
| 		setenv ("SVCNAME", applet, 1); | ||||
| 		execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); | ||||
| 		eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", | ||||
| 				 applet, strerror (errno)); | ||||
| 	} | ||||
|  | ||||
| #ifdef __linux__ | ||||
| 	/* coldplug events can trigger init scripts, but we don't want to run them | ||||
| 	   until after rc sysinit has completed so we punt them to the boot runlevel */ | ||||
| @@ -1240,7 +1231,12 @@ int runscript (int argc, char **argv) | ||||
| 		doneone = true; | ||||
|  | ||||
| 		if (strcmp (optarg, "describe") == 0) { | ||||
| 			char *save = prefix; | ||||
|  | ||||
| 			eprefix (NULL); | ||||
| 			prefix = NULL; | ||||
| 			svc_exec (optarg, NULL); | ||||
| 			eprefix (save); | ||||
| 		} else if (strcmp (optarg, "help") == 0) { | ||||
| 			execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL); | ||||
| 			eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user