[gentoo-commits] proj/openrc:master commit in: src/librc/

2018-08-06 Thread William Hubbs
commit: 84ed570eaefcbb55b99ba425030bf7d1d1d46137
Author: Zac Medico  gmail  com>
AuthorDate: Mon Aug  6 21:50:41 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Aug  6 22:39:52 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=84ed570e

librc: fix EACCES errno false-positive crash

Use errno != EACCES to fix false-positive for non-root users
with grsecurity kernels.

Fixes: 37e29442721a ("librc: Add check for crashed state")
This fixes #237

 src/librc/librc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 01bfac03..c38695cc 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -850,7 +850,7 @@ rc_service_state(const char *service)
}
 
if (state & RC_SERVICE_STARTED) {
-   if (rc_service_daemons_crashed(service))
+   if (rc_service_daemons_crashed(service) && errno != EACCES)
state |= RC_SERVICE_CRASHED;
}
if (state & RC_SERVICE_STOPPED) {



[gentoo-commits] proj/openrc:master commit in: src/librc/

2018-06-28 Thread William Hubbs
commit: 3a803b3135837665d51ef4dd7a8b913c78e71ff6
Author: William Hubbs  gmail  com>
AuthorDate: Wed Jun 27 17:06:19 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jun 27 17:06:19 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3a803b31

librc-daemon.c: fix memory leaks

 src/librc/librc-daemon.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 173fcb83..6f3b492f 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -422,6 +422,7 @@ rc_service_daemon_set(const char *service, const char *exec,
rename(file, oldfile);
strlcpy(oldfile, file, sizeof(oldfile));
}
+   free(file);
}
closedir(dp);
rc_stringlist_free(match);
@@ -446,10 +447,12 @@ rc_service_daemon_set(const char *service, const char 
*exec,
fclose(fp);
retval = true;
}
+   free(file);
}
} else
retval = true;
 
+   free(dirpath);
return retval;
 }
 librc_hidden_def(rc_service_daemon_set)



[gentoo-commits] proj/openrc:master commit in: src/librc/

2018-06-22 Thread William Hubbs
commit: 72df51e17ba0e1a0f94451b4bbfb338288c4625c
Author: William Hubbs  gmail  com>
AuthorDate: Fri Jun 22 20:41:25 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Jun 22 20:41:25 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=72df51e1

librc-daemon: convert most snprintf calls to xasprintf

 src/librc/librc-daemon.c | 71 
 1 file changed, 36 insertions(+), 35 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index a40150a6..173fcb83 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -23,13 +23,13 @@
 static bool
 pid_is_exec(pid_t pid, const char *exec)
 {
-   char buffer[32];
+   char *buffer = NULL;
FILE *fp;
int c;
bool retval = false;
 
exec = basename_c(exec);
-   snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
+   xasprintf(, "/proc/%d/stat", pid);
if ((fp = fopen(buffer, "r"))) {
while ((c = getc(fp)) != EOF && c != '(')
;
@@ -41,23 +41,27 @@ pid_is_exec(pid_t pid, const char *exec)
}
fclose(fp);
}
+   free(buffer);
return retval;
 }
 
 static bool
 pid_is_argv(pid_t pid, const char *const *argv)
 {
-   char cmdline[32];
+   char *cmdline = NULL;
int fd;
char buffer[PATH_MAX];
char *p;
ssize_t bytes;
 
-   snprintf(cmdline, sizeof(cmdline), "/proc/%u/cmdline", pid);
-   if ((fd = open(cmdline, O_RDONLY)) < 0)
+   xasprintf(, "/proc/%u/cmdline", pid);
+   if ((fd = open(cmdline, O_RDONLY)) < 0) {
+   free(cmdline);
return false;
+   }
bytes = read(fd, buffer, sizeof(buffer));
close(fd);
+   free(cmdline);
if (bytes == -1)
return false;
 
@@ -88,7 +92,7 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t 
uid, pid_t pid)
char proc_ns[30];
size_t len = 0;
pid_t p;
-   char buffer[PATH_MAX];
+   char *buffer = NULL;
struct stat sb;
pid_t openrc_pid = 0;
char *pp;
@@ -149,18 +153,22 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
continue;
if (pid != 0 && pid != p)
continue;
-   snprintf(buffer, sizeof(buffer), "/proc/%d/ns/pid", p);
+   xasprintf(, "/proc/%d/ns/pid", p);
if (exists(buffer)) {
rc = readlink(buffer, proc_ns, sizeof(proc_ns));
if (rc <= 0)
proc_ns[0] = '\0';
}
+   free(buffer);
if (strlen(my_ns) && strlen (proc_ns) && strcmp(my_ns, proc_ns))
continue;
if (uid) {
-   snprintf(buffer, sizeof(buffer), "/proc/%d", p);
-   if (stat(buffer, ) != 0 || sb.st_uid != uid)
+   xasprintf(, "/proc/%d", p);
+   if (stat(buffer, ) != 0 || sb.st_uid != uid) {
+   free(buffer);
continue;
+   }
+   free(buffer);
}
if (exec && !pid_is_exec(p, exec))
continue;
@@ -169,9 +177,10 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
continue;
/* If this is an OpenVZ host, filter out container processes */
if (openvz_host) {
-   snprintf(buffer, sizeof(buffer), "/proc/%d/status", p);
+   xasprintf(, "/proc/%d/status", p);
if (exists(buffer)) {
fp = fopen(buffer, "r");
+   free(buffer);
if (! fp)
continue;
while (! feof(fp)) {
@@ -315,12 +324,13 @@ _match_daemon(const char *path, const char *file, 
RC_STRINGLIST *match)
 {
char *line = NULL;
size_t len = 0;
-   char ffile[PATH_MAX];
+   char *ffile = NULL;
FILE *fp;
RC_STRING *m;
 
-   snprintf(ffile, sizeof(ffile), "%s/%s", path, file);
+   xasprintf(, "%s/%s", path, file);
fp = fopen(ffile, "r");
+   free(ffile);
 
if (!fp)
return false;
@@ -346,29 +356,22 @@ _match_list(const char *exec, const char *const *argv, 
const char *pidfile)
 {
RC_STRINGLIST *match = rc_stringlist_new();
int i = 0;
-   size_t l;
char *m;
 
if (exec) {
-   l = strlen(exec) + 6;
-   m = xmalloc(sizeof(char) * l);
-   snprintf(m, l, "exec=%s", exec);
+   xasprintf(, "exec=%s", exec);
   

[gentoo-commits] proj/openrc:master commit in: src/librc/

2018-06-20 Thread William Hubbs
commit: b2f5531194e33c229462e9f52fa1d9388463f7b7
Author: William Hubbs  gmail  com>
AuthorDate: Wed Jun 20 22:45:01 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jun 20 22:45:01 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b2f55311

librc-misc: convert snprintf calls to xasprintf

 src/librc/librc-misc.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 9d514bcd..178768c5 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -237,13 +237,9 @@ static void rc_config_set_value(RC_STRINGLIST *config, 
char *value)
if (token[i] == '\n')
token[i] = 0;
 
-   i = strlen(entry) + strlen(token) + 2;
-   newline = xmalloc(sizeof(char) * i);
-   snprintf(newline, i, "%s=%s", entry, token);
+   xasprintf(, "%s=%s", entry, token);
} else {
-   i = strlen(entry) + 2;
-   newline = xmalloc(sizeof(char) * i);
-   snprintf(newline, i, "%s=", entry);
+   xasprintf(, "%s=", entry);
}
 
replaced = false;
@@ -300,8 +296,7 @@ static RC_STRINGLIST *rc_config_kcl(RC_STRINGLIST *config)
 
if (value != NULL) {
len = varlen + strlen(value) + 2;
-   tmp = xmalloc(sizeof(char) * len);
-   snprintf(tmp, len, "%s=%s", override->value, value);
+   xasprintf(, "%s=%s", override->value, value);
}
 
/*



[gentoo-commits] proj/openrc:master commit in: src/librc/

2018-05-22 Thread William Hubbs
commit: 37e29442721af0dc3846e87ef2b85a474af3cf2b
Author: William Hubbs  gmail  com>
AuthorDate: Fri May 18 23:28:07 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 22 17:19:41 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=37e29442

librc: Add check for crashed state

In rc_service_state,, call rc_service_daemons_crashed to check for
a crashed daemon if the service is started.

 src/librc/librc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 4473a1bb..01bfac03 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -849,6 +849,10 @@ rc_service_state(const char *service)
}
}
 
+   if (state & RC_SERVICE_STARTED) {
+   if (rc_service_daemons_crashed(service))
+   state |= RC_SERVICE_CRASHED;
+   }
if (state & RC_SERVICE_STOPPED) {
dirs = ls_dir(RC_SVCDIR "/scheduled", 0);
TAILQ_FOREACH(dir, dirs, entries) {



[gentoo-commits] proj/openrc:master commit in: src/librc/

2018-05-22 Thread William Hubbs
commit: 4e0eace837287845504c9895429dc9f64872d075
Author: William Hubbs  gmail  com>
AuthorDate: Thu May 17 22:42:14 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 22 17:19:22 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4e0eace8

librc: Add crashed state

 src/librc/librc.c | 1 +
 src/librc/rc.h.in | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index ee65b00a..4473a1bb 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -50,6 +50,7 @@ static const rc_service_state_name_t rc_service_state_names[] 
= {
{ RC_SERVICE_HOTPLUGGED,  "hotplugged" },
{ RC_SERVICE_FAILED,  "failed" },
{ RC_SERVICE_SCHEDULED,   "scheduled"},
+   { RC_SERVICE_CRASHED, "crashed"},
{ 0, NULL}
 };
 

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 1f984d52..d2e51dc6 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -188,7 +188,8 @@ typedef enum
/* Optional states service could also be in */
RC_SERVICE_FAILED  = 0x0200,
RC_SERVICE_SCHEDULED   = 0x0400,
-   RC_SERVICE_WASINACTIVE = 0x0800
+   RC_SERVICE_WASINACTIVE = 0x0800,
+   RC_SERVICE_CRASHED = 0x1000,
 } RC_SERVICE;
 
 /*! Add the service to the runlevel



[gentoo-commits] proj/openrc:master commit in: src/librc/

2017-11-30 Thread William Hubbs
commit: a7c99506d9de81b9a2a7547bd11715073de1ce95
Author: Will Miles  sgl  com>
AuthorDate: Thu Aug 24 01:53:16 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Nov 30 19:56:54 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a7c99506

Fix repeated dependency cache rebuild if clock skewed

rc_deptree_update_needed would return early as soon as it found
any file newer than the existing dependency cache.  Unfortunately,
the first file found may not be the newest one there; so the
clock skew workaround in rc-misc:_rc_deptree_load would be given
a timestamp that was still too old.

This fix forces a full scan of all relevant files, so as to
ensure that we return a timestamp that will allow the clock skew
fix to operate.   The runtime cost is no worse than the case where
the cache is up to date (ie. we must check every possible file).

This fixes #161.

 src/librc/librc-depend.c | 123 +++
 1 file changed, 71 insertions(+), 52 deletions(-)

diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index 1c993998..37f0b60d 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -542,52 +542,41 @@ rc_deptree_order(const RC_DEPTREE *deptree, const char 
*runlevel, int options)
 }
 librc_hidden_def(rc_deptree_order)
 
+
+/* Given a time, recurse the target path to find out if there are
+   any older (or newer) files.   If false, sets the time to the
+   oldest (or newest) found.
+*/
 static bool
-mtime_check(const char *source, const char *target, bool newer,
+deep_mtime_check(const char *target, bool newer,
time_t *rel, char *file)
 {
struct stat buf;
-   time_t mtime;
bool retval = true;
DIR *dp;
struct dirent *d;
char path[PATH_MAX];
int serrno = errno;
 
-   /* We have to exist */
-   if (stat(source, ) != 0)
-   return false;
-   mtime = buf.st_mtime;
-
/* If target does not exist, return true to mimic shell test */
if (stat(target, ) != 0)
return true;
 
if (newer) {
-   if (mtime < buf.st_mtime) {
-   if (rel == NULL)
-   return false;
+   if (*rel < buf.st_mtime) {
retval = false;
-   }
-   if (rel != NULL) {
-   if (*rel < buf.st_mtime) {
-   if (file)
-   strlcpy(file, target, PATH_MAX);
-   *rel = buf.st_mtime;
-   }
+
+   if (file)
+   strlcpy(file, target, PATH_MAX);
+   *rel = buf.st_mtime;
}
} else {
-   if (mtime > buf.st_mtime) {
-   if (rel == NULL)
-   return false;
+   if (*rel > buf.st_mtime) {
retval = false;
-   }
-   if (rel != NULL) {
-   if (*rel > buf.st_mtime) {
-   if (file)
-   strlcpy(file, target, PATH_MAX);
-   *rel = buf.st_mtime;
-   }
+
+   if (file)
+   strlcpy(file, target, PATH_MAX);
+   *rel = buf.st_mtime;
}
}
 
@@ -602,16 +591,38 @@ mtime_check(const char *source, const char *target, bool 
newer,
if (d->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%s/%s", target, d->d_name);
-   if (!mtime_check(source, path, newer, rel, file)) {
+   if (!deep_mtime_check(path, newer, rel, file)) {
retval = false;
-   if (rel == NULL)
-   break;
}
}
closedir(dp);
return retval;
 }
 
+/* Recursively check if target is older/newer than source.
+ * If false, return the filename and most different time (if
+ * the return value arguments are non-null).
+ */
+static bool
+mtime_check(const char *source, const char *target, bool newer,
+   time_t *rel, char *file)
+{
+   struct stat buf;
+   time_t mtime;
+   bool retval = true;
+
+   /* We have to exist */
+   if (stat(source, ) != 0)
+   return false;
+   mtime = buf.st_mtime;
+
+retval = deep_mtime_check(target,newer,,file);
+if (rel) {
+*rel = mtime;
+}
+return retval;
+}
+
 bool
 rc_newer_than(const char *source, const char *target,
  time_t *newest, char *file)
@@ -670,6 +681,8 @@ rc_deptree_update_needed(time_t *newest, char *file)
RC_STRINGLIST *config;
RC_STRING *s;
int i;
+   struct stat buf;
+   time_t mtime;

[gentoo-commits] proj/openrc:master commit in: src/librc/

2017-11-14 Thread William Hubbs
commit: 971e82784cd1ad8f9a286ee792e6417359972976
Author: William Hubbs  gmail  com>
AuthorDate: Mon Nov 13 22:54:57 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Nov 13 22:54:57 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=971e8278

rc_find_pids: namespace fix

Ignore namespaces if there are errors reading either the pid namespace
for the current process or the process we aare testing.

This fixes https://github.com/openrc/openrc/issues/180.

 src/librc/librc-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 916cc142..a40150a6 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -155,7 +155,7 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
if (rc <= 0)
proc_ns[0] = '\0';
}
-   if (strcmp(my_ns, proc_ns))
+   if (strlen(my_ns) && strlen (proc_ns) && strcmp(my_ns, proc_ns))
continue;
if (uid) {
snprintf(buffer, sizeof(buffer), "/proc/%d", p);



[gentoo-commits] proj/openrc:master commit in: src/librc/

2017-10-26 Thread William Hubbs
commit: cf429ee359356d736c818e8b35db8fca887e7332
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 17:54:37 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 17:54:37 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cf429ee3

rc_service_value_set: remove the option if NULL is the value

This allows the equivalent of "unsetting" a value for a service.

 src/librc/librc.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 84c76b5a..ee65b00a 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -894,12 +894,15 @@ rc_service_value_set(const char *service, const char 
*option,
return false;
 
snprintf(p, sizeof(file) - (p - file), "/%s", option);
-   if (!(fp = fopen(file, "w")))
-   return false;
-   if (value)
+   if (value) {
+   if (!(fp = fopen(file, "w")))
+   return false;
fprintf(fp, "%s", value);
-   fclose(fp);
-   return true;
+   fclose(fp);
+   } else {
+   unlink(file);
+   }
+   return true;
 }
 librc_hidden_def(rc_service_value_set)
 



[gentoo-commits] proj/openrc:master commit in: src/librc/

2017-10-24 Thread William Hubbs
commit: f5acc66db7d1a0bfad6a40eefc0240b80f52df94
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct 24 15:37:01 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct 24 15:37:37 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f5acc66d

rc_find_pids: ignore pids that are not in our pid namespace

X-Gentoo-Bug: 634634
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=634634

 src/librc/librc-daemon.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 56aaa91b..916cc142 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -80,9 +80,12 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
DIR *procdir;
struct dirent *entry;
FILE *fp;
+   int rc;
bool container_pid = false;
bool openvz_host = false;
char *line = NULL;
+   char my_ns[30];
+   char proc_ns[30];
size_t len = 0;
pid_t p;
char buffer[PATH_MAX];
@@ -131,6 +134,14 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
}
}
 
+   memset(my_ns, 0, sizeof(my_ns));
+   memset(proc_ns, 0, sizeof(proc_ns));
+   if (exists("/proc/self/ns/pid")) {
+   rc = readlink("/proc/self/ns/pid", my_ns, sizeof(my_ns));
+   if (rc <= 0)
+   my_ns[0] = '\0';
+   }
+
while ((entry = readdir(procdir)) != NULL) {
if (sscanf(entry->d_name, "%d", ) != 1)
continue;
@@ -138,6 +149,14 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
continue;
if (pid != 0 && pid != p)
continue;
+   snprintf(buffer, sizeof(buffer), "/proc/%d/ns/pid", p);
+   if (exists(buffer)) {
+   rc = readlink(buffer, proc_ns, sizeof(proc_ns));
+   if (rc <= 0)
+   proc_ns[0] = '\0';
+   }
+   if (strcmp(my_ns, proc_ns))
+   continue;
if (uid) {
snprintf(buffer, sizeof(buffer), "/proc/%d", p);
if (stat(buffer, ) != 0 || sb.st_uid != uid)



[gentoo-commits] proj/openrc:master commit in: src/librc/, /, man/, src/rc/, etc/

2017-04-06 Thread William Hubbs
commit: 13ca79856e5836117e469c3edbcfd4bf47b6bab0
Author: William Hubbs  gmail  com>
AuthorDate: Thu Apr  6 22:13:59 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Apr  6 22:13:59 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=13ca7985

add init process

openrc-init.c and openrc-shutdown.c are based on code which was written by
James Hammons  acm.org>, so I would like to publically
thank him for his work.

 NEWS.md  |   7 ++
 etc/rc.conf  |   5 ++
 man/Makefile |   2 +-
 man/openrc-init.8|  46 +
 man/openrc-shutdown.8|  42 
 src/librc/rc.h.in|   1 +
 src/rc/.gitignore|   2 +
 src/rc/Makefile  |  21 +-
 src/rc/openrc-init.c | 168 +++
 src/rc/openrc-shutdown.c | 119 +
 10 files changed, 410 insertions(+), 3 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 9d5117f8..90a452b6 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -3,6 +3,13 @@
 This file will contain a list of notable changes for each release. Note
 the information in this file is in reverse order.
 
+## OpenRC-0.25
+
+This version contains an OpenRC-specific implementation of init for
+Linux which can be used in place of sysvinit or any other init process.
+For information on its usage, see the man pages for openrc-init (8) and
+openrc-shutdown (8).
+
 ## OpenRC-0.24.1
 
 This version starts cleaning up the dependencies so that rc_parallel

diff --git a/etc/rc.conf b/etc/rc.conf
index 028ceab4..689e6be2 100644
--- a/etc/rc.conf
+++ b/etc/rc.conf
@@ -178,6 +178,11 @@
 # "xenU"   - XenU Domain (Linux and NetBSD)
 #rc_sys=""
 
+# if  you use openrc-init, which is currently only available on Linux,
+# this is the default runlevel to activate after "sysinit" and "boot"
+# when booting.
+#rc_default_runlevel="default"
+
 # on Linux and Hurd, this is the number of ttys allocated for logins
 # It is used in the consolefont, keymaps, numlock and termencoding
 # service scripts.

diff --git a/man/Makefile b/man/Makefile
index 48c58429..a72b7e72 100644
--- a/man/Makefile
+++ b/man/Makefile
@@ -9,7 +9,7 @@ MAN8=   rc-service.8 rc-status.8 rc-update.8 openrc.8 
openrc-run.8 \
service.8 start-stop-daemon.8 supervise-daemon.8
 
 ifeq (${OS},Linux)
-MAN8 += rc-sstat.8
+MAN8 += rc-sstat.8 openrc-init.8 openrc-shutdown.8
 endif
 
 # Handy macro to create symlinks

diff --git a/man/openrc-init.8 b/man/openrc-init.8
new file mode 100644
index ..93068f10
--- /dev/null
+++ b/man/openrc-init.8
@@ -0,0 +1,46 @@
+.\" Copyright (c) 2017 The OpenRC Authors.
+.\" See the Authors file at the top-level directory of this distribution and
+.\" https://github.com/OpenRC/openrc/blob/master/AUTHORS
+.\"
+.\" This file is part of OpenRC. It is subject to the license terms in
+.\" the LICENSE file found in the top-level directory of this
+.\" distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
+.\" This file may not be copied, modified, propagated, or distributed
+.\"except according to the terms contained in the LICENSE file.
+.\"
+.Dd April 6, 2017
+.Dt openrc-init 8 SMM
+.Os OpenRC
+.Sh NAME
+.Nm openrc-init
+.Nd the parent of all processes
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+.Nm
+is an init process which can be an alternative to sysvinit or any other
+init process.
+.Pp
+To use
+.Nm
+configure your boot loader to invoke it or symlink it to /sbin/init.
+Also, you will need to use
+.Xr openrc-shutdown 8 ,
+to halt, reboot or poweroff the system.
+.Pp
+The default runlevel is read from the init command line, the
+rc_default_runlevel setting in rc.conf, the kernel command line, or it is
+assumed to be "default" if it is not set in any of these places.
+.Pp
+.Nm
+doesn't manage getty's directly, so you will need to manage them another
+way. For example, you can use the agetty service script as described in
+agetty-guide.md in this distribution.
+.Sh BUGS
+OpenRC 0.25 contains the first release of this init process.
+I do not know of any specific issues. However, if you use it, please be
+aware that there may be bugs and report any issues you find.
+.Sh SEE ALSO
+.Xr openrc-shutdown 8 ,
+.Sh AUTHORS
+.An William Hubbs 

diff --git a/man/openrc-shutdown.8 b/man/openrc-shutdown.8
new file mode 100644
index ..98ec64a6
--- /dev/null
+++ b/man/openrc-shutdown.8
@@ -0,0 +1,42 @@
+.\" Copyright (c) 2017 The OpenRC Authors.
+.\" See the Authors file at the top-level directory of this distribution and
+.\" https://github.com/OpenRC/openrc/blob/master/AUTHORS
+.\"
+.\" This file is part of OpenRC. It is subject to the license terms in
+.\" the LICENSE file found in the top-level directory of this
+.\" distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
+.\" This file may not be copied, modified, propagated, or distributed
+.\"except according to the 

[gentoo-commits] proj/openrc:master commit in: src/librc/

2016-12-19 Thread William Hubbs
commit: 45aa36cc623eeeb15fb6827b57e0c07a37cdef41
Author: Doug Freed  mtu  edu>
AuthorDate: Mon Dec 19 00:43:27 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Dec 20 00:24:31 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=45aa36cc

librc: detect loops in stacked runlevels and abort

This fixes #109.
X-Gentoo-Bug: 558700
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=558700

 src/librc/librc.c | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index fdde3d5..3d3277d 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -367,11 +367,12 @@ rc_parse_service_state(RC_SERVICE state)
  * specified runlevel in dependency order, including the
  * specified runlevel. */
 static void
-get_runlevel_chain(const char *runlevel, RC_STRINGLIST *level_list)
+get_runlevel_chain(const char *runlevel, RC_STRINGLIST *level_list, 
RC_STRINGLIST *ancestor_list)
 {
char path[PATH_MAX];
RC_STRINGLIST *dirs;
-   RC_STRING *d, *dn;
+   RC_STRING *d, *parent;
+   const char *nextlevel;
 
/*
 * If we haven't been passed a runlevel or a level list, or
@@ -395,8 +396,27 @@ get_runlevel_chain(const char *runlevel, RC_STRINGLIST 
*level_list)
 */
snprintf(path, sizeof(path), "%s/%s", RC_RUNLEVELDIR, runlevel);
dirs = ls_dir(path, LS_DIR);
-   TAILQ_FOREACH_SAFE(d, dirs, entries, dn)
-   get_runlevel_chain(d->value, level_list);
+   TAILQ_FOREACH(d, dirs, entries) {
+   nextlevel = d->value;
+
+   /* Check for loop */
+   if (rc_stringlist_find(ancestor_list, nextlevel)) {
+   fprintf(stderr, "Loop detected in stacked runlevels 
attempting to enter runlevel %s!\n",
+   nextlevel);
+   fprintf(stderr, "Ancestors:\n");
+   TAILQ_FOREACH(parent, ancestor_list, entries)
+   fprintf(stderr, "\t%s\n", parent->value);
+   exit(1);
+   }
+
+   /* Add new ancestor */
+   rc_stringlist_add(ancestor_list, nextlevel);
+
+   get_runlevel_chain(nextlevel, level_list, ancestor_list);
+
+   rc_stringlist_delete(ancestor_list, nextlevel);
+   }
+   rc_stringlist_free(dirs);
 }
 
 bool
@@ -500,9 +520,12 @@ librc_hidden_def(rc_runlevel_unstack)
 RC_STRINGLIST *
 rc_runlevel_stacks(const char *runlevel)
 {
-   RC_STRINGLIST *stack;
+   RC_STRINGLIST *stack, *ancestor_list;
stack = rc_stringlist_new();
-   get_runlevel_chain(runlevel, stack);
+   ancestor_list = rc_stringlist_new();
+   rc_stringlist_add(ancestor_list, runlevel);
+   get_runlevel_chain(runlevel, stack, ancestor_list);
+   rc_stringlist_free(ancestor_list);
return stack;
 }
 librc_hidden_def(rc_runlevel_stacks)



[gentoo-commits] proj/openrc:master commit in: src/librc/

2016-08-15 Thread William Hubbs
commit: ca8c29ee60b0e8ca89091aaf801725bd71e28001
Author: William Hubbs  gmail  com>
AuthorDate: Sun Jul 31 17:24:56 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Jul 31 17:24:56 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ca8c29ee

librc: fix Docker auto detection

The original auto detection of Docker containers assumed the presence of
a container environment variable. However, Docker-1.12 does not
implement this, and I'm not sure which versions of docker implemented
it.

The new test is for the presence of a file named .dockerenv in the
root directory.

 src/librc/librc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 3e1f0d8..fdde3d5 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -285,6 +285,9 @@ detect_container(const char *systype)
return RC_SYS_RKT;
else if (file_regex("/proc/1/environ", "container=systemd-nspawn"))
return RC_SYS_SYSTEMD_NSPAWN;
+   else if (exists("/.dockerenv"))
+   return RC_SYS_DOCKER;
+   /* old test, I'm not sure when this was valid. */
else if (file_regex("/proc/1/environ", "container=docker"))
return RC_SYS_DOCKER;
 #endif



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/rc/, /

2016-07-14 Thread William Hubbs
commit: 3a1262703fd20d2e8288d13d908fb282c77d1793
Author: William Hubbs  gmail  com>
AuthorDate: Sun Mar 22 20:04:14 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jul 14 21:52:57 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3a126270

Remove the DEBUG_MEMORY macro

This fixes #43.

 README.md  |  3 ---
 src/librc/librc-misc.c | 18 ++
 src/rc/openrc-run.c|  4 
 src/rc/rc-misc.c   |  2 --
 src/rc/rc-service.c|  6 --
 src/rc/rc-status.c |  2 --
 src/rc/rc.c| 16 ++--
 src/rc/start-stop-daemon.c |  4 
 8 files changed, 12 insertions(+), 43 deletions(-)

diff --git a/README.md b/README.md
index 7fadd23..edf6426 100644
--- a/README.md
+++ b/README.md
@@ -43,9 +43,6 @@ We don't support building a static OpenRC with PAM.
 
 You may need to use `PROGLDFLAGS=-Wl,-Bstatic` on glibc instead of just 
`-static`.
 
-If you debug memory under valgrind, add `-DDEBUG_MEMORY`
-to your `CPPFLAGS` so that all malloc memory should be freed at exit.
-
 If you are building OpenRC for a Gentoo Prefix installation, add 
`MKPREFIX=yes`.
 
 `PKG_PREFIX` should be set to where packages install to by default.

diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index d558941..45bdb7a 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -404,6 +404,12 @@ librc_hidden_def(rc_config_value)
  * each rc_conf_value call */
 static RC_STRINGLIST *rc_conf = NULL;
 
+static void
+_free_rc_conf(void)
+{
+   rc_stringlist_free(rc_conf);
+}
+
 char *
 rc_conf_value(const char *setting)
 {
@@ -413,17 +419,13 @@ rc_conf_value(const char *setting)
 
if (! rc_conf) {
rc_conf = rc_config_load(RC_CONF);
-#ifdef DEBUG_MEMORY
atexit(_free_rc_conf);
-#endif
 
/* Support old configs. */
if (exists(RC_CONF_OLD)) {
old = rc_config_load(RC_CONF_OLD);
TAILQ_CONCAT(rc_conf, old, entries);
-#ifdef DEBUG_MEMORY
free(old);
-#endif
}
 
rc_conf = rc_config_directory(rc_conf);
@@ -443,11 +445,3 @@ rc_conf_value(const char *setting)
return rc_config_value(rc_conf, setting);
 }
 librc_hidden_def(rc_conf_value)
-
-#ifdef DEBUG_MEMORY
-static void
-_free_rc_conf(void)
-{
-   rc_stringlist_free(rc_conf);
-}
-#endif

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index 275cb32..ff884c4 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -247,7 +247,6 @@ cleanup(void)
 
rc_plugin_unload();
 
-#ifdef DEBUG_MEMORY
rc_stringlist_free(deptypes_b);
rc_stringlist_free(deptypes_n);
rc_stringlist_free(deptypes_nw);
@@ -267,7 +266,6 @@ cleanup(void)
free(service);
free(prefix);
free(runlevel);
-#endif
 }
 
 /* Buffer and lock all output messages so that we get readable content */
@@ -1097,9 +1095,7 @@ service_plugable(void)
break;
}
}
-#ifdef DEBUG_MEMORY
free(list);
-#endif
return allow;
 }
 

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index 82f1b78..85a0db7 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -110,11 +110,9 @@ env_filter(void)
setenv(env->value, e + 1, 1);
}
 
-#ifdef DEBUG_MEMORY
rc_stringlist_free(env_list);
rc_stringlist_free(env_allow);
rc_stringlist_free(profile);
-#endif
 }
 
 void

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index 3fd94b2..d0a6499 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -76,9 +76,7 @@ int main(int argc, char **argv)
case 'e':
service = rc_service_resolve(optarg);
opt = service ? EXIT_SUCCESS : EXIT_FAILURE;
-#ifdef DEBUG_MEMORY
free(service);
-#endif
return opt;
/* NOTREACHED */
case 'i':
@@ -97,9 +95,7 @@ int main(int argc, char **argv)
rc_stringlist_sort();
TAILQ_FOREACH(s, list, entries)
printf("%s\n", s->value);
-#ifdef DEBUG_MEMORY
rc_stringlist_free(list);
-#endif
return EXIT_SUCCESS;
/* NOTREACHED */
case 'r':
@@ -107,9 +103,7 @@ int main(int argc, char **argv)
if (service == NULL)
return EXIT_FAILURE;
printf("%s\n", service);
-#ifdef DEBUG_MEMORY
free(service);
-#endif
return EXIT_SUCCESS;
/* NOTREACHED */
 

diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index a0a2fce..6724db8 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -331,7 +331,6 @@ int 

[gentoo-commits] proj/openrc:master commit in: src/librc/

2016-01-18 Thread William Hubbs
commit: 4c814a0a285565bc09d662f602f93dbb938503c6
Author: Doug Freed  mtu  edu>
AuthorDate: Mon Jan 18 06:39:11 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 19 06:09:20 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4c814a0a

librc: handle rc_sys="prefix" even if we weren't built with a prefix

This probably isn't needed, but it mimics old behavior.

 src/librc/librc.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 8b4e8d4..3e1f0d8 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -220,6 +220,13 @@ detect_prefix(const char *systype)
 #ifdef PREFIX
return RC_SYS_PREFIX;
 #else
+   if (systype) {
+   if (strcmp(systype, RC_SYS_NONE) == 0)
+   return NULL;
+   if (strcmp(systype, RC_SYS_PREFIX) == 0)
+   return RC_SYS_PREFIX;
+   }
+
return NULL;
 #endif
 }



[gentoo-commits] proj/openrc:master commit in: src/librc/

2016-01-18 Thread William Hubbs
commit: 6c0942137572608d02eb4b34bad55c9bf418a6ba
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jan 19 05:40:03 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 19 05:40:03 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6c094213

Revert "librc: fix librc-depend functions to call rc_sys"

This reverts commit 73482cf13a338051606788957cbd0031ac850c70.

 src/librc/librc-depend.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index d64b2b2..991a871 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 = rc_sys();
+   const char *sys = NULL;
struct utsname uts;
 
/* Some init scripts need RC_LIBEXECDIR to source stuff
@@ -847,6 +847,9 @@ 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);



[gentoo-commits] proj/openrc:master commit in: src/librc/

2016-01-18 Thread William Hubbs
commit: 36dde4e7f21afba36a96837aa86f2b5d2dae3807
Author: Doug Freed  mtu  edu>
AuthorDate: Mon Jan 18 06:05:22 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 19 06:09:20 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=36dde4e7

librc: fix handling the nothing special case for rc_sys

 src/librc/librc.c | 15 +--
 src/librc/rc.h.in |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 5cf4898..8b4e8d4 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -228,8 +228,13 @@ static const char *
 detect_container(const char *systype)
 {
 #ifdef __FreeBSD__
-   if (systype && strcmp(systype, RC_SYS_JAIL) == 0)
-   return RC_SYS_JAIL;
+   if (systype) {
+   if (strcmp(systype, RC_SYS_NONE) == 0)
+  return NULL;
+   if (strcmp(systype, RC_SYS_JAIL) == 0)
+   return RC_SYS_JAIL;
+   }
+
int jailed = 0;
size_t len = sizeof(jailed);
 
@@ -240,6 +245,8 @@ detect_container(const char *systype)
 
 #ifdef __linux__
if (systype) {
+   if (strcmp(systype, RC_SYS_NONE) == 0)
+   return NULL;
if (strcmp(systype, RC_SYS_UML) == 0)
return RC_SYS_UML;
if (strcmp(systype, RC_SYS_VSERVER) == 0)
@@ -283,6 +290,8 @@ detect_vm(const char *systype)
 {
 #ifdef __NetBSD__
if (systype) {
+   if (strcmp(systype, RC_SYS_NONE) == 0)
+   return NULL;
if (strcmp(systype, RC_SYS_XEN0) == 0)
return RC_SYS_XEN0;
if (strcmp(systype, RC_SYS_XENU) == 0)
@@ -296,6 +305,8 @@ detect_vm(const char *systype)
 
 #ifdef __linux__
if (systype) {
+   if (strcmp(systype, RC_SYS_NONE) == 0)
+   return NULL;
if (strcmp(systype, RC_SYS_XEN0) == 0)
return RC_SYS_XEN0;
if (strcmp(systype, RC_SYS_XENU) == 0)

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 55fbc44..92ecbb4 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -318,6 +318,7 @@ bool rc_service_daemons_crashed(const char *);
  * Some services cannot work in these systems, or we do something else. */
 #define RC_SYS_DOCKER  "DOCKER"
 #define RC_SYS_JAIL"JAIL"
+#define RC_SYS_NONE""
 #define RC_SYS_OPENVZ  "OPENVZ"
 #define RC_SYS_LXC "LXC"
 #define RC_SYS_PREFIX  "PREFIX"



[gentoo-commits] proj/openrc:master commit in: src/librc/

2016-01-18 Thread William Hubbs
commit: 73482cf13a338051606788957cbd0031ac850c70
Author: William Hubbs  gmail  com>
AuthorDate: Mon Jan 18 21:09:31 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jan 18 21:09:31 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=73482cf1

librc: fix librc-depend functions to call rc_sys

 src/librc/librc-depend.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

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);



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/rc/

2015-12-08 Thread William Hubbs
commit: 9f6e05671d6d48faa7b83aec05a637bcdfcb3f82
Author: William Hubbs  gmail  com>
AuthorDate: Mon Dec  7 23:56:02 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Dec  8 18:09:33 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=9f6e0567

Convert rc_sys() calls to detect_container() and detect_vm()

 src/librc/librc-depend.c |  5 -
 src/rc/_usage.c  |  5 -
 src/rc/rc-misc.c |  6 --
 src/rc/rc.c  | 20 
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index c9c06ad..14cf297 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -753,7 +753,7 @@ rc_deptree_update(void)
char *depend, *depends, *service, *type, *nosys, *onosys;
size_t i, k, l;
bool retval = true;
-   const char *sys = rc_sys();
+   const char *sys = NULL;
struct utsname uts;
 
/* Some init scripts need RC_LIBEXECDIR to source stuff
@@ -860,6 +860,9 @@ 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/rc/_usage.c b/src/rc/_usage.c
index 2ab0fa6..a6bad4d 100644
--- a/src/rc/_usage.c
+++ b/src/rc/_usage.c
@@ -56,7 +56,10 @@ show_version(void)
const char *systype = NULL;
 
printf("%s (OpenRC", applet);
-   if ((systype = rc_sys()))
+   systype = detect_container();
+   if (!systype)
+   systype = detect_vm();
+   if (systype)
printf(" [%s]", systype);
printf(") %s", VERSION);
 #ifdef BRANDING

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index 1e2af0a..263c0ed 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -139,7 +139,7 @@ env_config(void)
char *np;
char *npp;
char *tok;
-   const char *sys = rc_sys();
+   const char *sys = NULL;
char buffer[PATH_MAX];
 
/* Ensure our PATH is prefixed with the system locations first
@@ -190,7 +190,9 @@ env_config(void)
} else
setenv("RC_DEFAULTLEVEL", RC_LEVEL_DEFAULT, 1);
 
-   if (sys)
+   sys = detect_container();
+   if (!sys)
+   sys = detect_vm();
setenv("RC_SYS", sys, 1);
 
 #ifdef PREFIX

diff --git a/src/rc/rc.c b/src/rc/rc.c
index 8f69333..ddc3c78 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -274,7 +274,11 @@ open_shell(void)
struct passwd *pw;
 
 #ifdef __linux__
-   const char *sys = rc_sys();
+   const char *sys = NULL;
+   
+   sys = detect_container();
+   if (!sys)
+   sys = detect_vm();
 
/* VSERVER and OPENVZ systems cannot really drop to shells */
if (sys &&
@@ -480,7 +484,10 @@ do_sysinit()
uts.machine);
 #endif
 
-   if ((sys = rc_sys()))
+   sys = detect_container();
+   if (!sys)
+   sys = detect_vm();
+   if (sys)
printf(" [%s]", sys);
 
printf("%s\n\n", ecolor(ECOLOR_NORMAL));
@@ -495,7 +502,10 @@ do_sysinit()
 
/* init may have mounted /proc so we can now detect or real
 * sys */
-   if ((sys = rc_sys()))
+   sys = detect_container();
+   if (!sys)
+   sys = detect_vm();
+   if (sys)
setenv("RC_SYS", sys, 1);
 }
 
@@ -846,7 +856,9 @@ main(int argc, char **argv)
eerrorx("%s: %s", applet, strerror(errno));
/* NOTREACHED */
case 'S':
-   systype = rc_sys();
+   systype = detect_container();
+   if (!systype)
+   systype = detect_vm();
if (systype)
printf("%s\n", systype);
exit(EXIT_SUCCESS);



[gentoo-commits] proj/openrc:master commit in: src/librc/

2015-12-08 Thread William Hubbs
commit: f9bdb072e8d88079a20834fe921d43e326a9a18a
Author: William Hubbs  gmail  com>
AuthorDate: Tue Dec  8 18:50:47 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Dec  8 18:50:47 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f9bdb072

rc.map: remove references to rc_sys_v{1,2}

 src/librc/rc.map | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/librc/rc.map b/src/librc/rc.map
index 2aa58de..0012d8a 100644
--- a/src/librc/rc.map
+++ b/src/librc/rc.map
@@ -59,8 +59,6 @@ global:
rc_stringlist_sort;
rc_stringlist_free;
rc_sys;
-   rc_sys_v1;
-   rc_sys_v2;
rc_yesno;
 
 local:



[gentoo-commits] proj/openrc:master commit in: src/librc/, man/, etc/

2015-12-02 Thread William Hubbs
commit: 9fedb3b40b5983372b2c2de29dfe321c6dfaadf4
Author: William Hubbs  gmail  com>
AuthorDate: Wed Dec  2 00:20:02 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Dec  2 16:20:15 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=9fedb3b4

Add detection for docker containers

 etc/rc.conf.Linux | 1 +
 man/openrc-run.8  | 2 ++
 src/librc/librc.c | 4 
 src/librc/rc.h.in | 1 +
 4 files changed, 8 insertions(+)

diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index f04f96e..0865075 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -3,6 +3,7 @@
 
 # This is the subsystem type. Valid options on Linux:
 # ""   - nothing special
+# "docker" - Docker container manager
 # "lxc"- Linux Containers
 # "openvz" - Linux OpenVZ
 # "prefix" - Prefix

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 12c1919..9e0e776 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -223,6 +223,8 @@ Same as -jail, but for VServer systems.
 Same as -jail, but for Xen DOM0 systems.
 .It Dv -xenu
 Same as -jail, but for Xen DOMU systems.
+.It Dv -docker
+Same as -jail, but for docker systems.
 .El
 .El
 .Pp

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 5e5de8d..cad8033 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -269,6 +269,8 @@ rc_sys(void)
return RC_SYS_LXC;
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 (exists("/proc/xen")) {
if (file_regex("/proc/xen/capabilities", "control_d"))
@@ -288,6 +290,8 @@ rc_sys(void)
return RC_SYS_LXC;
else if (file_regex("/proc/1/environ", "container=systemd-nspawn"))
return RC_SYS_SYSTEMD_NSPAWN;
+   else if (file_regex("/proc/1/environ", "container=docker"))
+   return RC_SYS_DOCKER;
 #endif
 
return NULL;

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 141ecb9..360c26a 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -329,6 +329,7 @@ bool rc_service_daemons_crashed(const char *);
 /*! @name System types
  * OpenRC can support some special sub system types, normally virtualization.
  * Some services cannot work in these systems, or we do something else. */
+#define RC_SYS_DOCKER  "DOCKER"
 #define RC_SYS_JAIL"JAIL"
 #define RC_SYS_OPENVZ  "OPENVZ"
 #define RC_SYS_LXC "LXC"



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/test/

2015-12-02 Thread William Hubbs
commit: 635e33cdc8f18bb290756633ce0714c496383cfb
Author: William Hubbs  gmail  com>
AuthorDate: Tue Dec  1 23:39:04 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Dec  1 23:39:04 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=635e33cd

librc: comsolidate rc_sys_v1 and rc_sys_v2 into rc_sys

These functions were never meant to be used outside of OpenRC, and they
were added when we thought we were going to do away with the automatic
detection of subsystems. Since the autodetection is not going away, we
can combine these functions into rc_sys.

 src/librc/librc.c  | 82 ++
 src/librc/librc.h  |  2 --
 src/librc/rc.h.in  |  8 -
 src/test/rc.funcs.list |  4 ---
 4 files changed, 30 insertions(+), 66 deletions(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 8f04313..5e5de8d 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -210,14 +210,14 @@ found:
 }
 #endif
 
-/* New sys identification code
- * Not to be used for any binaries outside of openrc. */
+
 const char *
-rc_sys_v2(void)
+rc_sys(void)
 {
-#define __STRING_SWITCH(x) { char *__string_switch = x; if (false) {}
-#define __STRING_CASE(y) else if (strcmp(__string_switch,y) == 0)
-#define __STRING_SWITCH_END() }
+#ifdef PREFIX
+   return RC_SYS_PREFIX;
+#endif
+
char *systype = rc_conf_value("rc_sys");
if (systype) {
char *s = systype;
@@ -227,43 +227,11 @@ rc_sys_v2(void)
*s = toupper((unsigned char) *s);
s++;
}
-   /* Now do detection */
-   __STRING_SWITCH(systype)
-   __STRING_CASE(RC_SYS_PREFIX){ return RC_SYS_PREFIX; }
-#ifdef __FreeBSD__
-   __STRING_CASE(RC_SYS_JAIL) { return RC_SYS_JAIL; }
-#endif /* __FreeBSD__ */
-#ifdef __NetBSD__
-   __STRING_CASE(RC_SYS_XEN0) { return RC_SYS_XEN0; }
-   __STRING_CASE(RC_SYS_XENU) { return RC_SYS_XENU; }
-#endif /* __NetBSD__ */
-#ifdef __linux__
-   __STRING_CASE(RC_SYS_XEN0) { return RC_SYS_XEN0; }
-   __STRING_CASE(RC_SYS_XENU) { return RC_SYS_XENU; }
-   __STRING_CASE(RC_SYS_UML) { return RC_SYS_UML; }
-   __STRING_CASE(RC_SYS_VSERVER) { return RC_SYS_VSERVER; }
-   __STRING_CASE(RC_SYS_OPENVZ) { return RC_SYS_OPENVZ; }
-   __STRING_CASE(RC_SYS_LXC) { return RC_SYS_LXC; }
-#endif /* __linux__ */
-   __STRING_SWITCH_END()
}
-#undef __STRING_SWITCH
-#undef __STRING_CASE
-#undef __STRING_SWITCH_END
-   return NULL;
-}
-librc_hidden_def(rc_sys_v2)
-
-/* Old sys identification code.
- * Not to be used for any binaries outside of openrc. */
-const char *
-rc_sys_v1(void)
-{
-#ifdef PREFIX
-   return RC_SYS_PREFIX;
-#else
 
 #ifdef __FreeBSD__
+   if (systype && strcmp(systype, RC_SYS_JAIL) == 0)
+   return RC_SYS_JAIL;
int jailed = 0;
size_t len = sizeof(jailed);
 
@@ -273,6 +241,12 @@ rc_sys_v1(void)
 #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"))
@@ -280,6 +254,22 @@ rc_sys_v1(void)
 #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)
+   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_SYSTEMD_NSPAWN) == 0)
+   return RC_SYS_SYSTEMD_NSPAWN;
+   }
if (exists("/proc/xen")) {
if (file_regex("/proc/xen/capabilities", "control_d"))
return RC_SYS_XEN0;
@@ -301,18 +291,6 @@ rc_sys_v1(void)
 #endif
 
return NULL;
-#endif /* PREFIX */
-}
-librc_hidden_def(rc_sys_v1)
-
-const char *
-rc_sys(void)
-{
-   if (rc_conf_value("rc_sys")) {
-   return rc_sys_v2();
-   } else {
-   return rc_sys_v1();
-   }
 }
 librc_hidden_def(rc_sys)
 

diff --git a/src/librc/librc.h b/src/librc/librc.h
index 0824eba..01bb740 100644
--- a/src/librc/librc.h
+++ b/src/librc/librc.h
@@ -130,8 +130,6 @@ librc_hidden_proto(rc_stringlist_new)
 

[gentoo-commits] proj/openrc:master commit in: src/librc/, man/

2015-12-02 Thread William Hubbs
commit: a0cf8f91246ff4487b36d6432dab787e5b10957d
Author: William Hubbs  gmail  com>
AuthorDate: Wed Dec  2 15:19:45 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Dec  2 16:20:39 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a0cf8f91

Add detection for rkt containers

 man/openrc-run.8  | 2 ++
 src/librc/librc.c | 4 
 src/librc/rc.h.in | 1 +
 3 files changed, 7 insertions(+)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 9e0e776..6aab067 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -215,6 +215,8 @@ Same as -jail, but for Linux Resource Containers (LXC).
 Same as -jail, but for OpenVZ systems.
 .It Dv -prefix
 Same as -jail, but for Prefix systems.
+.It Dv -rkt
+Same as -jail, but for RKT systems.
 .It Dv -uml
 Same as -jail, but for UML systems.
 .It Dv -vserver

diff --git a/src/librc/librc.c b/src/librc/librc.c
index cad8033..c041647 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -267,6 +267,8 @@ rc_sys(void)
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)
@@ -288,6 +290,8 @@ rc_sys(void)
return RC_SYS_OPENVZ; /* old test */
else if (file_regex("/proc/1/environ", "container=lxc"))
return RC_SYS_LXC;
+   else if (file_regex("/proc/1/environ", "container=rkt"))
+   return RC_SYS_RKT;
else if (file_regex("/proc/1/environ", "container=systemd-nspawn"))
return RC_SYS_SYSTEMD_NSPAWN;
else if (file_regex("/proc/1/environ", "container=docker"))

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 360c26a..30c0f8d 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -334,6 +334,7 @@ bool rc_service_daemons_crashed(const char *);
 #define RC_SYS_OPENVZ  "OPENVZ"
 #define RC_SYS_LXC "LXC"
 #define RC_SYS_PREFIX  "PREFIX"
+#define RC_SYS_RKT  "RKT"
 #define RC_SYS_SYSTEMD_NSPAWN "SYSTEMD-NSPAWN"
 #define RC_SYS_UML "UML"
 #define RC_SYS_VSERVER "VSERVER"



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/rc/

2015-11-11 Thread William Hubbs
commit: 085d77f17e3bedd23ffa96fe7e4eb8515ae8bfc6
Author: Benda Xu  gentoo  org>
AuthorDate: Wed Nov 11 19:37:41 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Nov 11 19:37:41 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=085d77f1

Standardize macro tests for gnu hurd

This also fixes breakage of GNU/hurd builds introduced by commit 3f82edbeb92.

 src/librc/librc-daemon.c | 3 ++-
 src/rc/mountinfo.c   | 8 
 src/rc/openrc-run.c  | 4 ++--
 src/rc/rc-logger.c   | 3 ++-
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 4986f70..09b2ce3 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -31,7 +31,8 @@
 #include "queue.h"
 #include "librc.h"
 
-#if defined(__linux__) || (defined (__FreeBSD_kernel__) && defined(__GLIBC__))
+#if defined(__linux__) || (defined (__FreeBSD_kernel__) && defined(__GLIBC__)) 
\
+   || defined(__GNU__)
 static bool
 pid_is_exec(pid_t pid, const char *exec)
 {

diff --git a/src/rc/mountinfo.c b/src/rc/mountinfo.c
index 3f1dfb6..8951c5a 100644
--- a/src/rc/mountinfo.c
+++ b/src/rc/mountinfo.c
@@ -39,8 +39,8 @@
 #  include 
 #  define statfs statvfs
 #  define F_FLAGS f_flag
-#elif defined (__linux__) || (defined(__FreeBSD_kernel__) && \
-   defined(__GLIBC__)) || defined(__GNU__)
+#elif defined(__linux__) || (defined(__FreeBSD_kernel__) && \
+   defined(__GLIBC__)) || defined(__GNU__)
 #  include 
 #endif
 
@@ -267,8 +267,8 @@ find_mounts(struct args *args)
return list;
 }
 
-#elif defined (__linux__) || (defined (__FreeBSD_kernel__) && \
-   defined(__GLIBC__))
+#elif defined(__linux__) || (defined(__FreeBSD_kernel__) && \
+   defined(__GLIBC__)) || defined(__GNU__)
 static struct mntent *
 getmntfile(const char *file)
 {

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index f3a009e..2af95ec 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -51,8 +51,8 @@
 #include 
 #include 
 
-#if defined(__linux__) || (defined(__FreeBSD_kernel__) && \
-   defined(__GLIBC__))
+#if defined(__linux__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) \
+   || defined(__GNU__)
 #  include 
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
 #  include 

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index e72f181..894912f 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -44,7 +44,8 @@
 #include 
 #include 
 
-#if defined(__linux__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
+#if defined(__linux__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) \
+   || defined(__GNU__)
 #  include 
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
 #  include 



[gentoo-commits] proj/openrc:master commit in: src/librc/

2015-11-05 Thread William Hubbs
commit: 591aea28215a8b5ad8660184dc6f6f15ff0c18b4
Author: William Hubbs  gmail  com>
AuthorDate: Thu Nov  5 15:29:33 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Nov  5 17:20:57 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=591aea28

librc: Remove redundant code from rc_config_load

 src/librc/librc-misc.c | 61 +-
 1 file changed, 1 insertion(+), 60 deletions(-)

diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 1eedc96..2c73663 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -378,71 +378,12 @@ rc_config_load(const char *file)
 {
RC_STRINGLIST *list;
RC_STRINGLIST *config;
-   char *token;
RC_STRING *line;
-   RC_STRING *cline;
-   size_t i = 0;
-   bool replaced;
-   char *entry;
-   char *newline;
-   char *p;
 
list = rc_config_list(file);
config = rc_stringlist_new();
TAILQ_FOREACH(line, list, entries) {
-   /* Get entry */
-   p = line->value;
-   if (! p)
-   continue;
-   if (strncmp(p, "export ", 7) == 0)
-   p += 7;
-   if (! (token = strsep(, "=")))
-   continue;
-
-   entry = xstrdup(token);
-   /* Preserve shell coloring */
-   if (*p == '$')
-   token = line->value;
-   else
-   do {
-   /* Bash variables are usually quoted */
-   token = strsep(, "\"\'");
-   } while (token && *token == '\0');
-
-   /* Drop a newline if that's all we have */
-   if (token) {
-   i = strlen(token) - 1;
-   if (token[i] == '\n')
-   token[i] = 0;
-
-   i = strlen(entry) + strlen(token) + 2;
-   newline = xmalloc(sizeof(char) * i);
-   snprintf(newline, i, "%s=%s", entry, token);
-   } else {
-   i = strlen(entry) + 2;
-   newline = xmalloc(sizeof(char) * i);
-   snprintf(newline, i, "%s=", entry);
-   }
-
-   replaced = false;
-   /* In shells the last item takes precedence, so we need to 
remove
-  any prior values we may already have */
-   TAILQ_FOREACH(cline, config, entries) {
-   i = strlen(entry);
-   if (strncmp(entry, cline->value, i) == 0 && 
cline->value[i] == '=') {
-   /* We have a match now - to save time we 
directly replace it */
-   free(cline->value);
-   cline->value = newline;
-   replaced = true;
-   break;
-   }
-   }
-
-   if (!replaced) {
-   rc_stringlist_add(config, newline);
-   free(newline);
-   }
-   free(entry);
+   rc_config_set_value(config, line->value);
}
rc_stringlist_free(list);
 



[gentoo-commits] proj/openrc:master commit in: src/librc/

2015-11-05 Thread William Hubbs
commit: c831f1f994e187afd8edfff15e4063b99440bbcb
Author: William Hubbs  gmail  com>
AuthorDate: Thu Nov  5 17:08:29 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Nov  5 17:20:57 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c831f1f9

librc: rework overriding rc.conf options from the kcl

Rename the rc_conf_override function to describe its purpose better,
drop one conditional compile by making it available everywhere, and move
the call to it after the optional rc.conf.d directory is processed.

 src/librc/librc-misc.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 2c73663..98e6f20 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -280,11 +280,14 @@ static void rc_config_set_value(RC_STRINGLIST *config, 
char *value)
 }
 
 /*
- * Override some specific rc.conf options on the kernel command line
+ * Override some specific rc.conf options on the kernel command line.
+ * I only know how to do this in Linux, so if someone wants to supply
+ * a patch for this on *BSD or tell me how to write the code to do this,
+ * any suggestions are welcome.
  */
-#ifdef __linux__
-static RC_STRINGLIST *rc_config_override(RC_STRINGLIST *config)
+static RC_STRINGLIST *rc_config_kcl(RC_STRINGLIST *config)
 {
+#ifdef __linux__
RC_STRINGLIST *overrides;
RC_STRING *cline, *override, *config_np;
char *tmp = NULL;
@@ -333,9 +336,9 @@ static RC_STRINGLIST *rc_config_override(RC_STRINGLIST 
*config)
}
 
rc_stringlist_free(overrides);
+#endif
return config;
 }
-#endif
 
 static RC_STRINGLIST * rc_config_directory(RC_STRINGLIST *config)
 {
@@ -387,13 +390,6 @@ rc_config_load(const char *file)
}
rc_stringlist_free(list);
 
-#ifdef __linux__
-   /* Only override rc.conf settings */
-   if (strcmp(file, RC_CONF) == 0) {
-   config = rc_config_override(config);
-   }
-#endif
-
return config;
 }
 librc_hidden_def(rc_config_load)
@@ -444,6 +440,7 @@ rc_conf_value(const char *setting)
}
 
rc_conf = rc_config_directory(rc_conf);
+   rc_conf = rc_config_kcl(rc_conf);
 
/* Convert old uppercase to lowercase */
TAILQ_FOREACH(s, rc_conf, entries) {



[gentoo-commits] proj/openrc:master commit in: src/librc/

2015-05-04 Thread William Hubbs
commit: 0b435ddd834bd18254c4d3341acdebf0829921f5
Author: Jakob Drexel jake42 AT rommel DOT stw DOT uni-erlangen DOT 
de
AuthorDate: Sun May  3 09:06:45 2015 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Mon May  4 14:54:51 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0b435ddd

librc: Fix crash if the service name is the same as the including runlevel

If a service has the same name as the runlevel it is in, openrc will
crash on changing to such runlevel. It goes in a recursive madness and
eventually gets a SEGV while in snprintf (don't know why).

This fixes two errors:
1. ls_dir stats files not with full path - stat always returns != 0
2. ls_dir adds files to list if stat failed

This fixes #53.

X-Gentoo-Bug: 537304
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=537304

 src/librc/librc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 03448e7..8f04313 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -101,7 +101,9 @@ ls_dir(const char *dir, int options)
continue;
}
if (options  LS_DIR) {
-   if (stat(d-d_name, buf) == 0 
+   snprintf(file, sizeof(file), %s/%s,
+   dir, d-d_name);
+   if (stat(file, buf) != 0 ||
!S_ISDIR(buf.st_mode))
continue;
}



[gentoo-commits] proj/openrc:master commit in: src/librc/, sh/, etc/

2015-05-01 Thread William Hubbs
commit: c709e6077c6eda3f4f7e798213413254ee0f
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Tue Apr 28 20:07:21 2015 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Fri May  1 14:04:07 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c709e607

Add support for systemd-nspawn containers

This adds support for running OpenRC in a container created by
the systemd-nspawn utility.

This fixes #52.

X-Gentoo-Bug: 548058
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=548058

 etc/rc.conf.Linux   | 17 +
 sh/openrc-run.sh.in |  5 -
 src/librc/librc.c   |  2 ++
 src/librc/rc.h.in   |  1 +
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 79bd971..a8ad58b 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -2,14 +2,15 @@
 # LINUX SPECIFIC OPTIONS
 
 # This is the subsystem type. Valid options on Linux:
-# - nothing special
-# lxc - Linux Containers
-# openvz  - Linux OpenVZ
-# prefix  - Prefix
-# uml - Usermode Linux
-# vserver - Linux vserver
-# xen0- Xen0 Domain
-# xenU- XenU Domain
+#- nothing special
+# lxc- Linux Containers
+# openvz - Linux OpenVZ
+# prefix - Prefix
+# uml- Usermode Linux
+# vserver- Linux vserver
+# systemd-nspawn - Container created by the systemd-nspawn utility
+# xen0   - Xen0 Domain
+# xenU   - XenU Domain
 # If this is commented out, automatic detection will be used.
 #
 # This should be set to the value representing the environment this file is

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index a6d2c0b..e279f11 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -34,7 +34,10 @@ sourcex()
 
 sourcex @LIBEXECDIR@/sh/functions.sh
 sourcex @LIBEXECDIR@/sh/rc-functions.sh
-[ $RC_SYS != PREFIX ]  sourcex -e @LIBEXECDIR@/sh/rc-cgroup.sh
+case $RC_SYS in
+   PREFIX|SYSTEMD-NSPAWN) ;;
+   *) sourcex -e @LIBEXECDIR@/sh/rc-cgroup.sh;;
+esac
 
 # Support LiveCD foo
 if sourcex -e /sbin/livecd-functions.sh; then

diff --git a/src/librc/librc.c b/src/librc/librc.c
index ca51aa6..03448e7 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -294,6 +294,8 @@ rc_sys_v1(void)
return RC_SYS_OPENVZ; /* old test */
else if (file_regex(/proc/1/environ, container=lxc))
return RC_SYS_LXC;
+   else if (file_regex(/proc/1/environ, container=systemd-nspawn))
+   return RC_SYS_SYSTEMD_NSPAWN;
 #endif
 
return NULL;

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 58d8eb5..13e1b5b 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -332,6 +332,7 @@ bool rc_service_daemons_crashed(const char *);
 #define RC_SYS_OPENVZ  OPENVZ
 #define RC_SYS_LXC LXC
 #define RC_SYS_PREFIX  PREFIX
+#define RC_SYS_SYSTEMD_NSPAWN SYSTEMD-NSPAWN
 #define RC_SYS_UML UML
 #define RC_SYS_VSERVER VSERVER
 #define RC_SYS_XEN0XEN0



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/rc/

2015-03-24 Thread William Hubbs
commit: f085ae400c60289f61d99e9e80ce037beedf38b4
Author: Doug Freed dwfreed AT mtu DOT edu
AuthorDate: Tue Mar 24 19:28:47 2015 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Wed Mar 25 00:08:29 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f085ae40

Fix some compiler warnings

librc: Fix C90 warning (mixed declaration and code)
rc: Fix warning about discarding const qualifier

Fixes #45.

 src/librc/librc-daemon.c | 6 --
 src/rc/rc.c  | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 76fdd7b..3811a04 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -510,6 +510,8 @@ rc_service_daemons_crashed(const char *service)
RC_STRINGLIST *list = NULL;
RC_STRING *s;
size_t i;
+   char *ch_root;
+   char *spidfile;
 
path += snprintf(dirpath, sizeof(dirpath), RC_SVCDIR /daemons/%s,
basename_c(service));
@@ -554,8 +556,8 @@ rc_service_daemons_crashed(const char *service)
}
fclose(fp);
 
-   char *ch_root = rc_service_value_get(basename_c(service), 
chroot);
-   char *spidfile = pidfile;
+   ch_root = rc_service_value_get(basename_c(service), chroot);
+   spidfile = pidfile;
if (ch_root  pidfile) {
spidfile = xmalloc(strlen(ch_root) + strlen(pidfile) + 
1);
strcpy(spidfile, ch_root);

diff --git a/src/rc/rc.c b/src/rc/rc.c
index e3301c6..dd35482 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -519,7 +519,7 @@ runlevel_config(const char *service, const char *level)
 }
 
 static void
-do_stop_services(const RC_STRINGLIST *types_n, const RC_STRINGLIST 
*start_services,
+do_stop_services(RC_STRINGLIST *types_n, RC_STRINGLIST *start_services,
 const RC_STRINGLIST *stop_services, const 
RC_DEPTREE *deptree,
 const char *newlevel, bool parallel, bool 
going_down)
 {



[gentoo-commits] proj/openrc:master commit in: src/librc/

2015-01-12 Thread William Hubbs
commit: 74478830a8d035c078e986b57efd40a5c48bc896
Author: Doug Freed dwfreed AT mtu DOT edu
AuthorDate: Mon Jan 12 15:10:29 2015 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Mon Jan 12 16:30:36 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=74478830

fix double free of pidfile

This fixes a double free of the pidfile variable. For discussion of this
issue, see the bug.

X-Gentoo-Bug: 531600
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=531600

---
 src/librc/librc-daemon.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 02aff5a..76fdd7b 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -560,22 +560,20 @@ rc_service_daemons_crashed(const char *service)
spidfile = xmalloc(strlen(ch_root) + strlen(pidfile) + 
1);
strcpy(spidfile, ch_root);
strcat(spidfile, pidfile);
+   free(pidfile);
+   pidfile = spidfile;
}
 
pid = 0;
-   if (spidfile) {
+   if (pidfile) {
retval = true;
-   if ((fp = fopen(spidfile, r))) {
+   if ((fp = fopen(pidfile, r))) {
if (fscanf(fp, %d, pid) == 1)
retval = false;
fclose(fp);
}
-   free(spidfile);
-   spidfile = NULL;
-   if (ch_root) {
-   free(pidfile);
-   pidfile = NULL;
-   }
+   free(pidfile);
+   pidfile = NULL;
 
/* We have the pid, so no need to match
   on exec or name */



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-11-01 Thread William Hubbs
commit: be952bebb3647069fb93b9791ee3439698f697ca
Author: Alexander Vershilov alexander.vershilov AT gmail DOT com
AuthorDate: Wed Oct 29 20:16:35 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Sat Nov  1 21:44:30 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=be952beb

Fix incorrect handling of chroot option.
Fixes #28.

X-Gentoo-Bug: #527370
X-Gentoo-Bug-Url: https://bugs.gentoo.org/show_bug.cgi?id=527370

---
 src/librc/librc-daemon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 190a014..02aff5a 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -556,8 +556,8 @@ rc_service_daemons_crashed(const char *service)
 
char *ch_root = rc_service_value_get(basename_c(service), 
chroot);
char *spidfile = pidfile;
-   if (ch_root) {
-   spidfile = malloc(strlen(ch_root) + strlen(pidfile));
+   if (ch_root  pidfile) {
+   spidfile = xmalloc(strlen(ch_root) + strlen(pidfile) + 
1);
strcpy(spidfile, ch_root);
strcat(spidfile, pidfile);
}



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-10-24 Thread William Hubbs
commit: 7700e6fe796cabfa22eefddc024d66257a28d4dc
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Fri Oct 24 15:44:14 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Fri Oct 24 15:44:14 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=7700e6fe

Fix compile errors created by bundling queue.h

---
 src/librc/rc.h.in | 45 +
 1 file changed, 45 insertions(+)

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 62119e9..58d8eb5 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -77,6 +77,51 @@ extern C {
 #  define RC_LOCAL_CONFDIR  RC_LOCAL_PREFIX /etc/conf.d
 #endif
 
+#ifndef _SYS_QUEUE_H_
+
+/*
+ * The following are copied directly from our imported queue.h.
+ */
+
+/*
+ * List definitions.
+ */
+#defineLIST_HEAD(name, type)   
\
+struct name {  \
+   struct type *lh_first;  /* first element */ \
+}
+
+#defineLIST_HEAD_INITIALIZER(head) 
\
+   { NULL }
+
+#defineLIST_ENTRY(type)
\
+struct {   \
+   struct type *le_next;   /* next element */  \
+   struct type **le_prev;  /* address of previous next element */  \
+}
+
+/*
+ * Tail queue definitions.
+ */
+#define_TAILQ_HEAD(name, type, qual)   
\
+struct name {  \
+   qual type *tqh_first;   /* first element */ \
+   qual type *qual *tqh_last;  /* addr of last next element */ \
+}
+#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
+
+#defineTAILQ_HEAD_INITIALIZER(head)
\
+   { TAILQ_END(head), (head).tqh_first }
+
+#define_TAILQ_ENTRY(type, qual)
\
+struct {   \
+   qual type *tqe_next;/* next element */  \
+   qual type *qual *tqe_prev;  /* address of previous next element */\
+}
+#define TAILQ_ENTRY(type)  _TAILQ_ENTRY(struct type,)
+
+#endif /* _SYS_QUEUE_H_ */
+
 /* A doubly linked list using queue(3) for ease of use */
 typedef struct rc_string {
char *value;



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-10-23 Thread William Hubbs
commit: 89c8a62a1078e770e12c47f06c8dbc9c2924e771
Author: Gabriele Giacone 1o5g4r8o AT gmail DOT com
AuthorDate: Wed Oct 22 02:17:52 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Wed Oct 22 18:27:37 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=89c8a62a

Fix rc_svcdir for GNU/kFreeBSD

---
 src/librc/rc.h.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 5ef8d7f..8f0e889 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -42,7 +42,7 @@ extern C {
 #define RC_LIBEXECDIR   @LIBEXECDIR@
 #if defined(PREFIX)
 #define RC_SVCDIR   RC_LIBEXECDIR /init.d
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__FreeBSD_kernel__)
 #define RC_SVCDIR   /run/openrc
 #else
 #define RC_SVCDIR   RC_LIBEXECDIR /init.d



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/rc/

2014-10-23 Thread William Hubbs
commit: 875f03e27c3475675f7b9572b071dd8c26257be7
Author: Svante Signell svante.signell AT gmail DOT com
AuthorDate: Wed Oct 22 19:59:01 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Thu Oct 23 18:00:24 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=875f03e2

fix defines for GNU/Hurd

---
 src/librc/librc.h  | 4 +++-
 src/rc/mountinfo.c | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/librc/librc.h b/src/librc/librc.h
index 54c9a1a..0824eba 100644
--- a/src/librc/librc.h
+++ b/src/librc/librc.h
@@ -57,11 +57,13 @@
 #include time.h
 #include unistd.h
 
-#ifdef BSD
+#if defined(BSD)  !defined(__GNU__)
 #include sys/param.h
 #include sys/user.h
 #include sys/sysctl.h
 #include kvm.h
+#else
+#include sys/param.h
 #endif
 
 #include rc.h

diff --git a/src/rc/mountinfo.c b/src/rc/mountinfo.c
index 7840987..c4515ae 100644
--- a/src/rc/mountinfo.c
+++ b/src/rc/mountinfo.c
@@ -35,11 +35,11 @@
 #  include sys/ucred.h
 #  include sys/mount.h
 #  define F_FLAGS f_flags
-#elif defined(BSD)
+#elif defined(BSD)  !defined(__GNU__)
 #  include sys/statvfs.h
 #  define statfs statvfs
 #  define F_FLAGS f_flag
-#elif defined (__linux__) || defined (__FreeBSD_kernel__)
+#elif defined (__linux__) || defined (__FreeBSD_kernel__) || defined(__GNU__)
 #  include mntent.h
 #endif
 
@@ -168,7 +168,7 @@ process_mount(RC_STRINGLIST *list, struct args *args,
return -1;
 }
 
-#ifdef BSD
+#if defined(BSD)  !defined(__GNU__)
 
 /* Translate the mounted options to english
  * This is taken directly from FreeBSD mount.c */



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-10-23 Thread William Hubbs
commit: 4ac289b5397a688393c596a9a01651c94d3b5711
Author: Gabriele Giacone 1o5g4r8o AT gmail DOT com
AuthorDate: Wed Oct 22 20:02:51 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Thu Oct 23 18:05:08 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=4ac289b5

Fix rc_svcdir for GNU/Hurd

---
 src/librc/rc.h.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 8f0e889..34f09f2 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -42,7 +42,7 @@ extern C {
 #define RC_LIBEXECDIR   @LIBEXECDIR@
 #if defined(PREFIX)
 #define RC_SVCDIR   RC_LIBEXECDIR /init.d
-#elif defined(__linux__) || defined(__FreeBSD_kernel__)
+#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
 #define RC_SVCDIR   /run/openrc
 #else
 #define RC_SVCDIR   RC_LIBEXECDIR /init.d



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/rc/

2014-10-23 Thread William Hubbs
commit: ca6b86be44fc7ed618a7ab3bd021e208d38878b1
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Thu Oct 23 23:47:04 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Thu Oct 23 23:47:24 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=ca6b86be

Fix all tests for GNU/kFreeBSD

It is necessary to check for both the kernel and c library because
__FreeBSD_kernel is also defined on native FreeBSD [1].

[1] http://sourceforge.net/p/predef/wiki/OperatingSystems/

---
 src/librc/librc-daemon.c | 2 +-
 src/librc/rc.h.in| 3 ++-
 src/rc/mountinfo.c   | 6 --
 src/rc/rc-logger.c   | 2 +-
 src/rc/runscript.c   | 3 ++-
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 9970315..d19c3a3 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -30,7 +30,7 @@
 
 #include librc.h
 
-#if defined(__linux__) || defined (__FreeBSD_kernel__)
+#if defined(__linux__) || (defined (__FreeBSD_kernel__)  defined(__GLIBC__))
 static bool
 pid_is_exec(pid_t pid, const char *exec)
 {

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 34f09f2..fca0dda 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -42,7 +42,8 @@ extern C {
 #define RC_LIBEXECDIR   @LIBEXECDIR@
 #if defined(PREFIX)
 #define RC_SVCDIR   RC_LIBEXECDIR /init.d
-#elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
+#elif defined(__linux__) || (defined(__FreeBSD_kernel__)  \
+   defined(__GLIBC__)) || defined(__GNU__)
 #define RC_SVCDIR   /run/openrc
 #else
 #define RC_SVCDIR   RC_LIBEXECDIR /init.d

diff --git a/src/rc/mountinfo.c b/src/rc/mountinfo.c
index c4515ae..fbad6af 100644
--- a/src/rc/mountinfo.c
+++ b/src/rc/mountinfo.c
@@ -39,7 +39,8 @@
 #  include sys/statvfs.h
 #  define statfs statvfs
 #  define F_FLAGS f_flag
-#elif defined (__linux__) || defined (__FreeBSD_kernel__) || defined(__GNU__)
+#elif defined (__linux__) || (defined(__FreeBSD_kernel__)  \
+   defined(__GLIBC__)) || defined(__GNU__)
 #  include mntent.h
 #endif
 
@@ -265,7 +266,8 @@ find_mounts(struct args *args)
return list;
 }
 
-#elif defined (__linux__) || defined (__FreeBSD_kernel__)
+#elif defined (__linux__) || (defined (__FreeBSD_kernel__)  \
+   defined(__GLIBC__))
 static struct mntent *
 getmntfile(const char *file)
 {

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index 50cf618..89eb84b 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -44,7 +44,7 @@
 #include time.h
 #include unistd.h
 
-#if defined(__linux__) || defined(__FreeBSD_kernel__)
+#if defined(__linux__) || (defined(__FreeBSD_kernel__)  defined(__GLIBC__))
 #  include pty.h
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
 #  include util.h

diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index 96aa683..47ed23e 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -51,7 +51,8 @@
 #include time.h
 #include unistd.h
 
-#if defined(__linux__) || defined(__FreeBSD_kernel__)
+#if defined(__linux__) || (defined(__FreeBSD_kernel__)  \
+   defined(__GLIBC__))
 #  include pty.h
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
 #  include util.h



[gentoo-commits] proj/openrc:master commit in: src/librc/, src/libeinfo/

2014-10-21 Thread Anthony G. Basile
commit: 4a08517cac3c68c232694db7288654b58b68b8ba
Author: Anthony G. Basile blueness AT gentoo DOT org
AuthorDate: Tue Oct 21 13:31:07 2014 +
Commit: Anthony G. Basile blueness AT gentoo DOT org
CommitDate: Tue Oct 21 13:39:34 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=4a08517c

einfo.h, rc.h.in: ensure __BEGIN_DECLS is defined

Some Standard C Libraries, like musl, don't define __BEGIN_DECLS
or __END_DECLS.  We add some ifdef magic to ensure these are
available.

---
 src/libeinfo/einfo.h | 10 ++
 src/librc/rc.h.in| 10 ++
 2 files changed, 20 insertions(+)

diff --git a/src/libeinfo/einfo.h b/src/libeinfo/einfo.h
index 31a891f..8fe5649 100644
--- a/src/libeinfo/einfo.h
+++ b/src/libeinfo/einfo.h
@@ -48,6 +48,16 @@
 # endif
 #endif
 
+#undef __BEGIN_DECLS
+#undef __END_DECLS
+#ifdef __cplusplus
+# define __BEGIN_DECLS extern C {
+# define __END_DECLS }
+#else
+# define __BEGIN_DECLS /* empty */
+# define __END_DECLS /* empty */
+#endif
+
 __BEGIN_DECLS
 
 /*! @brief Color types to use */

diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index c2a919f..5cd584f 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -31,6 +31,16 @@
 #include stdbool.h
 #include stdio.h
 
+#undef __BEGIN_DECLS
+#undef __END_DECLS
+#ifdef __cplusplus
+# define __BEGIN_DECLS extern C {
+# define __END_DECLS }
+#else
+# define __BEGIN_DECLS /* empty */
+# define __END_DECLS /* empty */
+#endif
+
 __BEGIN_DECLS
 
 #define RC_PREFIX @PREFIX@



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-10-20 Thread William Hubbs
commit: f9acd65497c6e561fbf5420386a99d681fede859
Author: Alexander Vershilov alexander.vershilov AT gmail DOT com
AuthorDate: Mon Oct 20 00:41:36 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Mon Oct 20 20:44:19 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=f9acd654

librc:look for the pid file in a chroot if defined

X-Gentoo-Bug: 524388
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524388

---
 src/librc/librc-daemon.c | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 8793075..04f25b1 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -553,16 +553,28 @@ rc_service_daemons_crashed(const char *service)
}
fclose(fp);
 
+   char *ch_root = rc_service_value_get(basename_c(service), 
chroot);
+   char *spidfile = pidfile;
+   if (ch_root) {
+   spidfile = malloc(strlen(ch_root) + strlen(pidfile));
+   strcpy(spidfile, ch_root);
+   strcat(spidfile, pidfile);
+   }
+
pid = 0;
-   if (pidfile) {
+   if (spidfile) {
retval = true;
-   if ((fp = fopen(pidfile, r))) {
+   if ((fp = fopen(spidfile, r))) {
if (fscanf(fp, %d, pid) == 1)
retval = false;
fclose(fp);
}
-   free(pidfile);
-   pidfile = NULL;
+   free(spidfile);
+   spidfile = NULL;
+   if (ch_root) {
+   free(pidfile);
+   pidfile = NULL;
+   }
 
/* We have the pid, so no need to match
   on exec or name */



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-07-19 Thread William Hubbs
commit: 1f7582c78b2697c3f2617a4a89afabaf3550b0fb
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Sat Jul 19 18:03:00 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Sat Jul 19 18:03:00 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=1f7582c7

src/librc/librc-daemon.c: style fix

---
 src/librc/librc-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index a53e6e1..8793075 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -131,7 +131,7 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
if (exists(/proc/self/status)) {
fp = fopen(/proc/self/status, r);
if (fp) {
-   while(! feof(fp)) {
+   while (! feof(fp)) {
rc_getline(line, len, fp);
if (strncmp(line, envID:\t0, 8) == 0) {
openvz_host = true;



[gentoo-commits] proj/openrc:master commit in: src/librc/

2014-06-20 Thread William Hubbs
commit: 9eb9b28d3e3b6725559fb38101ae869c1e4530ce
Author: William Hubbs w.d.hubbs AT gmail DOT com
AuthorDate: Fri Jun 20 21:01:47 2014 +
Commit: William Hubbs williamh AT gentoo DOT org
CommitDate: Fri Jun 20 21:01:47 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=9eb9b28d

librc: filter out container processes on OpenVZ host

Thanks to info and testing done by Daniel Robbins drobbins AT funtoo.org,
there is now a fix for this. Below is his description of the steps
OpenRC needed to use.

1) See if /proc/pid/status exists
2) If it does, see if it has a envID: field
3) If it does, see if envID: is set to 0
4) If so, then it's one of the host's processes and should be a
candidate for the list. Otherwise, it is one of the container's
processes and should be ignored.

This should fix the bug and allow start-stop-daemon to work properly on
OpenVZ hosts.

X-Gentoo-Bug: 376817
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=376817

---
 src/librc/librc-daemon.c | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index e98b02c..a53e6e1 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -90,6 +90,11 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
 {
DIR *procdir;
struct dirent *entry;
+   FILE *fp;
+   bool container_pid = false;
+   bool openvz_host = false;
+   char *line = NULL;
+   size_t len = 0;
pid_t p;
char buffer[PATH_MAX];
struct stat sb;
@@ -117,6 +122,26 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
runscript_pid = 0;
}
 
+   /*
+   If /proc/self/status contains EnvID: 0, then we are an OpenVZ host,
+   and we will need to filter out processes that are inside containers
+   from our list of pids.
+   */
+
+   if (exists(/proc/self/status)) {
+   fp = fopen(/proc/self/status, r);
+   if (fp) {
+   while(! feof(fp)) {
+   rc_getline(line, len, fp);
+   if (strncmp(line, envID:\t0, 8) == 0) {
+   openvz_host = true;
+   break;
+   }
+   }
+   fclose(fp);
+   }
+   }
+
while ((entry = readdir(procdir)) != NULL) {
if (sscanf(entry-d_name, %d, p) != 1)
continue;
@@ -134,6 +159,25 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
if (argv 
!pid_is_argv(p, (const char *const *)argv))
continue;
+   /* If this is an OpenVZ host, filter out container processes */
+   if (openvz_host) {
+   snprintf(buffer, sizeof(buffer), /proc/%d/status, p);
+   if (exists(buffer)) {
+   fp = fopen(buffer, r);
+   if (! fp)
+   continue;
+   while (! feof(fp)) {
+   rc_getline(line, len, fp);
+   if (strncmp(line, envID:, 6) == 0) {
+   container_pid = ! 
(strncmp(line, envID:\t0, 8) == 0);
+   break;
+   }
+   }
+   fclose(fp);
+   }
+   }
+   if (container_pid)
+   continue;
if (!pids) {
pids = xmalloc(sizeof(*pids));
LIST_INIT(pids);
@@ -142,6 +186,8 @@ rc_find_pids(const char *exec, const char *const *argv, 
uid_t uid, pid_t pid)
pi-pid = p;
LIST_INSERT_HEAD(pids, pi, entries);
}
+   if (line != NULL)
+   free(line);
closedir(procdir);
return pids;
 }