aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-12-18 18:01:05 +0000
committerRoy Marples <roy@marples.name>2007-12-18 18:01:05 +0000
commit47887ac7c340639c9c6b7bf4379a1940f3e01b6c (patch)
treec5febe0cf89b4088aa5ce3b648b153cb85752a8b /src
parent437363a3449423173bc94746a122fbf3b4cf254c (diff)
usage now requires a global applet var instead of a define, don't prefix describe output and use generic usage for runscript.
Diffstat (limited to 'src')
-rw-r--r--src/_usage.c3
-rw-r--r--src/_usage.h2
-rw-r--r--src/fstabinfo.c6
-rw-r--r--src/mountinfo.c9
-rw-r--r--src/rc-status.c2
-rw-r--r--src/rc-update.c9
-rw-r--r--src/runscript.c34
7 files changed, 34 insertions, 31 deletions
diff --git a/src/_usage.c b/src/_usage.c
index 088ccb48..ce733a97 100644
--- a/src/_usage.c
+++ b/src/_usage.c
@@ -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);
}
-
diff --git a/src/_usage.h b/src/_usage.h
index ba09255c..e4a5fa3b 100644
--- a/src/_usage.h
+++ b/src/_usage.h
@@ -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"
diff --git a/src/fstabinfo.c b/src/fstabinfo.c
index 08c2b0b9..9782f9da 100644
--- a/src/fstabinfo.c
+++ b/src/fstabinfo.c
@@ -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");
diff --git a/src/mountinfo.c b/src/mountinfo.c
index a55bf4fd..ad76d32d 100644
--- a/src/mountinfo.c
+++ b/src/mountinfo.c
@@ -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");
diff --git a/src/rc-status.c b/src/rc-status.c
index bf4d63d3..155192fa 100644
--- a/src/rc-status.c
+++ b/src/rc-status.c
@@ -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 };
diff --git a/src/rc-update.c b/src/rc-update.c
index 7c611d3c..3ab52fd1 100644
--- a/src/rc-update.c
+++ b/src/rc-update.c
@@ -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) ||
diff --git a/src/runscript.c b/src/runscript.c
index 108512ae..c52b33ea 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -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",