[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: faa8318b3ba278544413a39d4a5ae4457711793f Author: William Hubbs gmail com> AuthorDate: Fri May 18 21:48:21 2018 + Commit: William Hubbs gentoo org> CommitDate: Fri May 18 21:48:21 2018 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=faa8318b Remove the _rc_can_find_pids function This test to find if we could see pid 1 was being used inconsistently in rc-status and mark_service_crashed to decide whether we could test to see if the daemon for the service was crashed, and it was not part of the librc library. I am removing it from the executables because of inconsistent usage. I will add it to the library if it is needed there. src/includes/rc-misc.h | 3 --- src/rc/do_service.c| 4 +--- src/rc/rc-misc.c | 28 src/rc/rc-status.c | 7 +-- 4 files changed, 2 insertions(+), 40 deletions(-) diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index e6789911..d05255f4 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -66,9 +66,6 @@ int parse_mode(mode_t *, char *); /* Handy function so we can wrap einfo around our deptree */ RC_DEPTREE *_rc_deptree_load (int, int *); -/* Test to see if we can see pid 1 or not */ -bool _rc_can_find_pids(void); - RC_SERVICE lookup_service_state(const char *service); void from_time_t(char *time_string, time_t tv); time_t to_time_t(char *timestring); diff --git a/src/rc/do_service.c b/src/rc/do_service.c index a36a09ca..5d78e8df 100644 --- a/src/rc/do_service.c +++ b/src/rc/do_service.c @@ -68,9 +68,7 @@ int main(int argc, char **argv) ok = rc_service_started_daemon(service, exec, NULL, idx); } else if (strcmp(applet, "service_crashed") == 0) { - ok = (_rc_can_find_pids() && - rc_service_daemons_crashed(service) && - errno != EACCES); + ok = ( rc_service_daemons_crashed(service) && errno != EACCES); } else eerrorx("%s: unknown applet", applet); diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index 50c09747..e933409f 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -411,34 +411,6 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen) return rc_deptree_load(); } -bool _rc_can_find_pids(void) -{ - RC_PIDLIST *pids; - RC_PID *pid; - RC_PID *pid2; - bool retval = false; - - if (geteuid() == 0) - return true; - - /* If we cannot see process 1, then we don't test to see if -* services crashed or not */ - pids = rc_find_pids(NULL, NULL, 0, 1); - if (pids) { - pid = LIST_FIRST(pids); - if (pid) { - retval = true; - while (pid) { - pid2 = LIST_NEXT(pid, entries); - free(pid); - pid = pid2; - } - } - free(pids); - } - return retval; -} - static const struct { const char * const name; RC_SERVICE bit; diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c index d29f876a..ab80d901 100644 --- a/src/rc/rc-status.c +++ b/src/rc/rc-status.c @@ -54,7 +54,6 @@ const char *usagestring = "" \ "Usage: rc-status [options] ...\n"\ " or: rc-status [options] [-a | -c | -l | -m | -r | -s | -u]"; -static bool test_crashed = false; static RC_DEPTREE *deptree; static RC_STRINGLIST *types; @@ -145,9 +144,7 @@ print_service(const char *service) color = ECOLOR_WARN; } else if (state & RC_SERVICE_STARTED) { errno = 0; - if (test_crashed && - rc_service_daemons_crashed(service) && - errno != EACCES) + if (rc_service_daemons_crashed(service) && errno != EACCES) { child_pid = rc_service_value_get(service, "child_pid"); start_time = rc_service_value_get(service, "start_time"); @@ -240,8 +237,6 @@ int main(int argc, char **argv) char *p, *runlevel = NULL; int opt, retval = 0; - test_crashed = _rc_can_find_pids(); - applet = basename_c(argv[0]); while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1)
[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: cfbe9c2ede24dac530ef58e5c35bd57f22a788a3 Author: William Hubbs gmail com> AuthorDate: Wed Aug 23 19:16:49 2017 + Commit: William Hubbs gentoo org> CommitDate: Wed Aug 23 19:36:50 2017 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cfbe9c2e move get_pid function to a shared file src/includes/rc-misc.h | 1 + src/rc/rc-misc.c | 24 src/rc/start-stop-daemon.c | 31 +++ src/rc/supervise-daemon.c | 28 ++-- 4 files changed, 30 insertions(+), 54 deletions(-) diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index 95ccbc33..9a55c413 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -71,5 +71,6 @@ bool _rc_can_find_pids(void); RC_SERVICE lookup_service_state(const char *service); void from_time_t(char *time_string, time_t tv); time_t to_time_t(char *timestring); +pid_t get_pid(const char *applet, const char *pidfile); #endif diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index a6cc788e..d43f1274 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -474,3 +474,27 @@ time_t to_time_t(char *timestring) } return result; } + +pid_t get_pid(const char *applet,const char *pidfile) +{ + FILE *fp; + pid_t pid; + + if (! pidfile) + return -1; + + if ((fp = fopen(pidfile, "r")) == NULL) { + ewarnv("%s: fopen `%s': %s", applet, pidfile, strerror(errno)); + return -1; + } + + if (fscanf(fp, "%d", ) != 1) { + ewarnv("%s: no pid found in `%s'", applet, pidfile); + fclose(fp); + return -1; + } + + fclose(fp); + + return pid; +} diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index c88bc962..451d4a5c 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -368,31 +368,6 @@ parse_schedule(const char *string, int timeout) return; } -static pid_t -get_pid(const char *pidfile) -{ - FILE *fp; - pid_t pid; - - if (! pidfile) - return -1; - - if ((fp = fopen(pidfile, "r")) == NULL) { - ewarnv("%s: fopen `%s': %s", applet, pidfile, strerror(errno)); - return -1; - } - - if (fscanf(fp, "%d", ) != 1) { - ewarnv("%s: no pid found in `%s'", applet, pidfile); - fclose(fp); - return -1; - } - - fclose(fp); - - return pid; -} - /* return number of processed killed, -1 on error */ static int do_stop(const char *exec, const char *const *argv, @@ -472,7 +447,7 @@ run_stop_schedule(const char *exec, const char *const *argv, } if (pidfile) { - pid = get_pid(pidfile); + pid = get_pid(applet, pidfile); if (pid == -1) return 0; } @@ -1090,7 +1065,7 @@ int main(int argc, char **argv) } if (pidfile) - pid = get_pid(pidfile); + pid = get_pid(applet, pidfile); else pid = 0; @@ -1365,7 +1340,7 @@ int main(int argc, char **argv) alive = true; } else { if (pidfile) { - pid = get_pid(pidfile); + pid = get_pid(applet, pidfile); if (pid == -1) { eerrorx("%s: did not " "create a valid" diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c index dc6d6c12..c59fb099 100644 --- a/src/rc/supervise-daemon.c +++ b/src/rc/supervise-daemon.c @@ -147,30 +147,6 @@ static void cleanup(void) free(changeuser); } -static pid_t get_pid(const char *pidfile) -{ - FILE *fp; - pid_t pid; - - if (! pidfile) - return -1; - - if ((fp = fopen(pidfile, "r")) == NULL) { - ewarnv("%s: fopen `%s': %s", applet, pidfile, strerror(errno)); - return -1; - } - - if (fscanf(fp, "%d", ) != 1) { - ewarnv("%s: no pid found in `%s'", applet, pidfile); - fclose(fp); - return -1; - } - - fclose(fp); - - return pid; -} - static void child_process(char *exec, char **argv, char *svcname, int start_count) { @@ -673,7 +649,7 @@ int main(int argc, char **argv) *exec_file ? exec_file : exec); if (stop) { - pid = get_pid(pidfile); + pid = get_pid(applet, pidfile); if (pid == -1) i = pid; else @@ -697,7 +673,7 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } - pid = get_pid(pidfile); + pid = get_pid(applet, pidfile); if (pid != -1)
[gentoo-commits] proj/openrc:master commit in: /, src/includes/, src/rc/, src/librc/
commit: 649f63d882d53533ae8b1c3b28967e772e738c45 Author: Doug Freed mtu edu> AuthorDate: Mon Jan 18 05:43:46 2016 + Commit: William Hubbs gentoo org> CommitDate: Tue Jan 19 06:09:20 2016 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=649f63d8 librc: move system detection code into rc_sys and use it This fixes an issue where librc code was calling code that only existed in the rc binary. This reverts commits 8addd79 and 9f6e056 This fixes #75. FEATURE-REMOVAL-SCHEDULE.md | 10 --- src/includes/rc-misc.h | 4 -- src/librc/librc-depend.c| 5 +- src/librc/librc.c | 97 ++ src/rc/_usage.c | 5 +- src/rc/rc-misc.c| 164 +--- src/rc/rc.c | 20 ++ 7 files changed, 76 insertions(+), 229 deletions(-) diff --git a/FEATURE-REMOVAL-SCHEDULE.md b/FEATURE-REMOVAL-SCHEDULE.md index 8d07cd4..d66f94f 100644 --- a/FEATURE-REMOVAL-SCHEDULE.md +++ b/FEATURE-REMOVAL-SCHEDULE.md @@ -76,13 +76,3 @@ Why: The getline() function was standardized in POSIX.1-2008, so it Who: -### rc_sys() - -When: 1.0 - -Why: The OpenRC code now uses two internal functions, detect_container() -and detect_vm() to handle this. rc_sys() is broken because it -doesn't differentiate between containers and vm's. - -Who: - diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index f2449cd..684ace5 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -60,10 +60,6 @@ int is_writable(const char *); #define service_stop(service) exec_service(service, "stop"); int parse_mode(mode_t *, char *); -const char *detect_prefix(void); -const char *get_systype(void); -const char *detect_container(void); -const char *detect_vm(void); /* Handy function so we can wrap einfo around our deptree */ RC_DEPTREE *_rc_deptree_load (int, int *); diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index 991a871..d64b2b2 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -740,7 +740,7 @@ rc_deptree_update(void) char *depend, *depends, *service, *type, *nosys, *onosys; size_t i, k, l; bool retval = true; - const char *sys = NULL; + const char *sys = rc_sys(); struct utsname uts; /* Some init scripts need RC_LIBEXECDIR to source stuff @@ -847,9 +847,6 @@ rc_deptree_update(void) /* Phase 2 - if we're a special system, remove services that don't * work for them. This doesn't stop them from being run directly. */ - sys = detect_container(); - if (!sys) - sys = detect_vm(); if (sys) { len = strlen(sys); nosys = xmalloc(len + 2); diff --git a/src/librc/librc.c b/src/librc/librc.c index 6449898..5cf4898 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -198,13 +198,9 @@ found: #endif -const char * -rc_sys(void) +static const char * +get_systype(void) { -#ifdef PREFIX - return RC_SYS_PREFIX; -#endif - char *systype = rc_conf_value("rc_sys"); if (systype) { char *s = systype; @@ -215,7 +211,22 @@ rc_sys(void) s++; } } + return systype; +} + +static const char * +detect_prefix(const char *systype) +{ +#ifdef PREFIX + return RC_SYS_PREFIX; +#else + return NULL; +#endif +} +static const char * +detect_container(const char *systype) +{ #ifdef __FreeBSD__ if (systype && strcmp(systype, RC_SYS_JAIL) == 0) return RC_SYS_JAIL; @@ -227,25 +238,8 @@ rc_sys(void) return RC_SYS_JAIL; #endif -#ifdef __NetBSD__ - if (systype) { - if(strcmp(systype, RC_SYS_XEN0) == 0) - return RC_SYS_XEN0; - if (strcmp(systype, RC_SYS_XENU) == 0) - return RC_SYS_XENU; - } - if (exists("/kern/xen/privcmd")) - return RC_SYS_XEN0; - if (exists("/kern/xen")) - return RC_SYS_XENU; -#endif - #ifdef __linux__ if (systype) { - if (strcmp(systype, RC_SYS_XEN0) == 0) - return RC_SYS_XEN0; - if (strcmp(systype, RC_SYS_XENU) == 0) - return RC_SYS_XENU; if (strcmp(systype, RC_SYS_UML) == 0) return RC_SYS_UML; if (strcmp(systype, RC_SYS_VSERVER) == 0) @@ -261,11 +255,7 @@ rc_sys(void) if (strcmp(systype, RC_SYS_DOCKER) == 0) return RC_SYS_DOCKER; } - if (exists("/proc/xen")) { - if (file_regex("/proc/xen/capabilities", "control_d")) - return RC_SYS_XEN0; - return RC_SYS_XENU; - } else if (file_regex("/proc/cpuinfo", "UML")) + if (file_regex("/proc/cpuinfo",
[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: 55a28f5d2524615560698453a5a6afd50460030c Author: William Hubbs gmail com> AuthorDate: Tue Jan 19 05:40:20 2016 + Commit: William Hubbs gentoo org> CommitDate: Tue Jan 19 05:40:20 2016 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=55a28f5d Revert "rc: make get_systype similar to the old rc_sys function" This reverts commit f79a7a7be18d68bf264efc60d82838d03048da6b. src/includes/rc-misc.h | 5 +- src/rc/_usage.c| 5 +- src/rc/rc-misc.c | 333 - src/rc/rc.c| 19 ++- 4 files changed, 186 insertions(+), 176 deletions(-) diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index de73c5c..f2449cd 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -43,7 +43,6 @@ char *rc_conf_value(const char *var); bool rc_conf_yesno(const char *var); -char *get_systype(void); void env_filter(void); void env_config(void); int signal_setup(int sig, void (*handler)(int)); @@ -61,6 +60,10 @@ int is_writable(const char *); #define service_stop(service) exec_service(service, "stop"); int parse_mode(mode_t *, char *); +const char *detect_prefix(void); +const char *get_systype(void); +const char *detect_container(void); +const char *detect_vm(void); /* Handy function so we can wrap einfo around our deptree */ RC_DEPTREE *_rc_deptree_load (int, int *); diff --git a/src/rc/_usage.c b/src/rc/_usage.c index 40d8142..9fc3e5d 100644 --- a/src/rc/_usage.c +++ b/src/rc/_usage.c @@ -44,9 +44,12 @@ void set_quiet_options(void) _noreturn void show_version(void) { - char *systype = get_systype(); + const char *systype = NULL; printf("%s (OpenRC", applet); + systype = detect_container(); + if (!systype) + systype = detect_vm(); if (systype) printf(" [%s]", systype); printf(") %s", VERSION); diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index e0e6e2c..2c6c388 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -50,172 +50,6 @@ rc_conf_yesno(const char *setting) return rc_yesno(rc_conf_value (setting)); } -/* - * static bool is_container(const char *systype) - * { -* FreeBSD: RC_SYS_JAIL -* Linux: RC_SYS_UML RC_SYS_VSERVER RC_SYS_OPENVZ RC_SYS_LXC -* RC_SYS_RKT RC_SYS_SYSTEMD_NSPAWN RC_SYS_DOCKER - * } - * - * static bool is_vm(const char *systype) - * { -* NetBSD: RC_SYS_XEN0 RC_SYS_XENU -* Linux: RC_SYS_XEN0 RC_SYS_XENU - * } - */ - -static bool file_regex(const char *file, const char *regex) -{ - FILE *fp; - char *line = NULL; - size_t len = 0; - regex_t re; - bool retval = true; - int result; - - if (!(fp = fopen(file, "r"))) - return false; - - if ((result = regcomp(, regex, REG_EXTENDED | REG_NOSUB)) != 0) { - fclose(fp); - line = xmalloc(sizeof(char) * BUFSIZ); - regerror(result, , line, BUFSIZ); - fprintf(stderr, "file_regex: %s", line); - free(line); - return false; - } - - while ((rc_getline(, , fp))) { - char *str = line; - /* some /proc files have \0 separated content so we have to - loop through the 'line' */ - do { - if (regexec(, str, 0, NULL, 0) == 0) - goto found; - str += strlen(str) + 1; - /* len is the size of allocated buffer and we don't - want call regexec BUFSIZE times. find next str */ - while (str < line + len && *str == '\0') - str++; - } while (str < line + len); - } - retval = false; -found: - fclose(fp); - free(line); - regfree(); - - return retval; -} - -char *get_systype(void) -{ - char *systype = rc_conf_value("rc_sys"); - char *s; - - if (systype) { - if (*systype == '\0') { - free(systype); - return NULL; - } - s = systype; - /* Convert to uppercase */ - while (s && *s) { - if (islower((unsigned char) *s)) - *s = toupper((unsigned char) *s); - s++; - } - if (strcmp(systype,RC_SYS_PREFIX) == 0) - return systype; - -#ifdef __FreeBSD__ - if (strcmp(systype, RC_SYS_JAIL) == 0) - return systype; -#endif - -#ifdef __linux__ - if (strcmp(systype, RC_SYS_UML) == 0) - return systype; - else if (strcmp(systype, RC_SYS_VSERVER) == 0) - return systype; - else if (strcmp(systype, RC_SYS_OPENVZ) == 0) -
[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: 981d2b3308edb0d0a68f7bdce4f2c99110de6940 Author: William Hubbs gmail com> AuthorDate: Fri Jan 1 19:13:28 2016 + Commit: William Hubbs gentoo org> CommitDate: Fri Jan 1 19:13:28 2016 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=981d2b33 rc: clean up compiler warnings The get_systype(), detect_container(), detect_prefix() and detect_vm() functions need to return "char *" instead of "const char *". src/includes/rc-misc.h | 8 src/rc/_usage.c| 2 +- src/rc/rc-misc.c | 10 +- src/rc/rc.c| 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index 89d6336..fa370e4 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -74,8 +74,8 @@ int is_writable(const char *); #define service_stop(service) exec_service(service, "stop"); int parse_mode(mode_t *, char *); -const char *detect_prefix(void); -const char *get_systype(void); -const char *detect_container(void); -const char *detect_vm(void); +char *detect_prefix(void); +char *get_systype(void); +char *detect_container(void); +char *detect_vm(void); #endif diff --git a/src/rc/_usage.c b/src/rc/_usage.c index e190eb4..b5f664a 100644 --- a/src/rc/_usage.c +++ b/src/rc/_usage.c @@ -40,7 +40,7 @@ static void set_quiet_options(void) _noreturn static void show_version(void) { - const char *systype = NULL; + char *systype = NULL; printf("%s (OpenRC", applet); systype = detect_container(); diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index f1dad3b..bb401e1 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -126,7 +126,7 @@ env_config(void) char *np; char *npp; char *tok; - const char *sys = NULL; + char *sys = NULL; char buffer[PATH_MAX]; /* Ensure our PATH is prefixed with the system locations first @@ -380,7 +380,7 @@ found: return retval; } -const char *detect_prefix(void) +char *detect_prefix(void) { #ifdef PREFIX return RC_SYS_PREFIX; @@ -389,7 +389,7 @@ const char *detect_prefix(void) #endif } -const char *get_systype(void) +char *get_systype(void) { char *systype = rc_conf_value("rc_sys"); if (systype) { @@ -404,7 +404,7 @@ const char *get_systype(void) return systype; } -const char *detect_container(void) +char *detect_container(void) { char *systype = get_systype(); @@ -459,7 +459,7 @@ const char *detect_container(void) return NULL; } -const char *detect_vm(void) +char *detect_vm(void) { char *systype = get_systype(); diff --git a/src/rc/rc.c b/src/rc/rc.c index a0b1886..64541e0 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -261,7 +261,7 @@ open_shell(void) struct passwd *pw; #ifdef __linux__ - const char *sys = NULL; + char *sys = NULL; sys = detect_container(); if (!sys) @@ -450,7 +450,7 @@ static void do_sysinit() { struct utsname uts; - const char *sys; + char *sys; /* exec init-early.sh if it exists * This should just setup the console to use the correct @@ -749,7 +749,7 @@ main(int argc, char **argv) { const char *bootlevel = NULL; char *newlevel = NULL; - const char *systype = NULL; + char *systype = NULL; static RC_STRINGLIST *hotplugged_services; static RC_STRINGLIST *stop_services; static RC_STRINGLIST *start_services;
[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: fe485f44339963fdbee143687dcbef2069924bc6 Author: William Hubbs gmail com> AuthorDate: Tue Jan 5 06:57:40 2016 + Commit: William Hubbs gentoo org> CommitDate: Tue Jan 5 07:05:00 2016 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=fe485f44 rc: fix compiler warnings cleanup This reverts commit 981d2b3308edb0d0a68f7bdce4f2c99110de6940 and fixes the warnings that generated. src/includes/rc-misc.h | 8 src/rc/_usage.c| 2 +- src/rc/rc-misc.c | 14 +++--- src/rc/rc.c| 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index fa370e4..89d6336 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -74,8 +74,8 @@ int is_writable(const char *); #define service_stop(service) exec_service(service, "stop"); int parse_mode(mode_t *, char *); -char *detect_prefix(void); -char *get_systype(void); -char *detect_container(void); -char *detect_vm(void); +const char *detect_prefix(void); +const char *get_systype(void); +const char *detect_container(void); +const char *detect_vm(void); #endif diff --git a/src/rc/_usage.c b/src/rc/_usage.c index b5f664a..e190eb4 100644 --- a/src/rc/_usage.c +++ b/src/rc/_usage.c @@ -40,7 +40,7 @@ static void set_quiet_options(void) _noreturn static void show_version(void) { - char *systype = NULL; + const char *systype = NULL; printf("%s (OpenRC", applet); systype = detect_container(); diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index dbdac68..f2f4d9f 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -122,7 +122,7 @@ env_config(void) char *np; char *npp; char *tok; - char *sys = NULL; + const char *sys = NULL; char buffer[PATH_MAX]; /* Ensure our PATH is prefixed with the system locations first @@ -376,7 +376,7 @@ found: return retval; } -char *detect_prefix(void) +const char *detect_prefix(void) { #ifdef PREFIX return RC_SYS_PREFIX; @@ -385,7 +385,7 @@ char *detect_prefix(void) #endif } -char *get_systype(void) +const char *get_systype(void) { char *systype = rc_conf_value("rc_sys"); if (systype) { @@ -400,9 +400,9 @@ char *get_systype(void) return systype; } -char *detect_container(void) +const char *detect_container(void) { - char *systype = get_systype(); + const char *systype = get_systype(); #ifdef __FreeBSD__ if (systype && strcmp(systype, RC_SYS_JAIL) == 0) @@ -455,9 +455,9 @@ char *detect_container(void) return NULL; } -char *detect_vm(void) +const char *detect_vm(void) { - char *systype = get_systype(); + const char *systype = get_systype(); #ifdef __NetBSD__ if (systype) { diff --git a/src/rc/rc.c b/src/rc/rc.c index 64541e0..a0b1886 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -261,7 +261,7 @@ open_shell(void) struct passwd *pw; #ifdef __linux__ - char *sys = NULL; + const char *sys = NULL; sys = detect_container(); if (!sys) @@ -450,7 +450,7 @@ static void do_sysinit() { struct utsname uts; - char *sys; + const char *sys; /* exec init-early.sh if it exists * This should just setup the console to use the correct @@ -749,7 +749,7 @@ main(int argc, char **argv) { const char *bootlevel = NULL; char *newlevel = NULL; - char *systype = NULL; + const char *systype = NULL; static RC_STRINGLIST *hotplugged_services; static RC_STRINGLIST *stop_services; static RC_STRINGLIST *start_services;
[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: bf2f40828ee26d3ba9185f29db596ee5d7b9cf61 Author: William Hubbs gmail com> AuthorDate: Wed Dec 23 20:06:31 2015 + Commit: William Hubbs gentoo org> CommitDate: Tue Jan 12 16:42:14 2016 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=bf2f4082 Remove multicall binary structure from OpenRC This eliminates the need for the selinux-specific wrapper scrript we were installing in /lib*/rc/{bin,sbin}. src/includes/helpers.h | 17 ++ src/includes/rc-misc.h | 24 +- src/rc/Makefile| 133 +++ src/rc/_usage.c| 32 +-- src/rc/_usage.h| 13 ++ src/rc/builtins.h | 34 --- src/rc/checkpath.c | 59 +++-- src/rc/do_e.c | 228 +++ src/rc/do_mark_service.c | 91 src/rc/do_service.c| 78 +++ src/rc/do_value.c | 64 ++ src/rc/fstabinfo.c | 55 ++--- src/rc/is_newer_than.c | 33 +++ src/rc/is_older_than.c | 34 +++ src/rc/mountinfo.c | 80 --- src/rc/openrc-run.c| 59 ++--- src/rc/rc-abort.c | 43 src/rc/rc-applets.c| 557 - src/rc/rc-depend.c | 72 +- src/rc/rc-misc.c | 107 + src/rc/rc-selinux.c| 4 + src/rc/rc-service.c| 28 ++- src/rc/rc-status.c | 86 +++ src/rc/rc-update.c | 46 ++-- src/rc/rc.c| 55 ++--- src/rc/shell_var.c | 41 src/rc/start-stop-daemon.c | 133 +-- src/rc/swclock.c | 21 +- 28 files changed, 1160 insertions(+), 1067 deletions(-) diff --git a/src/includes/helpers.h b/src/includes/helpers.h index c541f99..1a00d3d 100644 --- a/src/includes/helpers.h +++ b/src/includes/helpers.h @@ -53,6 +53,9 @@ } while (/* CONSTCOND */ 0) #endif +#include +#include + _unused static void *xmalloc (size_t size) { void *value = malloc(size); @@ -104,4 +107,18 @@ _unused static const char *basename_c(const char *path) return (path); } +_unused static bool exists(const char *pathname) +{ + struct stat buf; + + return (stat(pathname, ) == 0); +} + +_unused static bool existss(const char *pathname) +{ + struct stat buf; + + return (stat(pathname, ) == 0 && buf.st_size != 0); +} + #endif diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index 89d6336..9616634 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -26,6 +26,7 @@ #include #include "helpers.h" +#include "rc.h" #define RC_LEVEL_BOOT "boot" #define RC_LEVEL_DEFAULT"default" @@ -41,20 +42,6 @@ #define RC_SVCDIR_STARTED RC_SVCDIR "/started" #define RC_SVCDIR_COLDPLUGGED RC_SVCDIR "/coldplugged" -_unused static bool exists(const char *pathname) -{ - struct stat buf; - - return (stat(pathname, ) == 0); -} - -_unused static bool existss(const char *pathname) -{ - struct stat buf; - - return (stat(pathname, ) == 0 && buf.st_size != 0); -} - char *rc_conf_value(const char *var); bool rc_conf_yesno(const char *var); void env_filter(void); @@ -78,4 +65,13 @@ const char *detect_prefix(void); const char *get_systype(void); const char *detect_container(void); const char *detect_vm(void); + +/* Handy function so we can wrap einfo around our deptree */ +RC_DEPTREE *_rc_deptree_load (int, int *); + +/* Test to see if we can see pid 1 or not */ +bool _rc_can_find_pids(void); + +RC_SERVICE lookup_service_state(const char *service); + #endif diff --git a/src/rc/Makefile b/src/rc/Makefile index 65b5811..1df26d8 100644 --- a/src/rc/Makefile +++ b/src/rc/Makefile @@ -1,8 +1,4 @@ -PROG= openrc -SRCS= checkpath.c fstabinfo.c mountinfo.c openrc-run.c \ - rc-applets.c rc-depend.c rc-logger.c \ - rc-misc.c rc-plugin.c rc-service.c rc-status.c rc-update.c \ - rc.c start-stop-daemon.c swclock.c +SRCS= rc.crc-logger.c rc-misc.c rc-plugin.c ifeq (${MKSELINUX},yes) SRCS+= rc-selinux.c @@ -14,26 +10,26 @@ BINDIR= ${PREFIX}/bin SBINDIR= ${PREFIX}/sbin LINKDIR= ${LIBEXECDIR} -BINLINKS= rc-status -SBINLINKS= rc rc-service rc-update openrc-run runscript service \ - start-stop-daemon -RC_BINLINKS= einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \ - eindent eoutdent esyslog eval_ecolors ewaitfile \ - veinfo vewarn vebegin veend vewend veindent veoutdent \ - service_starting service_started \ - service_stopping service_stopped \ - service_inactive service_wasinactive \ - service_hotplugged service_started_daemon service_crashed \ - checkpath fstabinfo mountinfo rc-depend \ - service_get_value service_set_value get_options save_options \ - shell_var is_newer_than
[gentoo-commits] proj/openrc:master commit in: src/includes/, src/rc/
commit: 8addd7913a743b75ef3854ab4a96fea81cc5245d Author: William Hubbs gmail com> AuthorDate: Sat Dec 5 00:02:43 2015 + Commit: William Hubbs gentoo org> CommitDate: Tue Dec 8 18:05:59 2015 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8addd791 Create detect_container() and detect_vm() functions These functions replace rc_sys so that we can detect containers and vms separately. Also, we copy file_regex() to rc-misc.c and open it to all operating systems. src/includes/rc-misc.h | 4 ++ src/rc/rc-misc.c | 159 - 2 files changed, 162 insertions(+), 1 deletion(-) diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h index 3cce8d0..e0565b6 100644 --- a/src/includes/rc-misc.h +++ b/src/includes/rc-misc.h @@ -87,4 +87,8 @@ int is_writable(const char *); #define service_stop(service) exec_service(service, "stop"); int parse_mode(mode_t *, char *); +const char *detect_prefix(void); +const char *get_systype(void); +const char *detect_container(void); +const char *detect_vm(void); #endif diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index 27d9f81..1e2af0a 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -34,12 +34,12 @@ #ifdef __linux__ # include -# include #endif #include #include #include +# include #include #include #include @@ -346,3 +346,160 @@ is_writable(const char *path) return 0; } + +static bool file_regex(const char *file, const char *regex) +{ + FILE *fp; + char *line = NULL; + size_t len = 0; + regex_t re; + bool retval = true; + int result; + + if (!(fp = fopen(file, "r"))) + return false; + + if ((result = regcomp(, regex, REG_EXTENDED | REG_NOSUB)) != 0) { + fclose(fp); + line = xmalloc(sizeof(char) * BUFSIZ); + regerror(result, , line, BUFSIZ); + fprintf(stderr, "file_regex: %s", line); + free(line); + return false; + } + + while ((rc_getline(, , fp))) { + char *str = line; + /* some /proc files have \0 separated content so we have to + loop through the 'line' */ + do { + if (regexec(, str, 0, NULL, 0) == 0) + goto found; + str += strlen(str) + 1; + /* len is the size of allocated buffer and we don't + want call regexec BUFSIZE times. find next str */ + while (str < line + len && *str == '\0') + str++; + } while (str < line + len); + } + retval = false; +found: + fclose(fp); + free(line); + regfree(); + + return retval; +} + +const char *detect_prefix(void) +{ +#ifdef PREFIX + return RC_SYS_PREFIX; +#else + return NULL; +#endif +} + +const char *get_systype(void) +{ + char *systype = rc_conf_value("rc_sys"); + if (systype) { + char *s = systype; + /* Convert to uppercase */ + while (s && *s) { + if (islower((unsigned char) *s)) + *s = toupper((unsigned char) *s); + s++; + } + } + return systype; +} + +const char *detect_container(void) +{ + char *systype = get_systype(); + +#ifdef __FreeBSD__ + if (systype && strcmp(systype, RC_SYS_JAIL) == 0) + return RC_SYS_JAIL; + int jailed = 0; + size_t len = sizeof(jailed); + + if (sysctlbyname("security.jail.jailed", , , NULL, 0) == 0) + if (jailed == 1) + return RC_SYS_JAIL; +#endif + +#ifdef __linux__ + if (systype) { + if (strcmp(systype, RC_SYS_UML) == 0) + return RC_SYS_UML; + if (strcmp(systype, RC_SYS_VSERVER) == 0) + return RC_SYS_VSERVER; + if (strcmp(systype, RC_SYS_OPENVZ) == 0) + return RC_SYS_OPENVZ; + if (strcmp(systype, RC_SYS_LXC) == 0) + return RC_SYS_LXC; + if (strcmp(systype, RC_SYS_RKT) == 0) + return RC_SYS_RKT; + if (strcmp(systype, RC_SYS_SYSTEMD_NSPAWN) == 0) + return RC_SYS_SYSTEMD_NSPAWN; + if (strcmp(systype, RC_SYS_DOCKER) == 0) + return RC_SYS_DOCKER; + } + if (file_regex("/proc/cpuinfo", "UML")) + return RC_SYS_UML; + else if (file_regex("/proc/self/status", + "(s_context|VxID):[[:space:]]*[1-9]")) + return RC_SYS_VSERVER; + else if (exists("/proc/vz/veinfo") && !exists("/proc/vz/version")) + return RC_SYS_OPENVZ; + else if