From d81def80b00a3dbcb4f8980f4503c4d659b48a2a Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 23 Nov 2007 12:04:11 +0000 Subject: Move /etc/conf.d/rc to /etc/rc.conf. Lowercase all configurable variables, non configurations remain uppercase. Replace rc_env_bool with rc_yesno. Split localmount info procfs (Linux) and dumpon, savecore (BSD) --- src/fstabinfo.c | 2 +- src/librc-misc.c | 29 +++++++--------- src/librc.h | 2 +- src/mountinfo.c | 4 ++- src/rc-logger.c | 2 +- src/rc-misc.c | 90 +++++++++++++++++++++++-------------------------- src/rc-misc.h | 4 +-- src/rc-status.c | 2 +- src/rc-update.c | 2 +- src/rc.c | 21 ++++++++---- src/rc.h | 4 +-- src/rc.map | 2 +- src/runscript.c | 22 ++++++------ src/start-stop-daemon.c | 4 +-- 14 files changed, 94 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/fstabinfo.c b/src/fstabinfo.c index 495f311e..ffb42a1f 100644 --- a/src/fstabinfo.c +++ b/src/fstabinfo.c @@ -205,7 +205,7 @@ int fstabinfo (int argc, char **argv) } /* No point in outputting if quiet */ - if (rc_env_bool ("RC_QUIET")) + if (rc_yesno (getenv ("RC_QUIET"))) continue; switch (output) { diff --git a/src/librc-misc.c b/src/librc-misc.c index d63dc182..a8c9f33d 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -32,33 +32,28 @@ #include "librc.h" -bool rc_env_bool (const char *var) +bool rc_yesno (const char *value) { - char *v; - - if (! var) - return (false); - - if (! (v = getenv (var))) { - errno = ENOENT; + if (! value) { + errno = EINVAL; return (false); } - if (strcasecmp (v, "true") == 0 || - strcasecmp (v, "y") == 0 || - strcasecmp (v, "yes") == 0 || - strcasecmp (v, "1") == 0) + if (strcasecmp (value, "yes") == 0 || + strcasecmp (value, "y") == 0 || + strcasecmp (value, "true") == 0 || + strcasecmp (value, "1") == 0) return (true); - if (strcasecmp (v, "false") != 0 && - strcasecmp (v, "n") != 0 && - strcasecmp (v, "no") != 0 && - strcasecmp (v, "0") != 0) + if (strcasecmp (value, "no") != 0 && + strcasecmp (value, "n") != 0 && + strcasecmp (value, "false") != 0 && + strcasecmp (value, "0") != 0) errno = EINVAL; return (false); } -librc_hidden_def(rc_env_bool) +librc_hidden_def(rc_yesno) char *rc_strcatpaths (const char *path1, const char *paths, ...) { diff --git a/src/librc.h b/src/librc.h index fb37e8c0..370a1266 100644 --- a/src/librc.h +++ b/src/librc.h @@ -81,7 +81,6 @@ librc_hidden_proto(rc_deptree_load) librc_hidden_proto(rc_deptree_order) librc_hidden_proto(rc_deptree_update) librc_hidden_proto(rc_deptree_update_needed) -librc_hidden_proto(rc_env_bool) librc_hidden_proto(rc_find_pids) librc_hidden_proto(rc_runlevel_exists) librc_hidden_proto(rc_runlevel_get) @@ -123,5 +122,6 @@ librc_hidden_proto(rc_strlist_delete) librc_hidden_proto(rc_strlist_free) librc_hidden_proto(rc_strlist_join) librc_hidden_proto(rc_strlist_reverse) +librc_hidden_proto(rc_yesno) #endif diff --git a/src/mountinfo.c b/src/mountinfo.c index 22fe2c14..4fed2b1a 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -365,6 +365,7 @@ int mountinfo (int argc, char **argv) char *n; int opt; int result; + bool quiet; #define DO_REG(_var) \ if (_var) free (_var); \ @@ -442,12 +443,13 @@ int mountinfo (int argc, char **argv) rc_strlist_reverse (nodes); result = EXIT_FAILURE; + quiet = rc_yesno (getenv ("RC_QUIET")); STRLIST_FOREACH (nodes, n, i) { if (point_regex && regexec (point_regex, n, 0, NULL, 0) != 0) continue; if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0) continue; - if (! rc_env_bool ("RC_QUIET")) + if (! quiet) printf ("%s\n", n); result = EXIT_SUCCESS; } diff --git a/src/rc-logger.c b/src/rc-logger.c index c95b2c8f..1cab3221 100644 --- a/src/rc-logger.c +++ b/src/rc-logger.c @@ -150,7 +150,7 @@ void rc_logger_open (const char *level) if (! isatty (STDOUT_FILENO)) return; - if (! rc_env_bool ("RC_LOGGER")) + if (! rc_conf_yesno ("rc_logger")) return; if (pipe (signal_pipe) == -1) diff --git a/src/rc-misc.c b/src/rc-misc.c index 56033115..dfedbdc9 100644 --- a/src/rc-misc.c +++ b/src/rc-misc.c @@ -38,6 +38,7 @@ #endif #include +#include #include #include #include @@ -50,10 +51,49 @@ #define PROFILE_ENV "/etc/profile.env" #define SYS_WHITELIST RC_LIBDIR "/conf.d/env_whitelist" #define USR_WHITELIST "/etc/conf.d/env_whitelist" -#define RC_CONFIG "/etc/conf.d/rc" +#define RC_CONF "/etc/rc.conf" +#define RC_CONF_OLD "/etc/conf.d/rc" #define PATH_PREFIX RC_LIBDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin" +static char **rc_conf = NULL; + +static void _free_rc_conf (void) +{ + rc_strlist_free (rc_conf); +} + +bool rc_conf_yesno (const char *setting) +{ + if (! rc_conf) { + char *line; + int i; + + rc_conf = rc_config_load (RC_CONF); + atexit (_free_rc_conf); + + /* Support old configs */ + if (exists (RC_CONF_OLD)) { + char **old = rc_config_load (RC_CONF_OLD); + rc_strlist_join (&rc_conf, old); + rc_strlist_free (old); + } + + /* Convert old uppercase to lowercase */ + STRLIST_FOREACH (rc_conf, line, i) { + char *p = line; + while (p && *p && *p != '=') { + if (isupper (*p)) + *p = tolower (*p); + p++; + } + } + + } + + return (rc_yesno (rc_config_value (rc_conf, setting))); +} + char **env_filter (void) { char **env = NULL; @@ -64,10 +104,10 @@ char **env_filter (void) bool got_path = false; char *env_var; int env_len; - char *p; char *token; char *sep; char *e; + char *p; int pplen = strlen (PATH_PREFIX); whitelist = rc_config_list (SYS_WHITELIST); @@ -195,45 +235,14 @@ char **env_config (void) char **env = NULL; char *line; int i; - char *p; - char **config; - char *e; #ifdef __linux__ char sys[6]; #endif struct utsname uts; - bool has_net_fs_list = false; FILE *fp; char buffer[PATH_MAX]; char *runlevel = rc_runlevel_get (); - /* Don't trust environ for softlevel yet */ - snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel); - if (exists (buffer)) - config = rc_config_load (buffer); - else - config = rc_config_load (RC_CONFIG); - - STRLIST_FOREACH (config, line, i) { - p = strchr (line, '='); - if (! p) - continue; - - *p = 0; - e = getenv (line); - if (! e) { - *p = '='; - rc_strlist_add (&env, line); - } else { - int len = strlen (line) + strlen (e) + 2; - char *new = xmalloc (sizeof (char) * len); - snprintf (new, len, "%s=%s", line, e); - rc_strlist_add (&env, new); - free (new); - } - } - rc_strlist_free (config); - /* One char less to drop the trailing / */ i = strlen ("RC_LIBDIR=") + strlen (RC_LIBDIR) + 1; line = xmalloc (sizeof (char) * i); @@ -304,21 +313,6 @@ char **env_config (void) #endif - /* Only add a NET_FS list if not defined */ - STRLIST_FOREACH (env, line, i) - if (strncmp (line, "RC_NET_FS_LIST=", strlen ("RC_NET_FS_LIST=")) == 0) { - has_net_fs_list = true; - break; - } - - if (! has_net_fs_list) { - i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1; - line = xmalloc (sizeof (char) * i); - snprintf (line, i, "RC_NET_FS_LIST=%s", RC_NET_FS_LIST_DEFAULT); - rc_strlist_add (&env, line); - free (line); - } - /* Some scripts may need to take a different code path if Linux/FreeBSD, etc To save on calling uname, we store it in an environment variable */ if (uname (&uts) == 0) { diff --git a/src/rc-misc.h b/src/rc-misc.h index 01c25a6a..7e69f451 100644 --- a/src/rc-misc.h +++ b/src/rc-misc.h @@ -64,9 +64,6 @@ /* Max buffer to read a line from a file */ #define RC_LINEBUFFER 4096 -/* Good defaults just incase user has none set */ -#define RC_NET_FS_LIST_DEFAULT "afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" - #define ERRX fprintf (stderr, "out of memory\n"); exit (1) static inline void *xmalloc (size_t size) @@ -113,6 +110,7 @@ static inline bool exists (const char *pathname) return (stat (pathname, &buf) == 0); } +bool rc_conf_yesno (const char *var); char **env_filter (void); char **env_config (void); diff --git a/src/rc-status.c b/src/rc-status.c index 02368a11..3958b71a 100644 --- a/src/rc-status.c +++ b/src/rc-status.c @@ -82,7 +82,7 @@ static void print_service (char *service) } else snprintf (status, sizeof (status), " stopped "); - if (isatty (fileno (stdout)) && ! rc_env_bool ("RC_NOCOLOR")) + if (isatty (fileno (stdout)) && ! rc_yesno (getenv ("RC_NOCOLOR"))) printf ("\n"); ebracket (cols, color, status); } diff --git a/src/rc-update.c b/src/rc-update.c index f8dd6c47..02a650fe 100644 --- a/src/rc-update.c +++ b/src/rc-update.c @@ -185,7 +185,7 @@ int rc_update (int argc, char **argv) } } - verbose = rc_env_bool ("RC_VERBOSE"); + verbose = rc_yesno (getenv ("RC_VERBOSE")); if ((action & DOSHOW && action != DOSHOW) || (action & DOADD && action != DOADD) || diff --git a/src/rc.c b/src/rc.c index 33f6ef37..1bd8e2c3 100644 --- a/src/rc.c +++ b/src/rc.c @@ -492,6 +492,8 @@ static char read_key (bool block) static bool want_interactive (void) { char c; + static bool gotinteractive; + static bool interactive; if (PREVLEVEL && strcmp (PREVLEVEL, "N") != 0 && @@ -499,7 +501,11 @@ static bool want_interactive (void) strcmp (PREVLEVEL, "1") != 0) return (false); - if (! rc_env_bool ("RC_INTERACTIVE")) + if (! gotinteractive) { + gotinteractive = true; + interactive = rc_conf_yesno ("rc_interactive"); + } + if (! interactive) return (false); c = read_key (false); @@ -793,6 +799,7 @@ int main (int argc, char **argv) int opt; DIR *dp; struct dirent *d; + bool parallel; atexit (cleanup); if (argv[0]) @@ -982,7 +989,7 @@ int main (int argc, char **argv) ecolor (ECOLOR_GOOD), ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL)); - if (rc_env_bool ("RC_INTERACTIVE")) + if (rc_conf_yesno ("rc_interactive")) printf ("Press %sI%s to enter interactive boot mode\n\n", ecolor (ECOLOR_GOOD), ecolor (ECOLOR_NORMAL)); @@ -1156,7 +1163,7 @@ int main (int argc, char **argv) if (newlevel && strcmp (newlevel, bootlevel) == 0 && (strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) && - rc_env_bool ("RC_COLDPLUG")) + rc_conf_yesno ("rc_coldplug")) { #if defined(__DragonFly__) || defined(__FreeBSD__) /* The net interfaces are easy - they're all in net /dev/net :) */ @@ -1263,6 +1270,8 @@ int main (int argc, char **argv) if (going_down) rc_runlevel_set (newlevel); + parallel = rc_conf_yesno ("rc_parallel"); + /* Now stop the services that shouldn't be running */ STRLIST_FOREACH (stop_services, service, i) { bool found = false; @@ -1278,7 +1287,7 @@ int main (int argc, char **argv) /* We always stop the service when in these runlevels */ if (going_down) { pid_t pid = rc_service_stop (service); - if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) + if (pid > 0 && ! parallel) rc_waitpid (pid); continue; } @@ -1348,7 +1357,7 @@ int main (int argc, char **argv) if ((pid = rc_service_stop (service)) > 0) { add_pid (pid); - if (! rc_env_bool ("RC_PARALLEL")) { + if (! parallel) { rc_waitpid (pid); remove_pid (pid); } @@ -1448,7 +1457,7 @@ interactive_option: if ((pid = rc_service_start (service)) > 0) { add_pid (pid); - if (! rc_env_bool ("RC_PARALLEL")) { + if (! parallel) { rc_waitpid (pid); remove_pid (pid); } diff --git a/src/rc.h b/src/rc.h index 2b392a4e..8d5f32ea 100644 --- a/src/rc.h +++ b/src/rc.h @@ -353,12 +353,12 @@ char **rc_config_load (const char *file); /*! Return the value of the entry from a key=value list. */ char *rc_config_value (char **list, const char *entry); -/*! Check if an environment variable is a boolean and return it's value. +/*! Check if a variable is a boolean and return it's value. * If variable is not a boolean then we set errno to be ENOENT when it does * not exist or EINVAL if it's not a boolean. * @param variable to check * @return true if it matches true, yes or 1, false if otherwise. */ -bool rc_env_bool (const char *variable); +bool rc_yesno (const char *variable); /*! @name String List functions * Handy functions for dealing with string arrays of char **. diff --git a/src/rc.map b/src/rc.map index e74f66b8..b487b663 100644 --- a/src/rc.map +++ b/src/rc.map @@ -9,7 +9,6 @@ global: rc_deptree_order; rc_deptree_update; rc_deptree_update_needed; - rc_env_bool; rc_environ_fd; rc_find_pids; rc_runlevel_exists; @@ -52,6 +51,7 @@ global: rc_strlist_free; rc_strlist_join; rc_strlist_reverse; + rc_yesno; local: *; diff --git a/src/runscript.c b/src/runscript.c index 6431a784..68c14f86 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -590,7 +590,7 @@ static void svc_start (bool deps) state = rc_service_state (service); - if (rc_env_bool ("IN_HOTPLUG") || in_background) { + if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) { if (! state & RC_SERVICE_INACTIVE && ! state & RC_SERVICE_STOPPED) exit (EXIT_FAILURE); @@ -615,7 +615,7 @@ static void svc_start (bool deps) hook_out = RC_HOOK_SERVICE_START_OUT; rc_plugin_run (RC_HOOK_SERVICE_START_IN, applet); - if (rc_env_bool ("RC_DEPEND_STRICT")) + if (rc_conf_yesno ("rc_depend_strict")) depoptions |= RC_DEP_STRICT; if (rc_runlevel_starting ()) @@ -651,7 +651,7 @@ static void svc_start (bool deps) STRLIST_FOREACH (use_services, svc, i) if (rc_service_state (svc) & RC_SERVICE_STOPPED) { pid_t pid = rc_service_start (svc); - if (! rc_env_bool ("RC_PARALLEL")) + if (! rc_conf_yesno ("rc_parallel")) rc_waitpid (pid); } } @@ -805,7 +805,7 @@ static void svc_stop (bool deps) state & RC_SERVICE_FAILED) exit (EXIT_FAILURE); - if (rc_env_bool ("IN_HOTPLUG") || in_background) + if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) if (! (state & RC_SERVICE_STARTED) && ! (state & RC_SERVICE_INACTIVE)) exit (EXIT_FAILURE); @@ -833,7 +833,7 @@ static void svc_stop (bool deps) char *svc; int i; - if (rc_env_bool ("RC_DEPEND_STRICT")) + if (rc_conf_yesno ("RC_DEPEND_STRICT")) depoptions |= RC_DEP_STRICT; if (rc_runlevel_stopping ()) @@ -859,7 +859,7 @@ static void svc_stop (bool deps) svcs & RC_SERVICE_INACTIVE) { pid_t pid = rc_service_stop (svc); - if (! rc_env_bool ("RC_PARALLEL")) + if (! rc_conf_yesno ("rc_parallel")) rc_waitpid (pid); rc_strlist_add (&tmplist, svc); } @@ -1087,7 +1087,7 @@ int runscript (int argc, char **argv) setenv ("RC_RUNSCRIPT_PID", pid, 1); /* eprefix is kinda klunky, but it works for our purposes */ - if (rc_env_bool ("RC_PARALLEL")) { + if (rc_conf_yesno ("rc_parallel")) { int l = 0; int ll; @@ -1137,13 +1137,13 @@ int runscript (int argc, char **argv) /* Save the IN_BACKGROUND env flag so it's ONLY passed to the service that is being called and not any dependents */ if (getenv ("IN_BACKGROUND")) { - in_background = rc_env_bool ("IN_BACKGROUND"); ibsave = xstrdup (getenv ("IN_BACKGROUND")); + in_background = rc_yesno (ibsave); unsetenv ("IN_BACKGROUND"); } - if (rc_env_bool ("IN_HOTPLUG")) { - if (! rc_env_bool ("RC_HOTPLUG") || ! rc_service_plugable (applet)) + if (rc_yesno (getenv ("IN_HOTPLUG"))) { + if (! rc_conf_yesno ("rc_hotplug") || ! rc_service_plugable (applet)) eerrorx ("%s: not allowed to be hotplugged", applet); } @@ -1197,7 +1197,7 @@ int runscript (int argc, char **argv) const char *t[] = { optarg, NULL }; const char *s[] = { applet, NULL }; - if (rc_env_bool ("RC_DEPEND_STRICT")) + if (rc_conf_yesno ("rc_depend_strict")) depoptions |= RC_DEP_STRICT; if (! deptree && ((deptree = _rc_deptree_load ()) == NULL)) diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 967d4263..551bad58 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -708,8 +708,8 @@ int start_stop_daemon (int argc, char **argv) case_RC_COMMON_GETOPT } - quiet = rc_env_bool ("RC_QUIET"); - verbose = rc_env_bool ("RC_VERBOSE"); + quiet = rc_yesno (getenv ("RC_QUIET")); + verbose = rc_yesno (getenv ("RC_VERBOSE")); /* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq * instead of forcing --stop --oknodo as well */ -- cgit v1.2.3