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