diff options
-rw-r--r-- | src/librc/librc-misc.c | 48 | ||||
-rw-r--r-- | src/librc/librc.h | 1 | ||||
-rw-r--r-- | src/librc/rc.h.in | 7 | ||||
-rw-r--r-- | src/librc/rc.map | 1 | ||||
-rw-r--r-- | src/rc/rc.c | 54 | ||||
-rw-r--r-- | src/test/rc.funcs.list | 2 |
6 files changed, 63 insertions, 50 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index 97fa54c8..cebc9e8c 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -29,6 +29,7 @@ */ #include "librc.h" +#include "einfo.h" bool rc_yesno(const char *value) @@ -127,6 +128,53 @@ rc_getline(char **line, size_t *len, FILE *fp) } librc_hidden_def(rc_getline) +#ifdef __linux__ +char * +rc_proc_getent(const char *ent) +{ + FILE *fp; + char *proc, *p, *value = NULL; + size_t i, len; + + if (!exists("/proc/cmdline")) + return NULL; + + if (!(fp = fopen("/proc/cmdline", "r"))) { + eerror("failed to open `/proc/cmdline': %s", strerror(errno)); + return NULL; + } + + proc = NULL; + i = 0; + if (rc_getline(&proc, &i, fp) == -1 || proc == NULL) + eerror("rc_getline: %s", strerror(errno)); + + if (proc != NULL) { + len = strlen(ent); + + while ((p = strsep(&proc, " "))) { + if (strncmp(ent, p, len) == 0 && (p[len] == '\0' || p[len] == ' ' || p[len] == '=')) { + p += len; + + if (*p == '=') + p++; + + value = xstrdup(p); + } + } + } + + if (!value) + errno = ENOENT; + + fclose(fp); + free(proc); + + return value; +} +librc_hidden_def(rc_proc_getent) +#endif + RC_STRINGLIST * rc_config_list(const char *file) { diff --git a/src/librc/librc.h b/src/librc/librc.h index 876c0472..54c9a1ac 100644 --- a/src/librc/librc.h +++ b/src/librc/librc.h @@ -87,6 +87,7 @@ librc_hidden_proto(rc_find_pids) librc_hidden_proto(rc_getfile) librc_hidden_proto(rc_getline) librc_hidden_proto(rc_newer_than) +librc_hidden_proto(rc_proc_getent) librc_hidden_proto(rc_older_than) librc_hidden_proto(rc_runlevel_exists) librc_hidden_proto(rc_runlevel_get) diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 350f518e..31b21f16 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -361,6 +361,13 @@ bool rc_newer_than(const char *, const char *, time_t *, char *); * @return true if source is older than target, otherwise false */ bool rc_older_than(const char *, const char *, time_t *, char *); +#ifdef __linux__ +/*! Read variables/values from /proc/cmdline + * @param value + * @return pointer to the value, otherwise NULL */ +char *rc_proc_getent(const char *); +#endif + /*! Update the cached dependency tree if it's older than any init script, * its configuration file or an external configuration file the init script * has specified. diff --git a/src/librc/rc.map b/src/librc/rc.map index 0f45cdfe..2aa58dea 100644 --- a/src/librc/rc.map +++ b/src/librc/rc.map @@ -18,6 +18,7 @@ global: rc_getline; rc_newer_than; rc_older_than; + rc_proc_getent; rc_runlevel_exists; rc_runlevel_get; rc_runlevel_list; diff --git a/src/rc/rc.c b/src/rc/rc.c index 9ee3047a..f284c2e3 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -167,52 +167,6 @@ cleanup(void) #endif } -#ifdef __linux__ -static char * -proc_getent(const char *ent) -{ - FILE *fp; - char *proc, *p, *value = NULL; - size_t i, len; - - if (!exists("/proc/cmdline")) - return NULL; - - if (!(fp = fopen("/proc/cmdline", "r"))) { - eerror("failed to open `/proc/cmdline': %s", strerror(errno)); - return NULL; - } - - proc = NULL; - i = 0; - if (rc_getline(&proc, &i, fp) == -1 || proc == NULL) - eerror("rc_getline: %s", strerror(errno)); - - if (proc != NULL) { - len = strlen(ent); - - while ((p = strsep(&proc, " "))) { - if (strncmp(ent, p, len) == 0 && (p[len] == '\0' || p[len] == ' ' || p[len] == '=')) { - p += len; - - if (*p == '=') - p++; - - value = xstrdup(p); - } - } - } - - if (!value) - errno = ENOENT; - - fclose(fp); - free(proc); - - return value; -} -#endif - static char read_key(bool block) { @@ -969,9 +923,9 @@ main(int argc, char **argv) #ifdef __linux__ if (strcmp(newlevel, RC_LEVEL_SYSINIT) == 0) { /* If we requested a runlevel, save it now */ - p = proc_getent("rc_runlevel"); + p = rc_proc_getent("rc_runlevel"); if (p == NULL) - p = proc_getent("softlevel"); + p = rc_proc_getent("softlevel"); if (p != NULL) { set_krunlevel(p); free(p); @@ -1123,7 +1077,7 @@ main(int argc, char **argv) #ifdef __linux__ /* mark any services skipped as started */ - proc = p = proc_getent("noinit"); + proc = p = rc_proc_getent("noinit"); if (proc) { while ((token = strsep(&p, ","))) rc_service_mark(token, RC_SERVICE_STARTED); @@ -1144,7 +1098,7 @@ main(int argc, char **argv) #ifdef __linux__ /* mark any services skipped as stopped */ - proc = p = proc_getent("noinit"); + proc = p = rc_proc_getent("noinit"); if (proc) { while ((token = strsep(&p, ","))) rc_service_mark(token, RC_SERVICE_STOPPED); diff --git a/src/test/rc.funcs.list b/src/test/rc.funcs.list index f0416b7d..f4c90b51 100644 --- a/src/test/rc.funcs.list +++ b/src/test/rc.funcs.list @@ -32,6 +32,8 @@ rc_newer_than rc_newer_than@@RC_1.0 rc_older_than rc_older_than@@RC_1.0 +rc_proc_getent +rc_proc_getent@@RC_1.0 rc_runlevel_exists rc_runlevel_exists@@RC_1.0 rc_runlevel_get |