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

2018-11-05 Thread William Hubbs
commit: 025c9693ccab9c6220520ace47aa81553e7ea600
Author: William Hubbs  gmail  com>
AuthorDate: Mon Nov  5 17:39:39 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Nov  5 17:39:39 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=025c9693

rc-service: fix help output

 src/rc/rc-service.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index 8b01fa0d..e9795650 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -49,10 +49,12 @@ const char * const longopts_help[] = {
"set xtrace when running the command",
"ignore dependencies",
"tests if the service exists or not",
-   "if the service is crashed then run the command",
-   "if the service exists then run the command",
-   "if the service is inactive then run the command",
-   "if the service is not started then run the command",
+   "if the service is crashed run the command",
+   "if the service exists run the command",
+   "if the service is inactive run the command",
+   "if the service is not started run the command",
+   "if the service is started run the command",
+   "if the service is stopped run the command",
"list all available services",
"resolve the service name to an init script",
"dry run (show what would happen)",



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

2018-11-05 Thread William Hubbs
commit: 008c9d0036e348242e323c0b5a66f3724b4a839d
Author: William Hubbs  gmail  com>
AuthorDate: Tue Nov  6 03:35:00 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Nov  6 03:35:00 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=008c9d00

supervise-daemon: reap zombies

We need to make sure to reap zombies so that we can shut down
successfully.

Fixes #252.
Possibly related to #250.

 src/rc/supervise-daemon.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 883c738d..52525c19 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -197,6 +197,16 @@ static void healthcheck(int sig)
do_healthcheck = 1;
 }
 
+static void reap_zombies(int sig)
+{
+   int serrno;
+   (void) sig;
+
+   serrno = errno;
+   while (waitpid((pid_t)(-1), NULL, WNOHANG) > 0) {}
+   errno = serrno;
+}
+
 static char * expand_home(const char *home, const char *path)
 {
char *opath, *ppath, *p, *nh;
@@ -457,6 +467,7 @@ static void supervisor(char *exec, char **argv)
signal_setup_restart(SIGPIPE, handle_signal);
signal_setup_restart(SIGALRM, handle_signal);
signal_setup(SIGTERM, handle_signal);
+   signal_setup(SIGCHLD, reap_zombies);
signal_setup_restart(SIGUSR1, handle_signal);
signal_setup_restart(SIGUSR2, handle_signal);
signal_setup_restart(SIGBUS, handle_signal);



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

2018-11-02 Thread William Hubbs
commit: e2416d089396e2b9a72cc56ef9f57886ffb0f1c8
Author: William Hubbs  gmail  com>
AuthorDate: Wed Oct 24 20:24:29 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Oct 24 20:24:40 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e2416d08

openrc-shutdown: do not require a time for -w switch

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

 src/rc/openrc-shutdown.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/rc/openrc-shutdown.c b/src/rc/openrc-shutdown.c
index ab2e7469..71a91255 100644
--- a/src/rc/openrc-shutdown.c
+++ b/src/rc/openrc-shutdown.c
@@ -250,6 +250,9 @@ int main(int argc, char **argv)
} else if (do_reexec) {
send_cmd("reexec");
exit(EXIT_SUCCESS);
+   } else if (do_wtmp_only) {
+   log_wtmp("shutdown", "~~", 0, RUN_LVL, "~~");
+   exit(EXIT_SUCCESS);
}
 
if (optind >= argc) {
@@ -329,7 +332,5 @@ int main(int argc, char **argv)
send_cmd("reboot");
else if (do_single)
send_cmd("single");
-   else if (do_wtmp_only)
-   log_wtmp("shutdown", "~~", 0, RUN_LVL, "~~");
return 0;
 }



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

2018-11-02 Thread William Hubbs
commit: ee3c4afdb75b98cd472b7ffbb46adc9d8a1e1b15
Author: William Hubbs  gmail  com>
AuthorDate: Fri Nov  2 23:22:11 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Nov  2 23:22:11 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ee3c4afd

openrc-init: add SELinux support

This is for #173.

 src/rc/openrc-init.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index e557c63d..c57a3b06 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -31,6 +31,10 @@
 #include 
 #include 
 
+#ifdef HAVE_SELINUX
+#  include 
+#endif
+
 #include "helpers.h"
 #include "rc.h"
 #include "rc-wtmp.h"
@@ -161,10 +165,36 @@ int main(int argc, char **argv)
bool reexec = false;
sigset_t signals;
struct sigaction sa;
+#ifdef HAVE_SELINUX
+   int enforce = 0;
+#endif
 
if (getpid() != 1)
return 1;
 
+#ifdef HAVE_SELINUX
+   if (getenv("SELINUX_INIT") == NULL) {
+   if (is_selinux_enabled() != 1) {
+   if (selinux_init_load_policy() == 0) {
+   putenv("SELINUX_INIT=YES");
+   execv(argv[0], argv);
+   } else {
+   if (enforce > 0) {
+   /*
+* SELinux in enforcing mode but 
load_policy failed
+* At this point, we probably can't 
open /dev/console,
+* so log() won't work
+*/
+   fprintf(stderr,"Unable to load SELinux 
Policy.\n");
+   fprintf(stderr,"Machine is  in 
enforcing mode.\n");
+   fprintf(stderr,"Halting now.\n");
+   exit(1);
+   }
+   }
+   }
+   }
+#endif  
+
printf("OpenRC init version %s starting\n", VERSION);
 
if (argc > 1)



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

2018-10-23 Thread William Hubbs
commit: c1e582586d398b4452f568240985247294f645ef
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct  9 22:49:02 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct 23 18:38:14 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c1e58258

supervise-daemon: add health checks

Health checks are a way to monitor a service and make sure it stays
healthy.

If a service is not healthy, it will be automatically restarted after
running the unhealthy() function to clean up.

 NEWS.md   |   4 ++
 man/supervise-daemon.8|   9 +++
 sh/supervise-daemon.sh|  14 +
 src/rc/Makefile   |   2 +-
 src/rc/supervise-daemon.c | 136 +++---
 supervise-daemon-guide.md |  36 
 6 files changed, 169 insertions(+), 32 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index d4d96577..f1400197 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -22,6 +22,10 @@ This version adds timed shutdown and cancelation of shutdown 
to
 openrc-shutdown. Shutdowns can now be delayed for a certain amount of
 time or scheduled for an exact time.
 
+supervise-daemon supports health checks, which are a periodic way to make sure 
a
+service is healthy. For more information on setting this up, please see
+supervise-daemon-guide.md.
+
 ## OpenRC 0.37
 
 start-stop-daemon now supports logging stdout and stderr of daemons to

diff --git a/man/supervise-daemon.8 b/man/supervise-daemon.8
index af06ee31..8bcd8b5c 100644
--- a/man/supervise-daemon.8
+++ b/man/supervise-daemon.8
@@ -16,6 +16,10 @@
 .Nd starts a daemon and restarts it if it crashes
 .Sh SYNOPSIS
 .Nm
+.Fl a , -healthcheck-timer
+.Ar seconds
+.Fl A , -healthcheck-delay
+.Ar seconds
 .Fl D , -respawn-delay
 .Ar seconds
 .Fl d , -chdir
@@ -90,6 +94,11 @@ Print the action(s) that are taken just before doing them.
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.Fl a , -healthcheck-timer Ar seconds
+Run the healthcheck() command, possibly followed by the unhealthy()
+command every time this number of seconds passes.
+.Fl A , -healthcheck-delay Ar seconds
+Wait this long before the first health check.
 .It Fl D , -respawn-delay Ar seconds
 wait this number of seconds before restarting a daemon after it crashes.
 The default is 0.

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 80e0260c..73a70140 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -10,6 +10,8 @@
 # This file may not be copied, modified, propagated, or distributed
 #except according to the terms contained in the LICENSE file.
 
+extra_commands="healthcheck unhealthy ${extra_commands}"
+
 supervise_start()
 {
if [ -z "$command" ]; then
@@ -32,6 +34,8 @@ supervise_start()
${respawn_delay:+--respawn-delay} $respawn_delay \
${respawn_max:+--respawn-max} $respawn_max \
${respawn_period:+--respawn-period} $respawn_period \
+   ${healthcheck_delay:+--healthcheck-delay} $healthcheck_delay \
+   ${healthcheck_timer:+--healthcheck-timer} $healthcheck_timer \
${command_user+--user} $command_user \
${umask+--umask} $umask \
${supervise_daemon_args:-${start_stop_daemon_args}} \
@@ -98,3 +102,13 @@ supervise_status()
return 3
fi
 }
+
+healthcheck()
+{
+   return 0
+}
+
+unhealthy()
+{
+   return 0
+}

diff --git a/src/rc/Makefile b/src/rc/Makefile
index 9ba240fa..ea4a8c81 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -161,7 +161,7 @@ rc-update: rc-update.o _usage.o rc-misc.o
 start-stop-daemon: start-stop-daemon.o _usage.o rc-misc.o rc-pipes.o 
rc-schedules.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
-supervise-daemon: supervise-daemon.o _usage.o rc-misc.o rc-schedules.o
+supervise-daemon: supervise-daemon.o _usage.o rc-misc.o rc-plugin.o 
rc-schedules.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 service_get_value service_set_value get_options save_options: do_value.o 
rc-misc.o

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 27089152..883c738d 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -61,15 +61,18 @@ static struct pam_conv conv = { NULL, NULL};
 #include "queue.h"
 #include "rc.h"
 #include "rc-misc.h"
+#include "rc-plugin.h"
 #include "rc-schedules.h"
 #include "_usage.h"
 #include "helpers.h"
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "D:d:e:g:I:Kk:m:N:p:R:r:Su:1:2:3" \
+const char *getoptstring = "A:a:D:d:e:g:H:I:Kk:m:N:p:R:r:Su:1:2:3" \
getoptstring_COMMON;
 const struct option longopts[] = {
+   { "healthcheck-timer",1, NULL, 'a'},
+   { "healthcheck-delay",1, NULL, 'A'},
{ "respawn-delay",1, NULL, 'D'},
{ "chdir",1, NULL, 'd'},
{ "env",  

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

2018-10-18 Thread William Hubbs
commit: 3f918161aafa61c1c2005709fda0b9bec4c412d8
Author: William Hubbs  gmail  com>
AuthorDate: Fri Oct  5 19:10:59 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 18 22:56:36 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3f918161

openrc-shutdown: Add scheduled shutdown and the ability to cancel a shutdown

You can now schedule a shutdown for a certain time or a cpecific number
of minutes into the future.

When a shutdown is running, you can now cancel it with ^c from the
keyboard or by running "openrc-shutdown -c" from another shell.

 man/openrc-shutdown.8|   3 +
 src/rc/Makefile  |   4 +-
 src/rc/broadcast.c   | 209 +++
 src/rc/broadcast.h   |  16 
 src/rc/openrc-shutdown.c | 179 ++--
 5 files changed, 402 insertions(+), 9 deletions(-)

diff --git a/man/openrc-shutdown.8 b/man/openrc-shutdown.8
index 5db21334..b09e8c20 100644
--- a/man/openrc-shutdown.8
+++ b/man/openrc-shutdown.8
@@ -16,6 +16,7 @@
 .Nd bring the system down
 .Sh SYNOPSIS
 .Nm
+.Op Fl c , -cancel
 .Op Fl d , -no-write
 .Op Fl D , -dry-run
 .Op Fl H , -halt
@@ -32,6 +33,8 @@ is the utility that communicates with
 to bring down the system or instruct openrc-init to re-execute itself.
 It supports the following options:
 .Bl -tag -width "poweroff"
+.It Fl c , -cancel
+Cancel a pending shutdown.
 .It Fl d , -no-write
 Do not write the wtmp boot record.
 .It Fl D , -dry-run

diff --git a/src/rc/Makefile b/src/rc/Makefile
index b09c5058..9ba240fa 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -14,7 +14,7 @@ SRCS+=rc-selinux.c
 endif
 
 ifeq (${OS},Linux)
-SRCS+= kill_all.c openrc-init.c openrc-shutdown.c rc-wtmp.c
+SRCS+= kill_all.c openrc-init.c openrc-shutdown.c broadcast.c rc-wtmp.c
 endif
 
 CLEANFILES=version.h rc-selinux.o
@@ -134,7 +134,7 @@ mountinfo: mountinfo.o _usage.o rc-misc.o
 openrc rc: rc.o rc-logger.o rc-misc.o rc-plugin.o _usage.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
-openrc-shutdown: openrc-shutdown.o _usage.o rc-wtmp.o
+openrc-shutdown: openrc-shutdown.o rc-misc.o _usage.o broadcast.o rc-wtmp.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 openrc-run runscript: openrc-run.o _usage.o rc-misc.o rc-plugin.o

diff --git a/src/rc/broadcast.c b/src/rc/broadcast.c
new file mode 100644
index ..dbc861d1
--- /dev/null
+++ b/src/rc/broadcast.c
@@ -0,0 +1,209 @@
+/*
+ * broadcast.c
+ * broadcast a message to every logged in user
+ */
+
+/*
+ * Copyright 2018 Sony Interactive Entertainment Inc. 
+ *
+ * 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.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "broadcast.h"
+#include "helpers.h"
+
+#ifndef _PATH_DEV
+# define _PATH_DEV "/dev/"
+#endif
+
+#ifndef UT_LINESIZE
+#define UT_LINESIZE __UT_LINESIZE
+#endif
+
+static sigjmp_buf jbuf;
+
+/*
+ * Alarm handler
+ */
+/*ARGSUSED*/
+# ifdef __GNUC__
+static void handler(int arg __attribute__((unused)))
+# else
+static void handler(int arg)
+# endif
+{
+   siglongjmp(jbuf, 1);
+}
+
+static void getuidtty(char **userp, char **ttyp)
+{
+   struct passwd   *pwd;
+   uid_t   uid;
+   char*tty;
+   static char uidbuf[32];
+   static char ttynm[UT_LINESIZE + 4];
+
+   uid = getuid();
+   if ((pwd = getpwuid(uid)) != NULL) {
+   uidbuf[0] = 0;
+   strncat(uidbuf, pwd->pw_name, sizeof(uidbuf) - 1);
+   } else {
+   if (uid)
+   sprintf(uidbuf, "uid %d", (int) uid);
+   else
+   sprintf(uidbuf, "root");
+   }
+
+   if ((tty = ttyname(0)) != NULL) {
+   const size_t plen = strlen(_PATH_DEV);
+   if (strncmp(tty, _PATH_DEV, plen) == 0) {
+   tty += plen;
+   if (tty[0] == '/')
+   tty++;
+   }
+   snprintf(ttynm, sizeof(ttynm), "(%.*s) ",
+UT_LINESIZE, tty);
+   } else
+   ttynm[0] = 0;
+
+   *userp = uidbuf;
+   *ttyp  = ttynm;
+}
+
+/*
+ * Check whether the given filename looks like a tty device.
+ */
+static int file_isatty(const char *fname)
+{
+   struct stat st;
+   int major;
+
+ 

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

2018-10-15 Thread William Hubbs
commit: 07908be0903229a69b9e0f733ed13eeff0b55a44
Author: Austin English  gmail  com>
AuthorDate: Fri Oct 12 22:16:33 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Oct 13 16:53:54 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=07908be0

misc: style fixups

 src/rc/kill_all.c| 2 +-
 src/rc/openrc-init.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c
index 0833e5f8..bc079dea 100644
--- a/src/rc/kill_all.c
+++ b/src/rc/kill_all.c
@@ -58,7 +58,7 @@ static int mount_proc(void)
if (exists("/proc/version"))
return 0;
pid = fork();
-   switch(pid) {
+   switch (pid) {
case -1:
syslog(LOG_ERR, "Unable to fork");
return -1;

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index e02fa5ee..e557c63d 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -45,7 +45,7 @@ static pid_t do_openrc(const char *runlevel)
sigset_t signals;
 
pid = fork();
-   switch(pid) {
+   switch (pid) {
case -1:
perror("fork");
break;
@@ -139,7 +139,7 @@ static void reap_zombies(void)
 
 static void signal_handler(int sig)
 {
-   switch(sig) {
+   switch (sig) {
case SIGINT:
handle_shutdown("reboot", RB_AUTOBOOT);
break;



[gentoo-commits] proj/openrc:master commit in: src/rc/, init.d/, sh/

2018-10-15 Thread William Hubbs
commit: 02af093043a7444381b0d8a0a3e8e97247505f95
Author: Austin English  gmail  com>
AuthorDate: Fri Oct 12 22:16:23 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Oct 13 16:53:54 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=02af0930

misc: whitespace fixes

 init.d/modules.in | 2 +-
 sh/rc-cgroup.sh.in| 2 +-
 sh/s6.sh  | 2 +-
 sh/start-stop-daemon.sh   | 4 ++--
 src/rc/kill_all.c | 2 +-
 src/rc/rc-wtmp.c  | 2 +-
 src/rc/supervise-daemon.c | 2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/init.d/modules.in b/init.d/modules.in
index 08abae3d..998972ba 100644
--- a/init.d/modules.in
+++ b/init.d/modules.in
@@ -126,7 +126,7 @@ Linux_modules()
 start()
 {
case "$RC_UNAME" in
-   FreeBSD|Linux) 
+   FreeBSD|Linux)
modules_load_d
${RC_UNAME}_modules
;;

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index d4b68ada..79ada43f 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -62,7 +62,7 @@ cgroup_set_values()
while [ -n "$1" ] && [ "$controller" != "cpuacct" ]; do
case "$1" in
$controller.*)
-   if [ -n "${name}" ] && [ -w "${cgroup}/${name}" 
] && 
+   if [ -n "${name}" ] && [ -w "${cgroup}/${name}" 
] &&
[ -n "${val}" ]; then
veinfo "$RC_SVCNAME: Setting 
$cgroup/$name to $val"
printf "%s" "$val" > "$cgroup/$name"

diff --git a/sh/s6.sh b/sh/s6.sh
index 33c478ad..acbe965b 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -57,7 +57,7 @@ s6_stop()
ebegin "Stopping ${name:-$RC_SVCNAME}"
s6-svc -d -wD -T ${s6_service_timeout_stop:-6} "${s6_service_link}"
set -- $(s6-svstat "${s6_service_link}")
-   [ "$1" = "up" ] && 
+   [ "$1" = "up" ] &&
yesno "${s6_force_kill:-yes}" &&
_s6_force_kill "$@"
set -- $(s6-svstat "${s6_service_link}")

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index e68b47ef..2e549ae1 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -38,9 +38,9 @@ ssd_start()
service_inactive && _inactive=true
mark_service_inactive
fi
-   [ -n "$output_logger" ] && 
+   [ -n "$output_logger" ] &&
output_logger_arg="--stdout-logger \"$output_logger\""
-   [ -n "$error_logger" ] && 
+   [ -n "$error_logger" ] &&
error_logger_arg="--stderr-logger \"$error_logger\""
#the eval call is necessary for cases like:
# command_args="this \"is a\" test"

diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c
index 3aeaa262..0833e5f8 100644
--- a/src/rc/kill_all.c
+++ b/src/rc/kill_all.c
@@ -248,7 +248,7 @@ int main(int argc, char **argv)
usage(EXIT_FAILURE);
}
}
-   
+
openlog(applet, LOG_CONS|LOG_PID, LOG_DAEMON);
if (mount_proc() != 0) {
rc_stringlist_free(omits);

diff --git a/src/rc/rc-wtmp.c b/src/rc/rc-wtmp.c
index 8d494303..40cc280c 100644
--- a/src/rc/rc-wtmp.c
+++ b/src/rc/rc-wtmp.c
@@ -42,7 +42,7 @@ void log_wtmp(const char *user, const char *id, pid_t pid, 
int type,
strncpy(utmp.ut_name, user, sizeof(utmp.ut_name));
strncpy(utmp.ut_id  , id  , sizeof(utmp.ut_id  ));
strncpy(utmp.ut_line, line, sizeof(utmp.ut_line));
-
+
 /* Put the OS version in place of the hostname */
 if (uname(_buf) == 0)
strncpy(utmp.ut_host, uname_buf.release, sizeof(utmp.ut_host));

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 24cc56fa..4e3d22c4 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -835,7 +835,7 @@ int main(int argc, char **argv)
 
if (respawn_delay * respawn_max > respawn_period)
ewarn("%s: Please increase the value of 
--respawn-period to more "
-   "than %d to avoid infinite respawning", applet, 
+   "than %d to avoid infinite respawning", applet,
respawn_delay * respawn_max);
 
if (retry) {



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

2018-10-15 Thread William Hubbs
commit: 710c874e6e3bc57b1561eb8f2108244bf24ed32e
Author: Zac Medico  gmail  com>
AuthorDate: Sat Oct 13 19:32:45 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Oct 15 16:50:42 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=710c874e

supervise-daemon: fix respawn_max off by one

Fix the comparison between respawn_count and respawn_max so that
respawn_max = 1 will allow for one respawn. Since respawn_count is
incremented before the comparison, use a 'greater than' comparison
so that respawn will be triggered when respawn_count is equal to
respawn_max.

Fixes: https://github.com/OpenRC/openrc/issues/247
Fixes: https://github.com/OpenRC/openrc/issues/248

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 4e3d22c4..27089152 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -510,7 +510,7 @@ static void supervisor(char *exec, char **argv)
first_spawn = 0;
} else
respawn_count++;
-   if (respawn_count >= respawn_max) {
+   if (respawn_count > respawn_max) {
syslog(LOG_WARNING,
"respawned \"%s\" too 
many times, exiting", exec);
exiting = true;



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

2018-10-09 Thread William Hubbs
commit: 67e2d6033dd7ac6db0269ee060ed20484825ff9f
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct  9 16:34:52 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct  9 16:34:52 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=67e2d603

Complete implementation of forever timeout value in stop schedules

 src/rc/rc-schedules.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 8f36f073..f7ef20fb 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -351,8 +351,9 @@ int run_stop_schedule(const char *applet,
 
tkilled += nkilled;
break;
+   case SC_FOREVER:
case SC_TIMEOUT:
-   if (item->value < 1) {
+   if (item->type == SC_TIMEOUT && item->value < 1) {
item = NULL;
break;
}
@@ -360,7 +361,7 @@ int run_stop_schedule(const char *applet,
ts.tv_sec = 0;
ts.tv_nsec = POLL_INTERVAL;
 
-   for (nsecs = 0; nsecs < item->value; nsecs++) {
+   for (nsecs = 0; item->type == SC_FOREVER || nsecs < 
item->value; nsecs++) {
for (nloops = 0;
 nloops < ONE_SECOND / POLL_INTERVAL;
 nloops++)



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

2018-10-06 Thread William Hubbs
commit: 7ee3e5b2d6dbb9c279011b59ec132d27d04f843e
Author: William Hubbs  gmail  com>
AuthorDate: Sat Oct  6 17:49:44 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Oct  6 17:49:44 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7ee3e5b2

openrc-init: convert sleep() call to nanosleep()

Nanosleep is the safer call to use in case we need to use alarms
eventually.

 src/rc/openrc-init.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index d8038637..e02fa5ee 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -96,12 +97,15 @@ static void handle_reexec(char *my_name)
 static void handle_shutdown(const char *runlevel, int cmd)
 {
pid_t pid;
+   struct timespec ts;
 
pid = do_openrc(runlevel);
while (waitpid(pid, NULL, 0) != pid);
printf("Sending the final term signal\n");
kill(-1, SIGTERM);
-   sleep(3);
+   ts.tv_sec = 3;
+   ts.tv_nsec = 0;
+   nanosleep(, NULL);
printf("Sending the final kill signal\n");
kill(-1, SIGKILL);
sync();



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

2018-10-06 Thread William Hubbs
commit: eca4357892315ca7340bbfc2b373d7660a34142f
Author: William Hubbs  gmail  com>
AuthorDate: Sat Oct  6 17:51:04 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Oct  6 17:51:04 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=eca43578

supervise-daemon: use nanosleep() instead of sleep()

We will be using sigalrm in this process for health checking, and
sigalrm cannot be used with sleep() safely.

 src/rc/supervise-daemon.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 8d56b8d4..24cc56fa 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -425,6 +425,7 @@ static void supervisor(char *exec, char **argv)
FILE *fp;
int i;
int nkilled;
+   struct timespec ts;
time_t respawn_now= 0;
time_t first_spawn= 0;
 
@@ -497,7 +498,9 @@ static void supervisor(char *exec, char **argv)
if (nkilled > 0)
syslog(LOG_INFO, "killed %d processes", 
nkilled);
} else {
-   sleep(respawn_delay);
+   ts.tv_sec = respawn_delay;
+   ts.tv_nsec = 0;
+   nanosleep(, NULL);
if (respawn_max > 0 && respawn_period > 0) {
respawn_now = time(NULL);
if (first_spawn == 0)



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

2018-06-29 Thread William Hubbs
commit: 79648ac1c6355975abca6acf6076e7022037523f
Author: Holger Hoffstätte  applied-asynchrony  com>
AuthorDate: Thu Jun 28 21:08:57 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Jun 29 13:49:13 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=79648ac1

rc-status: initialize uptime pointer to prevent memory corruption

This fixes #231.

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

diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index 85e71dbb..cebdc5ed 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -87,7 +87,7 @@ static char *get_uptime(const char *service)
time_t diff_hours = (time_t) 0;
time_t diff_mins = (time_t) 0;
time_t diff_secs = (time_t) 0;
-   char *uptime;
+   char *uptime = NULL;
 
if (state & RC_SERVICE_STARTED) {
start_count = rc_service_value_get(service, "start_count");



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

2018-06-28 Thread William Hubbs
commit: 56ddda54b5aa01474bf563d5a662075c35152858
Author: William Hubbs  gmail  com>
AuthorDate: Wed Jun 27 22:37:11 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jun 27 22:37:11 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=56ddda54

supervise-daemon.c: clean up memory leaks

 src/rc/supervise-daemon.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 60bd1f20..8d56b8d4 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -860,10 +860,13 @@ int main(int argc, char **argv)
varbuf = NULL;
xasprintf(, "%i", respawn_delay);
rc_service_value_set(svcname, "respawn_delay", varbuf);
+   free(varbuf);
xasprintf(, "%i", respawn_max);
rc_service_value_set(svcname, "respawn_max", varbuf);
+   free(varbuf);
xasprintf(, "%i", respawn_period);
rc_service_value_set(svcname, "respawn_period", varbuf);
+   free(varbuf);
child_pid = fork();
if (child_pid == -1)
eerrorx("%s: fork: %s", applet, strerror(errno));
@@ -891,6 +894,7 @@ int main(int argc, char **argv)
}
xasprintf(, "%d", x);
rc_service_value_set(svcname, "argc", varbuf);
+   free(varbuf);
rc_service_value_set(svcname, "exec", exec);
supervisor(exec, argv);
} else



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

2018-06-20 Thread William Hubbs
commit: 64354831da2adeba5cb2f91a81fa0f56e1ce4ed9
Author: William Hubbs  gmail  com>
AuthorDate: Wed Jun 20 14:37:20 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jun 20 14:37:20 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=64354831

openrc: convert snprintf calls to xasprintf

 src/rc/rc.c | 40 
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/src/rc/rc.c b/src/rc/rc.c
index f613b5b6..c6e453b3 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -101,7 +101,6 @@ clean_failed(void)
 {
DIR *dp;
struct dirent *d;
-   size_t l;
char *path;
 
/* Clean the failed services state dir now */
@@ -112,16 +111,11 @@ clean_failed(void)
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
 
-   l = strlen(RC_SVCDIR "/failed/") +
-   strlen(d->d_name) + 1;
-   path = xmalloc(sizeof(char) * l);
-   snprintf(path, l, RC_SVCDIR "/failed/%s", d->d_name);
-   if (path) {
-   if (unlink(path))
-   eerror("%s: unlink `%s': %s",
-   applet, path, strerror(errno));
-   free(path);
-   }
+   xasprintf(, RC_SVCDIR "/failed/%s", d->d_name);
+   if (unlink(path))
+   eerror("%s: unlink `%s': %s",
+   applet, path, strerror(errno));
+   free(path);
}
closedir(dp);
}
@@ -391,7 +385,7 @@ static void
 handle_signal(int sig)
 {
int serrno = errno;
-   char signame[10] = { '\0' };
+   char *signame = NULL;
pid_t pid;
RC_PID *pi;
int status = 0;
@@ -422,16 +416,16 @@ handle_signal(int sig)
break;
 
case SIGINT:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGINT");
+   if (!signame)
+   xasprintf(, "SIGINT");
/* FALLTHROUGH */
case SIGTERM:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGTERM");
+   if (!signame)
+   xasprintf(, "SIGTERM");
/* FALLTHROUGH */
case SIGQUIT:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGQUIT");
+   if (!signame)
+   xasprintf(, "SIGQUIT");
eerrorx("%s: caught %s, aborting", applet, signame);
/* NOTREACHED */
case SIGUSR1:
@@ -512,14 +506,11 @@ runlevel_config(const char *service, const char *level)
 {
char *init = rc_service_resolve(service);
char *conf, *dir;
-   size_t l;
bool retval;
 
dir = dirname(init);
dir = dirname(init);
-   l = strlen(dir) + strlen(level) + strlen(service) + 10;
-   conf = xmalloc(sizeof(char) * l);
-   snprintf(conf, l, "%s/conf.d/%s.%s", dir, service, level);
+   xasprintf(, "%s/conf.d/%s.%s", dir, service, level);
retval = exists(conf);
free(conf);
free(init);
@@ -744,7 +735,7 @@ int main(int argc, char **argv)
bool going_down = false;
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
char *krunlevel = NULL;
-   char pidstr[10];
+   char *pidstr = NULL;
int opt;
bool parallel;
int regen = 0;
@@ -844,8 +835,9 @@ int main(int argc, char **argv)
setenv("EINFO_LOG", "openrc", 1);
 
/* Export our PID */
-   snprintf(pidstr, sizeof(pidstr), "%d", getpid());
+   xasprintf(, "%d", getpid());
setenv("RC_PID", pidstr, 1);
+   free(pidstr);
 
/* Create a list of all services which should be started for the new or
* current runlevel including those in boot, sysinit and hotplugged



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

2018-06-19 Thread William Hubbs
commit: f9d41243d8499c5d7027177d5aa716d5b5859cd6
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 22:46:12 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 22:46:12 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f9d41243

start-stop-daemon: convert snprintf calls to xasprintf

 src/rc/start-stop-daemon.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index a04a00ec..33f886c4 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -167,20 +167,20 @@ handle_signal(int sig)
 {
int status;
int serrno = errno;
-   char signame[10] = { '\0' };
+   char *signame = NULL;
 
switch (sig) {
case SIGINT:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGINT");
+   if (!signame)
+   xasprintf(, "SIGINT");
/* FALLTHROUGH */
case SIGTERM:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGTERM");
+   if (!signame)
+   xasprintf(, "SIGTERM");
/* FALLTHROUGH */
case SIGQUIT:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGQUIT");
+   if (!signame)
+   xasprintf(, "SIGQUIT");
eerrorx("%s: caught %s, aborting", applet, signame);
/* NOTREACHED */
 
@@ -199,6 +199,9 @@ handle_signal(int sig)
eerror("%s: caught unknown signal %d", applet, sig);
}
 
+   /* free signame */
+   free(signame);
+
/* Restore errno */
errno = serrno;
 }
@@ -207,7 +210,6 @@ static char *
 expand_home(const char *home, const char *path)
 {
char *opath, *ppath, *p, *nh;
-   size_t len;
struct passwd *pw;
 
if (!path || *path != '~')
@@ -238,9 +240,7 @@ expand_home(const char *home, const char *path)
return xstrdup(home);
}
 
-   len = strlen(ppath) + strlen(home) + 1;
-   nh = xmalloc(len);
-   snprintf(nh, len, "%s%s", home, ppath);
+   xasprintf(, "%s%s", home, ppath);
free(opath);
return nh;
 }



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

2018-06-19 Thread William Hubbs
commit: e14edd765fdc4ed43356d2eef35fa99228e5d461
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 22:57:10 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 22:57:10 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e14edd76

supervise-daemon: convert snprintf calls to xasprintf

 src/rc/supervise-daemon.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 952c610b..60bd1f20 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -186,7 +186,6 @@ static void handle_signal(int sig)
 static char * expand_home(const char *home, const char *path)
 {
char *opath, *ppath, *p, *nh;
-   size_t len;
struct passwd *pw;
 
if (!path || *path != '~')
@@ -217,9 +216,7 @@ static char * expand_home(const char *home, const char 
*path)
return xstrdup(home);
}
 
-   len = strlen(ppath) + strlen(home) + 1;
-   nh = xmalloc(len);
-   snprintf(nh, len, "%s%s", home, ppath);
+   xasprintf(, "%s%s", home, ppath);
free(opath);
return nh;
 }



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

2018-06-19 Thread William Hubbs
commit: be7ad06d4a0efce2a1144b2cf6f0cc361f2a81e4
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 22:06:33 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 22:06:33 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=be7ad06d

rc-status: convert snprintf calls to xasprintf

 src/rc/rc-status.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index a6b8d299..85e71dbb 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -126,7 +126,7 @@ static char *get_uptime(const char *service)
 static void
 print_service(const char *service)
 {
-   char status[60];
+   char *status = NULL;
char *uptime = NULL;
char *child_pid = NULL;
char *start_time = NULL;
@@ -136,12 +136,12 @@ print_service(const char *service)
ECOLOR color = ECOLOR_BAD;
 
if (state & RC_SERVICE_STOPPING)
-   snprintf(status, sizeof(status), "stopping ");
+   xasprintf(, "stopping ");
else if (state & RC_SERVICE_STARTING) {
-   snprintf(status, sizeof(status), "starting ");
+   xasprintf(, "starting ");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_INACTIVE) {
-   snprintf(status, sizeof(status), "inactive ");
+   xasprintf(, "inactive ");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_STARTED) {
errno = 0;
@@ -150,30 +150,31 @@ print_service(const char *service)
child_pid = rc_service_value_get(service, "child_pid");
start_time = rc_service_value_get(service, 
"start_time");
if (start_time && child_pid)
-   snprintf(status, sizeof(status), " unsupervised 
");
+   xasprintf(, " unsupervised ");
else
-   snprintf(status, sizeof(status), " crashed ");
+   xasprintf(, " crashed ");
free(child_pid);
free(start_time);
} else {
uptime = get_uptime(service);
if (uptime) {
-   snprintf(status, sizeof(status), " started %s", 
uptime);
+   xasprintf(, " started %s", uptime);
free(uptime);
} else
-   snprintf(status, sizeof(status), " started ");
+   xasprintf(, " started ");
color = ECOLOR_GOOD;
}
} else if (state & RC_SERVICE_SCHEDULED) {
-   snprintf(status, sizeof(status), "scheduled");
+   xasprintf(, "scheduled");
color = ECOLOR_WARN;
} else
-   snprintf(status, sizeof(status), " stopped ");
+   xasprintf(, " stopped ");
 
errno = 0;
if (c && *c && isatty(fileno(stdout)))
printf("\n");
ebracket(cols, color, status);
+   free(status);
 }
 
 static void



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

2018-06-19 Thread William Hubbs
commit: a6165168953b9c7a62c089ce946476b23b73fb12
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 21:15:22 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 21:18:48 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a6165168

rc-status: fix gcc 7 warnings

 src/rc/rc-status.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index ab80d901..a6b8d299 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -75,7 +75,7 @@ print_level(const char *prefix, const char *level)
printf("%s\n", level);
 }
 
-static void get_uptime(const char *service, char *uptime, int uptime_size)
+static char *get_uptime(const char *service)
 {
RC_SERVICE state = rc_service_state(service);
char *start_count;
@@ -87,8 +87,8 @@ static void get_uptime(const char *service, char *uptime, int 
uptime_size)
time_t diff_hours = (time_t) 0;
time_t diff_mins = (time_t) 0;
time_t diff_secs = (time_t) 0;
+   char *uptime;
 
-   uptime[0] = '\0';
if (state & RC_SERVICE_STARTED) {
start_count = rc_service_value_get(service, "start_count");
start_time_string = rc_service_value_get(service, "start_time");
@@ -110,23 +110,24 @@ static void get_uptime(const char *service, char *uptime, 
int uptime_size)
diff_secs %= diff_mins * (time_t) 60;
}
if (diff_days > 0)
-   snprintf(uptime, uptime_size,
+   xasprintf(,
"%ld day(s) %02ld:%02ld:%02ld 
(%s)",
diff_days, diff_hours, 
diff_mins, diff_secs,
start_count);
else
-   snprintf(uptime, uptime_size,
+   xasprintf(,
"%02ld:%02ld:%02ld (%s)",
diff_hours, diff_mins, 
diff_secs, start_count);
}
}
+   return uptime;
 }
 
 static void
 print_service(const char *service)
 {
char status[60];
-   char uptime [40];
+   char *uptime = NULL;
char *child_pid = NULL;
char *start_time = NULL;
int cols =  printf(" %s", service);
@@ -155,8 +156,12 @@ print_service(const char *service)
free(child_pid);
free(start_time);
} else {
-   get_uptime(service, uptime, 40);
-   snprintf(status, sizeof(status), " started %s", uptime);
+   uptime = get_uptime(service);
+   if (uptime) {
+   snprintf(status, sizeof(status), " started %s", 
uptime);
+   free(uptime);
+   } else
+   snprintf(status, sizeof(status), " started ");
color = ECOLOR_GOOD;
}
} else if (state & RC_SERVICE_SCHEDULED) {



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

2018-06-19 Thread William Hubbs
commit: c7e8f1133a42152cc293e6b637985f81bcf8b310
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 19:01:54 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 19:01:54 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c7e8f113

checkpath: fix gcc 7 warnings

 src/rc/checkpath.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c
index 07e5f78a..448c9cf8 100644
--- a/src/rc/checkpath.c
+++ b/src/rc/checkpath.c
@@ -269,11 +269,13 @@ int main(int argc, char **argv)
switch (opt) {
case 'D':
trunc = true;
+   /* falls through */
case 'd':
type = inode_dir;
break;
case 'F':
trunc = true;
+   /* falls through */
case 'f':
type = inode_file;
break;



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

2018-06-19 Thread William Hubbs
commit: 04721ece03b15503aa220f60e7c6159d01ee75e1
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 20:32:10 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 20:32:10 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=04721ece

start-stop-daemon: fix gcc 7 warnings

 src/rc/start-stop-daemon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index fceb3058..a04a00ec 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -386,6 +386,7 @@ int main(int argc, char **argv)
case 'c':  /* --chuid | */
/* DEPRECATED */
ewarn("WARNING: -c/--chuid is deprecated and will be 
removed in the future, please use -u/--user instead");
+   /* falls through */
case 'u':  /* --user | */
{
p = optarg;



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

2018-06-19 Thread William Hubbs
commit: 47e4bfae57402eedd017d6098b432c2c411cd374
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jun 19 18:59:16 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jun 19 18:59:16 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=47e4bfae

fix gcc 7 warnings in pipe routines

 src/rc/rc-pipes.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/rc/rc-pipes.c b/src/rc/rc-pipes.c
index 2d7b623e..70fefa80 100644
--- a/src/rc/rc-pipes.c
+++ b/src/rc/rc-pipes.c
@@ -37,21 +37,20 @@ int rc_pipe_command(char *cmd)
return -1;
 
pid = fork();
-   if (pid < 0)
-   return -1;
-   else if (pid > 0) {
+   if (pid > 0) {
/* parent */
-   close(pfd[0]);
+   close(pfd[pipe_read_end]);
return pfd[pipe_write_end];
} else if (pid == 0) {
/* child */
close(pfd[pipe_write_end]);
-   if (pfd[0] != STDIN_FILENO) {
-   if (dup2(pfd[0], STDIN_FILENO) < 0)
+   if (pfd[pipe_read_end] != STDIN_FILENO) {
+   if (dup2(pfd[pipe_read_end], STDIN_FILENO) < 0)
exit(1);
-   close(pfd[0]);
+   close(pfd[pipe_read_end]);
}
execl("/bin/sh", "sh", "-c", cmd, NULL);
exit(1);
}
+   return -1;
 }



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

2018-06-14 Thread William Hubbs
commit: d4501a9f06c807f87be04f128e535a74b370fdb4
Author: William Hubbs  gmail  com>
AuthorDate: Thu Jun 14 19:55:42 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jun 14 19:55:42 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d4501a9f

fix a typo

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

diff --git a/src/rc/rc-pipes.c b/src/rc/rc-pipes.c
index 55f3ff8d..2d7b623e 100644
--- a/src/rc/rc-pipes.c
+++ b/src/rc/rc-pipes.c
@@ -19,7 +19,7 @@
 #include 
 #include 
 
-#include "rc-pipe-command.h"
+#include "rc-pipes.h"
 
 static const int pipe_read_end = 0;
 static const int pipe_write_end = 1;



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

2018-06-13 Thread William Hubbs
commit: ec8abea4605395a2a59b26906ce4677a578e3c60
Author: Mike Gilbert  gentoo  org>
AuthorDate: Wed Jun 13 18:49:42 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jun 13 18:49:42 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ec8abea4

Add helper to spawn process with stdin connected to a pipe

 src/rc/Makefile   |  4 ++--
 src/rc/rc-pipes.c | 57 +++
 src/rc/rc-pipes.h | 18 ++
 3 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/src/rc/Makefile b/src/rc/Makefile
index 5e2a5e94..4b0983b5 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -5,8 +5,8 @@ include ${MK}/os.mk
 SRCS=  checkpath.c do_e.c do_mark_service.c do_service.c \
do_value.c fstabinfo.c is_newer_than.c is_older_than.c \
mountinfo.c openrc-run.c rc-abort.c rc.c \
-   rc-depend.c rc-logger.c rc-misc.c rc-plugin.c \
-   rc-service.c rc-status.c rc-update.c \
+   rc-depend.c rc-logger.c rc-misc.c rc-pipes.c \
+   rc-plugin.c rc-service.c rc-status.c rc-update.c \
shell_var.c start-stop-daemon.c supervise-daemon.c swclock.c 
_usage.c
 
 ifeq (${MKSELINUX},yes)

diff --git a/src/rc/rc-pipes.c b/src/rc/rc-pipes.c
new file mode 100644
index ..55f3ff8d
--- /dev/null
+++ b/src/rc/rc-pipes.c
@@ -0,0 +1,57 @@
+/*
+ * rc-pipes.c
+ * Helper to handle spawning processes and connecting them to pipes.
+ */
+
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#include 
+#include 
+#include 
+
+#include "rc-pipe-command.h"
+
+static const int pipe_read_end = 0;
+static const int pipe_write_end = 1;
+
+/*
+ * Starts a command with stdin redirected from a pipe
+ * Returns the write end of the pipe or -1
+ */
+int rc_pipe_command(char *cmd)
+{
+   int pfd[2];
+   pid_t pid;
+
+   if (pipe(pfd) < 0)
+   return -1;
+
+   pid = fork();
+   if (pid < 0)
+   return -1;
+   else if (pid > 0) {
+   /* parent */
+   close(pfd[0]);
+   return pfd[pipe_write_end];
+   } else if (pid == 0) {
+   /* child */
+   close(pfd[pipe_write_end]);
+   if (pfd[0] != STDIN_FILENO) {
+   if (dup2(pfd[0], STDIN_FILENO) < 0)
+   exit(1);
+   close(pfd[0]);
+   }
+   execl("/bin/sh", "sh", "-c", cmd, NULL);
+   exit(1);
+   }
+}

diff --git a/src/rc/rc-pipes.h b/src/rc/rc-pipes.h
new file mode 100644
index ..0c605ced
--- /dev/null
+++ b/src/rc/rc-pipes.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#ifndef RC_PIPES_H
+#define RC_PIPES_H
+
+int rc_pipe_command(char *cmd);
+
+#endif



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

2018-05-22 Thread William Hubbs
commit: 5d6dd97bba3559b57fb1c1de35e644c6dbd6baa7
Author: William Hubbs  gmail  com>
AuthorDate: Mon May 21 23:16:12 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 22 17:20:38 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=5d6dd97b

rc-misc: add the crashed state

 src/rc/rc-misc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index e933409f..2df4fd42 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -423,6 +423,7 @@ static const struct {
{ "service_hotplugged",  RC_SERVICE_HOTPLUGGED,  },
{ "service_wasinactive", RC_SERVICE_WASINACTIVE, },
{ "service_failed",  RC_SERVICE_FAILED,  },
+   { "service_crashed", RC_SERVICE_CRASHED, },
 };
 
 RC_SERVICE lookup_service_state(const char *service)



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

2018-05-22 Thread William Hubbs
commit: 7e56a49e23c810673b83e48eb9ca36229bb4016e
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 22 22:11:43 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 22 22:11:43 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7e56a49e

Logger: only log printable characters and newlines

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

 src/rc/rc-logger.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index 062ce3d9..22926211 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -87,6 +87,8 @@ write_log(int logfd, const char *buffer, size_t bytes)
}
 
if (!in_escape) {
+   if (!isprint((int) *p) && *p != '\n')
+   goto cont;
if (write(logfd, p++, 1) == -1)
eerror("write: %s", strerror(errno));
continue;



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

2018-05-22 Thread William Hubbs
commit: 0f4fa41574a4ebf8117493e5411f8ab522010467
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 22 16:08:35 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 22 17:20:38 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0f4fa415

Add mark_service_crashed binary

 src/rc/.gitignore | 1 +
 src/rc/Makefile   | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/rc/.gitignore b/src/rc/.gitignore
index 91d57075..a43088aa 100644
--- a/src/rc/.gitignore
+++ b/src/rc/.gitignore
@@ -56,6 +56,7 @@ mark_service_inactive
 mark_service_wasinactive
 mark_service_hotplugged
 mark_service_failed
+mark_service_crashed
 rc-abort
 rc
 openrc

diff --git a/src/rc/Makefile b/src/rc/Makefile
index cb90875c..5e2a5e94 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -41,6 +41,7 @@ RC_SBINPROGS= mark_service_starting mark_service_started \
mark_service_stopping mark_service_stopped \
mark_service_inactive mark_service_wasinactive \
mark_service_hotplugged mark_service_failed \
+   mark_service_crashed \
rc-abort swclock
 
 ifeq (${OS},Linux)
@@ -123,7 +124,8 @@ is_older_than: is_older_than.o rc-misc.o
 mark_service_starting mark_service_started \
 mark_service_stopping mark_service_stopped \
 mark_service_inactive mark_service_wasinactive \
-mark_service_hotplugged mark_service_failed: do_mark_service.o rc-misc.o
+mark_service_hotplugged mark_service_failed \
+mark_service_crashed: do_mark_service.o rc-misc.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 mountinfo: mountinfo.o _usage.o rc-misc.o



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

2018-05-16 Thread William Hubbs
commit: 08da36149c0b41c64a09369c3eef5e2f5a6fa39c
Author: William Hubbs  gmail  com>
AuthorDate: Wed May 16 18:25:22 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May 16 18:25:22 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=08da3614

rc-service: add --ifstarted and --ifstopped options

 man/rc-service.8|  8 
 src/rc/rc-service.c | 16 +++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/man/rc-service.8 b/man/rc-service.8
index 2834f361..72d5a559 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -40,6 +40,14 @@
 .Ar service cmd
 .Op Ar ...
 .Nm
+.Op Fl s , -ifstarted
+.Ar service cmd
+.Op Ar ...
+.Nm
+.Op Fl S , -ifstopped
+.Ar service cmd
+.Op Ar ...
+.Nm
 .Fl e , -exists
 .Ar service
 .Nm

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index ea69dab5..8b01fa0d 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -29,7 +29,7 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "cdDe:ilr:INZ" getoptstring_COMMON;
+const char *getoptstring = "cdDe:ilr:INsSZ" getoptstring_COMMON;
 const struct option longopts[] = {
{ "debug", 0, NULL, 'd' },
{ "nodeps", 0, NULL, 'D' },
@@ -38,6 +38,8 @@ const struct option longopts[] = {
{ "ifexists", 0, NULL, 'i' },
{ "ifinactive", 0, NULL, 'I' },
{ "ifnotstarted", 0, NULL, 'N' },
+   { "ifstarted", 0, NULL, 's' },
+   { "ifstopped", 0, NULL, 'S' },
{ "list", 0, NULL, 'l' },
{ "resolve",  1, NULL, 'r' },
{ "dry-run", 0, NULL, 'Z' },
@@ -73,6 +75,8 @@ int main(int argc, char **argv)
bool if_exists = false;
bool if_inactive = false;
bool if_notstarted = false;
+   bool if_started = false;
+   bool if_stopped = false;
 
applet = basename_c(argv[0]);
/* Ensure that we are only quiet when explicitly told to be */
@@ -124,6 +128,12 @@ int main(int argc, char **argv)
free(service);
return EXIT_SUCCESS;
/* NOTREACHED */
+   case 's':
+   if_started = true;
+   break;
+   case 'S':
+   if_stopped = true;
+   break;
case 'Z':
setenv("IN_DRYRUN", "yes", 1);
break;
@@ -148,6 +158,10 @@ int main(int argc, char **argv)
return 0;
if (if_notstarted && (state & RC_SERVICE_STARTED))
return 0;
+   if (if_started && ! (state & RC_SERVICE_STARTED))
+   return 0;
+   if (if_stopped && ! (state & RC_SERVICE_STOPPED))
+   return 0;
*argv = service;
execv(*argv, argv);
eerrorx("%s: %s", applet, strerror(errno));



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

2018-05-15 Thread William Hubbs
commit: 04886efd85328988657c34440da9ba6aa2841cfd
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 15 21:18:19 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 15 21:18:19 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=04886efd

Add RC_DEBUG and RC_NODEPS to environment whitelist

These are needed so rc-service can pass debug and nodeps options to
openrc-run.

 src/rc/rc-misc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index e676ad9e..50c09747 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -52,6 +52,7 @@ rc_conf_yesno(const char *setting)
 static const char *const env_whitelist[] = {
"EERROR_QUIET", "EINFO_QUIET",
"IN_BACKGROUND", "IN_DRYRUN", "IN_HOTPLUG",
+   "RC_DEBUG", "RC_NODEPS",
"LANG", "LC_MESSAGES", "TERM",
"EINFO_COLOR", "EINFO_VERBOSE",
NULL



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

2018-05-15 Thread William Hubbs
commit: 958f57d895b6573b39e62097e5e9881f16174715
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 15 21:27:42 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 15 21:27:42 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=958f57d8

openrc-run: respect the RC_NODEPS environment variable

 src/rc/openrc-run.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index ac682c4c..43889f2d 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -1268,6 +1268,9 @@ int main(int argc, char **argv)
case_RC_COMMON_GETOPT
}
 
+   if (rc_yesno(getenv("RC_NODEPS")))
+   deps = false;
+
/* If we're changing runlevels and not called by rc then we cannot
   work with any dependencies */
if (deps && getenv("RC_PID") == NULL &&



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

2018-05-14 Thread William Hubbs
commit: d980798d6444bbfc508796a233e962bf4dd61275
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 15 00:08:19 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 15 00:08:19 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d980798d

openrc-run: respect the IN_DRYRUN environment variable

This allows rc-service to pass the tryrun option to openrc-run.

This is for #225.

 src/rc/openrc-run.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index 73def8fb..ac682c4c 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -1282,6 +1282,8 @@ int main(int argc, char **argv)
unsetenv("IN_BACKGROUND");
}
 
+   if (rc_yesno(getenv("IN_DRYRUN")))
+   dry_run = true;
if (rc_yesno(getenv("IN_HOTPLUG"))) {
if (!service_plugable())
eerrorx("%s: not allowed to be hotplugged", applet);



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

2018-05-14 Thread William Hubbs
commit: 414a9aae6ce066d2a6ad42e7e24d1c12a7b46409
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 15 00:04:42 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 15 00:04:42 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=414a9aae

rc-misc.c: Add IN_DRYRUN to environment whitelist

This allows rc-service to pass the dryrun option to openrc-run.

This is for #225.

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

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index 2c9903c3..e676ad9e 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -51,7 +51,7 @@ rc_conf_yesno(const char *setting)
 
 static const char *const env_whitelist[] = {
"EERROR_QUIET", "EINFO_QUIET",
-   "IN_BACKGROUND", "IN_HOTPLUG",
+   "IN_BACKGROUND", "IN_DRYRUN", "IN_HOTPLUG",
"LANG", "LC_MESSAGES", "TERM",
"EINFO_COLOR", "EINFO_VERBOSE",
NULL



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

2018-05-11 Thread William Hubbs
commit: b35e03b6b1acc841ac33f601dd39c1152523621e
Author: William Hubbs  gmail  com>
AuthorDate: Fri May 11 00:35:24 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri May 11 00:35:24 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b35e03b6

Revert "Logger: only log printable characters and newlines"

This reverts commit 2b1392af2fe9e5dfc8eda2f19d896efdc41840bf.
This seems to create issues shutting down, so I need to look into it
further.

 src/rc/rc-logger.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index 1da3f59c..062ce3d9 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -87,9 +87,8 @@ write_log(int logfd, const char *buffer, size_t bytes)
}
 
if (!in_escape) {
-   if (isprint((unsigned char) *p) || *p == '\n')
-   if (write(logfd, p++, 1) == -1)
-   eerror("write: %s", strerror(errno));
+   if (write(logfd, p++, 1) == -1)
+   eerror("write: %s", strerror(errno));
continue;
}
 



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

2018-05-09 Thread William Hubbs
commit: 2b1392af2fe9e5dfc8eda2f19d896efdc41840bf
Author: William Hubbs  gmail  com>
AuthorDate: Wed May  9 22:30:08 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May  9 22:30:08 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=2b1392af

Logger: only log printable characters and newlines

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

 src/rc/rc-logger.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index 062ce3d9..1da3f59c 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -87,8 +87,9 @@ write_log(int logfd, const char *buffer, size_t bytes)
}
 
if (!in_escape) {
-   if (write(logfd, p++, 1) == -1)
-   eerror("write: %s", strerror(errno));
+   if (isprint((unsigned char) *p) || *p == '\n')
+   if (write(logfd, p++, 1) == -1)
+   eerror("write: %s", strerror(errno));
continue;
}
 



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

2018-05-07 Thread William Hubbs
commit: 022b8cbd061ac79b6aed4024220cd0386d2c
Author: Andrey Utkin  gentoo  org>
AuthorDate: Sat Apr 21 22:13:15 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May  2 18:42:59 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=022b

start-stop-daemon: don't fail stopping if pidfile is gone

If pidfile does not exist when we are stopping the daemon, assume it is
already stopped, and report success.

hostapd is an example of a daemon which removes its pidfile when it is
exiting. If this daemon terminates prematurely, that is, without s-s-d
involvement, then openrc fails to restart it, because s-s-d "stop"
command fails when pidfile is missing.

X-Gentoo-Bug: 646274
X-Gentoo-Bug-URL: https://bugs.gentoo.org/646274

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

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 1b565829..0b3b423f 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -661,7 +661,7 @@ int main(int argc, char **argv)
parse_schedule(applet, NULL, sig);
if (pidfile) {
pid = get_pid(applet, pidfile);
-   if (pid == -1)
+   if (pid == -1 && errno != ENOENT)
exit(EXIT_FAILURE);
} else {
pid = 0;



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

2018-05-07 Thread William Hubbs
commit: 2ae60ca0419d60c86904a8e15e71e902549e18d4
Author: Scall  users  noreply  github  com>
AuthorDate: Wed Mar 21 12:33:33 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Mar 21 12:33:33 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=2ae60ca0

rc-update: fix typo

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

diff --git a/src/rc/rc-update.c b/src/rc/rc-update.c
index abe40b88..b0a73609 100644
--- a/src/rc/rc-update.c
+++ b/src/rc/rc-update.c
@@ -62,7 +62,7 @@ add(const char *runlevel, const char *service)
 
if (!rc_service_exists(service)) {
if (errno == ENOEXEC)
-   eerror("%s: service `%s' is not executeable",
+   eerror("%s: service `%s' is not executable",
applet, service);
else
eerror("%s: service `%s' does not exist",



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

2018-03-14 Thread William Hubbs
commit: 5346fbf2c90b33b3abc01588e4727d4402f8db62
Author: William Hubbs  gmail  com>
AuthorDate: Thu Mar 15 01:05:45 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Mar 15 01:05:45 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=5346fbf2

supervise-daemon: fix off-by-one error

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 669db3a2..952c610b 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -232,8 +232,8 @@ static char *make_cmdline(char **argv)
 
for (c = argv; c && *c; c++)
len += (strlen(*c) + 1);
-   cmdline = xmalloc(len);
-   memset(cmdline, 0, len);
+   cmdline = xmalloc(len+1);
+   memset(cmdline, 0, len+1);
for (c = argv; c && *c; c++) {
strcat(cmdline, *c);
strcat(cmdline, " ");



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

2018-03-11 Thread William Hubbs
commit: b46123f2e19a5eb8dc02b898e8c20a2ccc211615
Author: Chris Cromer  users  noreply  github  
com>
AuthorDate: Fri Mar  2 00:31:33 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Mar  2 00:31:33 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b46123f2

openrc-run: fix memory size (#213)

Fixes #212 

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

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index daeafc52..73def8fb 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -1152,7 +1152,7 @@ int main(int argc, char **argv)
}
lnk = xmalloc(4096);
memset(lnk, 0, 4096);
-   if (readlink(argv[1], lnk, sizeof(lnk)-1)) {
+   if (readlink(argv[1], lnk, 4096)) {
dir = dirname(path);
if (strchr(lnk, '/')) {
save = xstrdup(dir);



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

2018-02-28 Thread William Hubbs
commit: 038c03bef315314ddb1e460c67d29b2599b494ad
Author: William Hubbs  gmail  com>
AuthorDate: Tue Feb 27 22:02:20 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Feb 27 22:02:20 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=038c03be

supervise-daemon: make an error message more verbose

 src/rc/supervise-daemon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 6d36a5aa..669db3a2 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -581,7 +581,8 @@ int main(int argc, char **argv)
openlog(applet, LOG_PID, LOG_DAEMON);
 
if (argc >= 1 && svcname && strcmp(argv[1], svcname))
-   eerrorx("%s: the first argument must be %s", applet, svcname);
+   eerrorx("%s: the first argument is %s and must be %s",
+   applet, argv[1], svcname);
 
if ((tmp = getenv("SSD_NICELEVEL")))
if (sscanf(tmp, "%d", ) != 1)



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

2018-02-26 Thread William Hubbs
commit: 0506d68427e342366d826aae4bfbbc6cc0adecc2
Author: William Hubbs  gmail  com>
AuthorDate: Mon Feb 26 19:46:47 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Feb 26 19:46:47 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0506d684

fstabinfo: fix an error message

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

diff --git a/src/rc/fstabinfo.c b/src/rc/fstabinfo.c
index a2e707aa..a35a52f6 100644
--- a/src/rc/fstabinfo.c
+++ b/src/rc/fstabinfo.c
@@ -141,7 +141,7 @@ do_mount(struct ENT *ent, bool remount)
/* NOTREACHED */
case 0:
execvp(argv[0], argv);
-   eerror("%s: execv: %s", applet, strerror(errno));
+   eerror("%s: execvp: %s", applet, strerror(errno));
_exit(EXIT_FAILURE);
/* NOTREACHED */
default:



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

2018-02-26 Thread William Hubbs
commit: e93b1d76d150c4477015052fc3df9b94647e5b5d
Author: William Hubbs  gmail  com>
AuthorDate: Mon Feb 26 19:13:44 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Feb 26 19:13:44 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e93b1d76

openrc: convert another execl() call to execlp()

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

diff --git a/src/rc/rc.c b/src/rc/rc.c
index 3054f6c2..a65f35e1 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -288,8 +288,8 @@ open_shell(void)
/* VSERVER systems cannot really drop to shells */
if (sys && strcmp(sys, RC_SYS_VSERVER) == 0)
{
-   execl("/sbin/halt", "/sbin/halt", "-f", (char *) NULL);
-   eerrorx("%s: unable to exec `/sbin/halt': %s",
+   execlp("halt", "halt", "-f", (char *) NULL);
+   eerrorx("%s: unable to exec `halt -f': %s",
applet, strerror(errno));
}
 #endif



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

2018-02-26 Thread William Hubbs
commit: c3d666acaf51c771671b0fa54bd8ec0f5d29859e
Author: William Hubbs  gmail  com>
AuthorDate: Mon Feb 26 19:14:31 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Feb 26 19:14:31 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c3d666ac

openrc: remove unused #define's.

 src/rc/rc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/rc/rc.c b/src/rc/rc.c
index a65f35e1..f613b5b6 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -78,9 +78,6 @@ const char *usagestring = ""  
\
 #define INITSH  RC_LIBEXECDIR "/sh/init.sh"
 #define INITEARLYSH RC_LIBEXECDIR "/sh/init-early.sh"
 
-#define SHUTDOWN"/sbin/shutdown"
-#define SULOGIN "/sbin/sulogin"
-
 #define INTERACTIVE RC_SVCDIR "/interactive"
 
 #define DEVBOOT"/dev/.rcboot"



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

2018-02-26 Thread William Hubbs
commit: acf1e43f815898c4a4957db352f71f3fb629edf3
Author: William Hubbs  gmail  com>
AuthorDate: Mon Feb 26 18:21:14 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Feb 26 18:21:14 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=acf1e43f

openrc-init: convert execl calls to execlp

 src/rc/openrc-init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index de570e56..d8038637 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -54,7 +54,7 @@ static pid_t do_openrc(const char *runlevel)
sigemptyset();
sigprocmask(SIG_SETMASK, , NULL);
printf("Starting %s runlevel\n", runlevel);
-   execl("/sbin/openrc", "/sbin/openrc", runlevel, NULL);
+   execlp("openrc", "openrc", runlevel, NULL);
perror("exec");
break;
default:
@@ -89,7 +89,7 @@ static void init(const char *default_runlevel)
 
 static void handle_reexec(char *my_name)
 {
-   execl(my_name, my_name, "reexec", NULL);
+   execlp(my_name, my_name, "reexec", NULL);
return;
 }
 



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

2018-02-24 Thread William Hubbs
commit: f383fd87b121492a04362ca9041f686d981718f1
Author: William Hubbs  gmail  com>
AuthorDate: Sat Feb 24 23:02:02 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Feb 24 23:02:02 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f383fd87

kill_all: change execl call to execlp

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

diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c
index d6ce354b..3aeaa262 100644
--- a/src/rc/kill_all.c
+++ b/src/rc/kill_all.c
@@ -65,7 +65,7 @@ static int mount_proc(void)
break;
case 0:
/* attempt to mount /proc */
-   execl("mount", "mount", "-t", "proc", "proc", "/proc", 
NULL);
+   execlp("mount", "mount", "-t", "proc", "proc", "/proc", 
NULL);
syslog(LOG_ERR, "Unable to execute mount");
exit(1);
break;



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

2018-02-24 Thread William Hubbs
commit: cfded513cd9b7febe4b7cf39a80411e4303f0655
Author: William Hubbs  gmail  com>
AuthorDate: Sat Feb 24 22:24:08 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Feb 24 22:24:08 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cfded513

openrc-init: set a default path

The default path provided by the system if one isn't set only includes
"/bin:/usr/bin". This adds the default path setting from sysvinit.

 src/rc/openrc-init.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index eb346f59..de570e56 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -35,6 +35,7 @@
 #include "rc-wtmp.h"
 #include "version.h"
 
+static const char *path_default = "/sbin:/usr/sbin:/bin:/usr/bin";
 static const char *rc_default_runlevel = "default";
 
 static pid_t do_openrc(const char *runlevel)
@@ -183,6 +184,9 @@ int main(int argc, char **argv)
sigaction(SIGINT, , NULL);
reboot(RB_DISABLE_CAD);
 
+   /* set default path */
+   setenv("PATH", path_default, 1);
+
if (! reexec)
init(default_runlevel);
 



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

2018-02-22 Thread William Hubbs
commit: aa7d3a7911b658c550e7ce76cd6d7d46541fc323
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 22 22:16:07 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 22 22:16:07 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=aa7d3a79

openrc: force deptree update for sysinit runlevel

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

diff --git a/src/rc/rc.c b/src/rc/rc.c
index 1f462c66..3054f6c2 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -505,6 +505,9 @@ do_sysinit()
 * sys */
if ((sys = rc_sys()))
setenv("RC_SYS", sys, 1);
+   /* force an update of the dependency tree */
+   if ((main_deptree = _rc_deptree_load(1, NULL)) == NULL)
+   eerrorx("failed to load deptree");
 }
 
 static bool



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

2018-02-22 Thread William Hubbs
commit: 98262647a9d2f3c65a7ceb1aaa81095522c1ef06
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 22 18:54:21 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 22 18:54:21 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=98262647

supervise-daemon: zero out the cmdline buffer when it is allocated

 src/rc/supervise-daemon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index a858cf46..6d36a5aa 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -233,6 +233,7 @@ static char *make_cmdline(char **argv)
for (c = argv; c && *c; c++)
len += (strlen(*c) + 1);
cmdline = xmalloc(len);
+   memset(cmdline, 0, len);
for (c = argv; c && *c; c++) {
strcat(cmdline, *c);
strcat(cmdline, " ");



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

2018-02-21 Thread William Hubbs
commit: 71aad16256604e0e9e146221957a9b00cfe67b99
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 22 00:15:35 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 22 00:15:35 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=71aad162

openrc-run: clean up a compiler warning

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

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index 7e8d2e50..daeafc52 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -1151,7 +1151,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
lnk = xmalloc(4096);
-   memset(lnk, 0, sizeof(lnk));
+   memset(lnk, 0, 4096);
if (readlink(argv[1], lnk, sizeof(lnk)-1)) {
dir = dirname(path);
if (strchr(lnk, '/')) {



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

2018-02-21 Thread William Hubbs
commit: e275da84de1589253da5ff6a7c272cf1c82f8567
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 22 00:14:56 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 22 00:14:56 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e275da84

supervise-daemon: remove references to PATH_MAX

 src/rc/supervise-daemon.c | 102 +-
 1 file changed, 56 insertions(+), 46 deletions(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 06d0bdb3..a858cf46 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -224,6 +224,22 @@ static char * expand_home(const char *home, const char 
*path)
return nh;
 }
 
+static char *make_cmdline(char **argv)
+{
+   char **c;
+   char *cmdline = NULL;
+   size_t len = 0;
+
+   for (c = argv; c && *c; c++)
+   len += (strlen(*c) + 1);
+   cmdline = xmalloc(len);
+   for (c = argv; c && *c; c++) {
+   strcat(cmdline, *c);
+   strcat(cmdline, " ");
+   }
+   return cmdline;
+}
+
 static void child_process(char *exec, char **argv)
 {
RC_STRINGLIST *env_list;
@@ -234,8 +250,7 @@ static void child_process(char *exec, char **argv)
size_t len;
char *newpath;
char *np;
-   char **c;
-   char cmdline[PATH_MAX];
+   char *cmdline = NULL;
time_t start_time;
char start_count_string[20];
char start_time_string[20];
@@ -395,15 +410,9 @@ static void child_process(char *exec, char **argv)
 
for (i = getdtablesize() - 1; i >= 3; --i)
fcntl(i, F_SETFD, FD_CLOEXEC);
-
-   *cmdline = '\0';
-   c = argv;
-   while (c && *c) {
-   strcat(cmdline, *c);
-   strcat(cmdline, " ");
-   c++;
-   }
+   cmdline = make_cmdline(argv);
syslog(LOG_INFO, "Child command line: %s", cmdline);
+   free(cmdline);
execvp(exec, argv);
 
 #ifdef HAVE_PAM
@@ -551,8 +560,8 @@ int main(int argc, char **argv)
char *token;
int i;
int n;
-   char exec_file[PATH_MAX];
-   char name[PATH_MAX];
+   char *exec_file = NULL;
+   char *varbuf = NULL;
struct timespec ts;
struct passwd *pw;
struct group *gr;
@@ -561,7 +570,7 @@ int main(int argc, char **argv)
int child_argc = 0;
char **child_argv = NULL;
char *str = NULL;
-   char cmdline[PATH_MAX];
+   char *cmdline = NULL;
 
applet = basename_c(argv[0]);
atexit(cleanup);
@@ -593,13 +602,7 @@ int main(int argc, char **argv)
}
}
 
-   *cmdline = '\0';
-   c = argv;
-   while (c && *c) {
-   strcat(cmdline, *c);
-   strcat(cmdline, " ");
-   c++;
-   }
+   cmdline = make_cmdline(argv);
if (svcname) {
argc--;
argv++;
@@ -761,9 +764,11 @@ int main(int argc, char **argv)
child_argv = xmalloc((child_argc + 1) * sizeof(char *));
memset(child_argv, 0, (child_argc + 1) * sizeof(char *));
for (x = 0; x < child_argc; x++) {
-   sprintf(name, "argv_%d", x);
-   str = rc_service_value_get(svcname, name);
+   xasprintf(, "argv_%d", x);
+   str = rc_service_value_get(svcname, varbuf);
child_argv[x] = str;
+   free(varbuf);
+   varbuf = NULL;
}
free(str);
str = rc_service_value_get(svcname, "child_pid");
@@ -792,32 +797,31 @@ int main(int argc, char **argv)
if (*exec == '/' || *exec == '.') {
/* Full or relative path */
if (ch_root)
-   snprintf(exec_file, sizeof(exec_file),
-   "%s/%s", ch_root, exec);
+   xasprintf(_file, "%s/%s", ch_root, 
exec);
else
-   snprintf(exec_file, sizeof(exec_file),
-   "%s", exec);
+   xasprintf(_file, "%s", exec);
} else {
/* Something in $PATH */
p = tmp = xstrdup(getenv("PATH"));
-   *exec_file = '\0';
+   exec_file = NULL;
while ((token = strsep(, ":"))) {
if (ch_root)
-   snprintf(exec_file, 
sizeof(exec_file),
-   "%s/%s/%s",
-   ch_root, token, exec);
+

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

2018-02-21 Thread William Hubbs
commit: 5868abe97babcc287794dcb36ad8e77989b6ddcf
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 22 00:16:56 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 22 00:16:56 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=5868abe9

start-stop-daemon: compiler warning cleanup

 src/rc/start-stop-daemon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 88b1e091..1b565829 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -616,7 +616,8 @@ int main(int argc, char **argv)
fp = fopen(exec_file, "r");
if (fp) {
line = NULL;
-   getline(, , fp);
+   if (getline(, , fp) == -1)
+   eerrorx("%s: %s", applet, strerror(errno));
p = line;
fclose(fp);
if (p != NULL && line[0] == '#' && line[1] == '!') {



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

2018-02-21 Thread William Hubbs
commit: a6cc7f06cf3807a0e0590697e1f14e6ab9055271
Author: William Hubbs  gmail  com>
AuthorDate: Wed Feb 21 19:49:41 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Feb 21 19:49:41 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a6cc7f06

rc.c: remove PATH_MAX references

 src/rc/rc.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/rc/rc.c b/src/rc/rc.c
index 110591e4..1f462c66 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -336,26 +336,26 @@ set_krunlevel(const char *level)
return true;
 }
 
-static size_t
-get_krunlevel(char *buffer, int buffer_len)
+static char *get_krunlevel(void)
 {
+   char *buffer = NULL;
FILE *fp;
size_t i = 0;
 
if (!exists(RC_KRUNLEVEL))
-   return 0;
+   return NULL;
if (!(fp = fopen(RC_KRUNLEVEL, "r"))) {
eerror("fopen `%s': %s", RC_KRUNLEVEL, strerror(errno));
-   return 0;
+   return NULL;
}
 
-   if (fgets(buffer, buffer_len, fp)) {
+   if (getline(, , fp) != -1) {
i = strlen(buffer);
if (buffer[i - 1] == '\n')
buffer[i - 1] = 0;
}
fclose(fp);
-   return i;
+   return buffer;
 }
 
 static void
@@ -743,7 +743,7 @@ int main(int argc, char **argv)
RC_STRING *service;
bool going_down = false;
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
-   char krunlevel [PATH_MAX];
+   char *krunlevel = NULL;
char pidstr[10];
int opt;
bool parallel;
@@ -892,7 +892,8 @@ int main(int argc, char **argv)
(strcmp(newlevel, RC_LEVEL_SYSINIT) != 0 &&
strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0))
{
-   if (get_krunlevel(krunlevel, sizeof(krunlevel))) {
+   krunlevel = get_krunlevel();
+   if (krunlevel) {
newlevel = krunlevel;
set_krunlevel(NULL);
}



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

2018-02-20 Thread William Hubbs
commit: 3c031ca9780c555817fe9ccb8b23ceb231129724
Author: William Hubbs  gmail  com>
AuthorDate: Tue Feb 20 22:01:15 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Feb 20 22:01:15 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3c031ca9

rc-plubin.c: remove references to PATH_MAX

 src/rc/rc-plugin.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/rc/rc-plugin.c b/src/rc/rc-plugin.c
index e4650b1d..31ccd341 100644
--- a/src/rc/rc-plugin.c
+++ b/src/rc/rc-plugin.c
@@ -68,7 +68,7 @@ rc_plugin_load(void)
DIR *dp;
struct dirent *d;
PLUGIN *plugin;
-   char file[PATH_MAX];
+   char *file = NULL;
void *h;
int (*fptr)(RC_HOOK, const char *);
 
@@ -85,8 +85,9 @@ rc_plugin_load(void)
if (d->d_name[0] == '.')
continue;
 
-   snprintf(file, sizeof(file), RC_PLUGINDIR "/%s",  d->d_name);
+   xasprintf(, RC_PLUGINDIR "/%s",  d->d_name);
h = dlopen(file, RTLD_LAZY);
+   free(file);
if (h == NULL) {
eerror("dlopen: %s", dlerror());
continue;



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

2018-02-20 Thread William Hubbs
commit: 8e02406d8fbf92167c30431987d5de8de72cd7df
Author: William Hubbs  gmail  com>
AuthorDate: Tue Feb 20 20:22:29 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Feb 20 20:22:29 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8e02406d

rc-misc.c: remove references to PATH_MAX

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

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index 21c06fc5..2c9903c3 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -131,7 +131,8 @@ env_config(void)
char *npp;
char *tok;
const char *sys = rc_sys();
-   char buffer[PATH_MAX];
+   char *buffer = NULL;
+   size_t size = 0;
 
/* Ensure our PATH is prefixed with the system locations first
   for a little extra security */
@@ -170,8 +171,7 @@ env_config(void)
free(e);
 
if ((fp = fopen(RC_KRUNLEVEL, "r"))) {
-   memset(buffer, 0, sizeof (buffer));
-   if (fgets(buffer, sizeof (buffer), fp)) {
+   if (getline(, , fp) != -1) {
l = strlen (buffer) - 1;
if (buffer[l] == '\n')
buffer[l] = 0;
@@ -181,6 +181,7 @@ env_config(void)
} else
setenv("RC_DEFAULTLEVEL", RC_LEVEL_DEFAULT, 1);
 
+   free(buffer);
if (sys)
setenv("RC_SYS", sys, 1);
 
@@ -232,11 +233,12 @@ signal_setup_restart(int sig, void (*handler)(int))
 int
 svc_lock(const char *applet)
 {
-   char file[PATH_MAX];
+   char *file = NULL;
int fd;
 
-   snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s", applet);
+   xasprintf(, RC_SVCDIR "/exclusive/%s", applet);
fd = open(file, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
+   free(file);
if (fd == -1)
return -1;
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
@@ -250,11 +252,12 @@ svc_lock(const char *applet)
 int
 svc_unlock(const char *applet, int fd)
 {
-   char file[PATH_MAX];
+   char *file = NULL;
 
-   snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s", applet);
+   xasprintf(, RC_SVCDIR "/exclusive/%s", applet);
close(fd);
unlink(file);
+   free(file);
return -1;
 }
 
@@ -358,7 +361,7 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen)
int serrno = errno;
int merrno;
time_t t;
-   char file[PATH_MAX];
+   char *file = NULL;
struct stat st;
struct utimbuf ut;
FILE *fp;



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

2018-02-20 Thread William Hubbs
commit: c1178c8eebb92c9f3702e981cd4af9ef41f51884
Author: William Hubbs  gmail  com>
AuthorDate: Tue Feb 20 22:35:50 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Feb 20 22:35:50 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c1178c8e

rc-selinux.c: remove references to path_max

 src/rc/rc-selinux.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/rc/rc-selinux.c b/src/rc/rc-selinux.c
index bfaf1556..2c9673cc 100644
--- a/src/rc/rc-selinux.c
+++ b/src/rc/rc-selinux.c
@@ -256,19 +256,19 @@ static int read_context_file(const char *filename, char 
**context)
 {
int ret = -1;
FILE *fp;
-   char filepath[PATH_MAX];
+   char *filepath = NULL;
char *line = NULL;
char *p;
char *p2;
size_t len = 0;
ssize_t read;
 
-   memset(filepath, '\0', PATH_MAX);
-   snprintf(filepath, PATH_MAX - 1, "%s/%s", selinux_contexts_path(), 
filename);
+   xasprintf(, "%s/%s", selinux_contexts_path(), filename);
 
fp = fopen(filepath, "r");
if (fp == NULL) {
eerror("Failed to open context file: %s", filename);
+   free(filepath);
return -1;
}
 
@@ -294,6 +294,7 @@ static int read_context_file(const char *filename, char 
**context)
}
 
free(line);
+   free(filepath);
fclose(fp);
return ret;
 }



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

2018-02-16 Thread William Hubbs
commit: 8dbdabcc5e0df8ac36722a4ba7bfe30664cc9919
Author: William Hubbs  gmail  com>
AuthorDate: Fri Feb 16 20:04:40 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Feb 16 20:04:40 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8dbdabcc

start-stop-daemon: clean up string handling

 src/rc/start-stop-daemon.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 54b89b2a..88b1e091 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -254,6 +254,7 @@ int main(int argc, char **argv)
 #endif
 
int opt;
+   size_t size = 0;
bool start = false;
bool stop = false;
bool oknodo = false;
@@ -287,10 +288,10 @@ int main(int argc, char **argv)
char *tmp, *newpath, *np;
char *p;
char *token;
-   char exec_file[PATH_MAX];
+   char *exec_file = NULL;
struct passwd *pw;
struct group *gr;
-   char line[130];
+   char *line = NULL;
FILE *fp;
size_t len;
mode_t numask = 022;
@@ -577,26 +578,22 @@ int main(int argc, char **argv)
if (*exec == '/' || *exec == '.') {
/* Full or relative path */
if (ch_root)
-   snprintf(exec_file, sizeof(exec_file),
-   "%s/%s", ch_root, exec);
+   xasprintf(_file, "%s/%s", ch_root, exec);
else
-   snprintf(exec_file, sizeof(exec_file),
-   "%s", exec);
+   xasprintf(_file, "%s", exec);
} else {
/* Something in $PATH */
p = tmp = xstrdup(getenv("PATH"));
-   *exec_file = '\0';
+   exec_file = NULL;
while ((token = strsep(, ":"))) {
if (ch_root)
-   snprintf(exec_file, sizeof(exec_file),
-   "%s/%s/%s",
-   ch_root, token, exec);
+   xasprintf(_file, "%s/%s/%s", 
ch_root, token, exec);
else
-   snprintf(exec_file, sizeof(exec_file),
-   "%s/%s", token, exec);
-   if (exists(exec_file))
+   xasprintf(_file, "%s/%s", token, 
exec);
+   if (exec_file && exists(exec_file))
break;
-   *exec_file = '\0';
+   free(exec_file);
+   exec_file = NULL;
}
free(tmp);
}
@@ -604,6 +601,7 @@ int main(int argc, char **argv)
if (start && !exists(exec_file)) {
eerror("%s: %s does not exist", applet,
*exec_file ? exec_file : exec);
+   free(exec_file);
exit(EXIT_FAILURE);
 
}
@@ -617,7 +615,9 @@ int main(int argc, char **argv)
if (interpreted && !pidfile) {
fp = fopen(exec_file, "r");
if (fp) {
-   p = fgets(line, sizeof(line), fp);
+   line = NULL;
+   getline(, , fp);
+   p = line;
fclose(fp);
if (p != NULL && line[0] == '#' && line[1] == '!') {
p = line + 2;
@@ -629,7 +629,8 @@ int main(int argc, char **argv)
if (p[len] == '\n')
p[len] = '\0';
token = strsep(, " ");
-   strncpy(exec_file, token, sizeof(exec_file));
+   free(exec_file);
+   xasprintf(_file, "%s", token);
opt = 0;
for (nav = argv; *nav; nav++)
opt++;



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

2018-02-16 Thread William Hubbs
commit: 9e14b35da8942bd8fa552363617c3415887f485f
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 15 18:23:39 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 15 18:23:39 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=9e14b35d

rc-update: remove reference to PATH_MAX

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

diff --git a/src/rc/rc-update.c b/src/rc/rc-update.c
index 9bc1fe5b..abe40b88 100644
--- a/src/rc/rc-update.c
+++ b/src/rc/rc-update.c
@@ -166,7 +166,7 @@ show(RC_STRINGLIST *runlevels, bool verbose)
RC_STRING *runlevel;
RC_STRINGLIST *in;
bool inone;
-   char buffer[PATH_MAX];
+   char *buffer = NULL;
size_t l;
 
rc_stringlist_sort();
@@ -182,9 +182,11 @@ show(RC_STRINGLIST *runlevels, bool verbose)
inone = true;
} else {
l = strlen(runlevel->value);
+   buffer = xmalloc(l+1);
memset (buffer, ' ', l);
buffer[l] = 0;
rc_stringlist_add (in, buffer);
+   free(buffer);
}
}
 



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

2018-02-16 Thread William Hubbs
commit: 488d8989c518d9256f183899aac02024c679b93e
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 15 21:10:24 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Feb 15 21:26:40 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=488d8989

openrc-run: clean up string handling

- remove references to PATH_MAX
- use xasprintf to create strings

 src/rc/openrc-run.c | 61 -
 1 file changed, 37 insertions(+), 24 deletions(-)

diff --git a/src/rc/openrc-run.c b/src/rc/openrc-run.c
index bb79f42f..7e8d2e50 100644
--- a/src/rc/openrc-run.c
+++ b/src/rc/openrc-run.c
@@ -109,7 +109,7 @@ static void
 handle_signal(int sig)
 {
int serrno = errno;
-   char signame[10] = { '\0' };
+   char *signame = NULL;
struct winsize ws;
 
switch (sig) {
@@ -134,20 +134,22 @@ handle_signal(int sig)
break;
 
case SIGINT:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGINT");
+   if (!signame)
+   xasprintf(, "SIGINT");
/* FALLTHROUGH */
case SIGTERM:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGTERM");
+   if (!signame)
+   xasprintf(, "SIGTERM");
/* FALLTHROUGH */
case SIGQUIT:
-   if (!signame[0])
-   snprintf(signame, sizeof(signame), "SIGQUIT");
+   if (!signame)
+   xasprintf(, "SIGQUIT");
/* Send the signal to our children too */
if (service_pid > 0)
kill(service_pid, sig);
-   eerrorx("%s: caught %s, aborting", applet, signame);
+   eerror("%s: caught %s, aborting", applet, signame);
+   free(signame);
+   exit(EXIT_FAILURE);
/* NOTREACHED */
 
default:
@@ -161,11 +163,12 @@ handle_signal(int sig)
 static void
 unhotplug()
 {
-   char file[PATH_MAX];
+   char *file = NULL;
 
-   snprintf(file, sizeof(file), RC_SVCDIR "/hotplugged/%s", applet);
+   xasprintf(, RC_SVCDIR "/hotplugged/%s", applet);
if (exists(file) && unlink(file) != 0)
eerror("%s: unlink `%s': %s", applet, file, strerror(errno));
+   free(file);
 }
 
 static void
@@ -485,7 +488,7 @@ svc_exec(const char *arg1, const char *arg2)
 static bool
 svc_wait(const char *svc)
 {
-   char file[PATH_MAX];
+   char *file = NULL;
int fd;
bool forever = false;
RC_STRINGLIST *keywords;
@@ -498,8 +501,7 @@ svc_wait(const char *svc)
forever = true;
rc_stringlist_free(keywords);
 
-   snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s",
-   basename_c(svc));
+   xasprintf(, RC_SVCDIR "/exclusive/%s", basename_c(svc));
 
interval.tv_sec = 0;
interval.tv_nsec = WAIT_INTERVAL;
@@ -512,23 +514,29 @@ svc_wait(const char *svc)
if (fd != -1) {
if (flock(fd, LOCK_SH | LOCK_NB) == 0) {
close(fd);
+   free(file);
return true;
}
close(fd);
}
-   if (errno == ENOENT)
+   if (errno == ENOENT) {
+   free(file);
return true;
-   if (errno != EWOULDBLOCK)
-   eerrorx("%s: open `%s': %s", applet, file,
+   }
+   if (errno != EWOULDBLOCK) {
+   eerror("%s: open `%s': %s", applet, file,
strerror(errno));
+   free(file);
+   exit(EXIT_FAILURE);
+   }
if (nanosleep(, NULL) == -1) {
if (errno != EINTR)
-   return false;
+   goto finish;
}
if (!forever) {
timespecsub(, , );
if (timeout.tv_sec <= 0)
-   return false;
+   goto finish;
timespecsub(, , );
if (warn.tv_sec <= 0) {
ewarn("%s: waiting for %s (%d seconds)",
@@ -538,6 +546,8 @@ svc_wait(const char *svc)
}
}
}
+finish:
+   free(file);
return false;
 }
 
@@ -1105,9 +1115,10 @@ int main(int argc, char **argv)
bool runscript = false;
int retval, opt, depoptions = RC_DEP_TRACE;
RC_STRING *svc;
-   char path[PATH_MAX], lnk[PATH_MAX];
+   char *path = NULL;
+   char *lnk = NULL;
char *dir, *save = NULL, *saveLnk = NULL;
-   char pidstr[10];
+  

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

2018-02-14 Thread William Hubbs
commit: 7b4879cb72e907414b70553663bd9b6fda8d4408
Author: William Hubbs  gmail  com>
AuthorDate: Wed Feb 14 22:56:19 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Feb 14 22:56:19 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7b4879cb

mountinfo: create strings with xasprintf

 src/rc/mountinfo.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/rc/mountinfo.c b/src/rc/mountinfo.c
index d9c25a38..5bf97386 100644
--- a/src/rc/mountinfo.c
+++ b/src/rc/mountinfo.c
@@ -248,7 +248,6 @@ find_mounts(struct args *args)
struct opt *o;
int netdev;
char *tmp;
-   size_t l;
 
if ((nmnts = getmntinfo(, MNT_NOWAIT)) == 0)
eerrorx("getmntinfo: %s", strerror (errno));
@@ -264,11 +263,7 @@ find_mounts(struct args *args)
if (! options)
options = xstrdup(o->o_name);
else {
-   l = strlen(options) +
-   strlen(o->o_name) + 2;
-   tmp = xmalloc(sizeof (char) * l);
-   snprintf(tmp, l, "%s,%s", options,
-   o->o_name);
+   xasprintf(, "%s,%s", options, 
o->o_name);
free(options);
options = tmp;
}
@@ -315,6 +310,7 @@ find_mounts(struct args *args)
 {
FILE *fp;
char *buffer;
+   size_t size;
char *p;
char *from;
char *to;
@@ -329,8 +325,8 @@ find_mounts(struct args *args)
 
list = rc_stringlist_new();
 
-   buffer = xmalloc(sizeof(char) * PATH_MAX * 3);
-   while (fgets(buffer, PATH_MAX * 3, fp)) {
+   buffer = NULL;
+   while (getline(, , fp) != -1) {
netdev = -1;
p = buffer;
from = strsep(, " ");
@@ -346,6 +342,8 @@ find_mounts(struct args *args)
}
 
process_mount(list, args, from, to, fst, opts, netdev);
+   free(buffer);
+   buffer = NULL;
}
free(buffer);
fclose(fp);
@@ -380,7 +378,7 @@ int main(int argc, char **argv)
regex_t *skip_point_regex = NULL;
RC_STRINGLIST *nodes;
RC_STRING *s;
-   char real_path[PATH_MAX + 1];
+   char *real_path = NULL;
int opt;
int result;
char *this_path;
@@ -450,9 +448,12 @@ int main(int argc, char **argv)
eerrorx("%s: `%s' is not a mount point",
argv[0], argv[optind]);
this_path = argv[optind++];
-   if (realpath(this_path, real_path))
+   real_path = realpath(this_path, NULL);
+   if (real_path)
this_path = real_path;
rc_stringlist_add(args.mounts, this_path);
+   free(real_path);
+   real_path = NULL;
}
nodes = find_mounts();
rc_stringlist_free(args.mounts);



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

2018-02-14 Thread William Hubbs
commit: 74cfb455c59298f86849541e724ae346ff205c3d
Author: William Hubbs  gmail  com>
AuthorDate: Wed Feb 14 22:50:24 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Feb 14 22:50:24 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=74cfb455

kill_all: create strings with xasprintf

 src/rc/kill_all.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c
index f3500227..d6ce354b 100644
--- a/src/rc/kill_all.c
+++ b/src/rc/kill_all.c
@@ -87,10 +87,11 @@ static int mount_proc(void)
 
 static bool is_user_process(pid_t pid)
 {
-   char buf[PATH_MAX+1];
+   char *buf = NULL;
FILE *fp;
-   char path[PATH_MAX+1];
+   char *path = NULL;
pid_t temp_pid;
+   size_t size;
bool user_process = true;
 
while (pid >0 && user_process) {
@@ -98,8 +99,9 @@ static bool is_user_process(pid_t pid)
user_process = false;
continue;
}
-   snprintf(path, sizeof(path), "/proc/%d/status", pid);
+   xasprintf(, "/proc/%d/status", pid);
fp = fopen(path, "r");
+   free(path);
/*
 * if we could not open the file, the process disappeared, which
 * leaves us no way to determine for sure whether it was a user
@@ -112,11 +114,14 @@ static bool is_user_process(pid_t pid)
}
temp_pid = -1;
while (! feof(fp)) {
-   buf[0] = 0;
-   if (fgets(buf, sizeof(buf), fp))
+   buf = NULL;
+   if (getline(, , fp) != -1) {
sscanf(buf, "PPid: %d", _pid);
-   else
+   free(buf);
+   } else {
+   free(buf);
break;
+   }
}
fclose(fp);
if (temp_pid == -1) {
@@ -135,7 +140,7 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, 
bool dryrun)
sigset_t oldsigs;
DIR *dir;
struct dirent   *d;
-   char buf[PATH_MAX+1];
+   char *buf = NULL;
pid_t pid;
int sendcount = 0;
 
@@ -170,7 +175,11 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, 
bool dryrun)
continue;
 
/* Is this a process we have been requested to omit? */
-   sprintf(buf, "%d", pid);
+   if (buf) {
+   free(buf);
+   buf = NULL;
+   }
+   xasprintf(, "%d", pid);
if (rc_stringlist_find(omits, buf))
continue;
 



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

2018-01-24 Thread William Hubbs
commit: 5dd1d39d20c118064d31ed65dc7ae2de75dd7908
Author: William Hubbs  gmail  com>
AuthorDate: Wed Jan 24 16:56:33 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jan 24 16:56:33 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=5dd1d39d

typo fix

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

diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c
index 2e2b4ee3..07e5f78a 100644
--- a/src/rc/checkpath.c
+++ b/src/rc/checkpath.c
@@ -205,7 +205,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, 
mode_t mode,
if (selinux_on)
selinux_util_label(path);
} else {
-   eerror(fstat: %s: %s", path, strerror(errno));
+   eerror("fstat: %s: %s", path, strerror(errno));
close(readfd);
return -1;
}



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

2018-01-23 Thread William Hubbs
commit: 1771bc2a83fe65bfe6ec3e93ea7632609e697a38
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jan 23 22:56:06 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 23 22:56:06 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1771bc2a

checkpath: use fchown and fchmod to handle ownership and mode changes

This is related to #195.

This is an attempt to shorten the window for the first two issues
discussed by using a file descriptor which does not follow symbolic
links and using the fchmod and fchown calls instead of chown and chmod.
with.

 src/rc/checkpath.c | 124 ++---
 1 file changed, 79 insertions(+), 45 deletions(-)

diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c
index 39e7ce4d..2e2b4ee3 100644
--- a/src/rc/checkpath.c
+++ b/src/rc/checkpath.c
@@ -73,25 +73,32 @@ static int do_check(char *path, uid_t uid, gid_t gid, 
mode_t mode,
inode_t type, bool trunc, bool chowner, bool selinux_on)
 {
struct stat st;
-   int fd, flags;
+   int fd;
+   int flags;
int r;
+   int readfd;
+   int readflags;
int u;
 
memset(, 0, sizeof(st));
-   if (lstat(path, ) || trunc) {
-   if (type == inode_file) {
-   einfo("%s: creating file", path);
-   if (!mode) /* 664 */
-   mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | 
S_IROTH;
-   flags = O_CREAT|O_NDELAY|O_WRONLY|O_NOCTTY;
+   flags = O_CREAT|O_NDELAY|O_WRONLY|O_NOCTTY;
+   readflags = O_NDELAY|O_NOCTTY|O_RDONLY;
 #ifdef O_CLOEXEC
-   flags |= O_CLOEXEC;
+   flags |= O_CLOEXEC;
+   readflags |= O_CLOEXEC;
 #endif
 #ifdef O_NOFOLLOW
-   flags |= O_NOFOLLOW;
+   flags |= O_NOFOLLOW;
+   readflags |= O_NOFOLLOW;
 #endif
-   if (trunc)
-   flags |= O_TRUNC;
+   if (trunc)
+   flags |= O_TRUNC;
+   readfd = open(path, readflags);
+   if (readfd == -1 || (type == inode_file && trunc)) {
+   if (type == inode_file) {
+   einfo("%s: creating file", path);
+   if (!mode) /* 664 */
+   mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | 
S_IROTH;
u = umask(0);
fd = open(path, flags, mode);
umask(u);
@@ -99,7 +106,9 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t 
mode,
eerror("%s: open: %s", applet, strerror(errno));
return -1;
}
-   close (fd);
+   if (readfd != -1 && trunc)
+   close(readfd);
+   readfd = fd;
} else if (type == inode_dir) {
einfo("%s: creating directory", path);
if (!mode) /* 775 */
@@ -113,7 +122,12 @@ static int do_check(char *path, uid_t uid, gid_t gid, 
mode_t mode,
strerror (errno));
return -1;
}
-   mode = 0;
+   readfd = open(path, readflags);
+   if (readfd == -1) {
+   eerror("%s: unable to open directory: %s", 
applet,
+   strerror(errno));
+   return -1;
+   }
} else if (type == inode_fifo) {
einfo("%s: creating fifo", path);
if (!mode) /* 600 */
@@ -126,56 +140,76 @@ static int do_check(char *path, uid_t uid, gid_t gid, 
mode_t mode,
strerror (errno));
return -1;
}
+   readfd = open(path, readflags);
+   if (readfd == -1) {
+   eerror("%s: unable to open fifo: %s", applet,
+   strerror(errno));
+   return -1;
+   }
}
-   } else {
+   }
+   if (fstat(readfd, ) != -1) {
if (type != inode_dir && S_ISDIR(st.st_mode)) {
eerror("%s: is a directory", path);
+   close(readfd);
return 1;
}
if (type != inode_file && S_ISREG(st.st_mode)) {
eerror("%s: is a file", path);
+   close(readfd);
return 1;
}
if (type != inode_fifo && S_ISFIFO(st.st_mode)) {
eerror("%s: is a fifo", path);
+   close(readfd);
   

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

2018-01-16 Thread William Hubbs
commit: 87c98ebb01873120eecc1757e615b3a4c14a2f1f
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jan 16 19:34:37 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 16 19:34:37 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=87c98ebb

checkpath: fix lchown error message

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

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

diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c
index 8846761b..39e7ce4d 100644
--- a/src/rc/checkpath.c
+++ b/src/rc/checkpath.c
@@ -169,7 +169,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, 
mode_t mode,
}
einfo("%s: correcting owner", path);
if (lchown(path, uid, gid)) {
-   eerror("%s: chown: %s", applet, strerror(errno));
+   eerror("%s: lchown: %s", applet, strerror(errno));
return -1;
}
}



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

2018-01-16 Thread William Hubbs
commit: 4af5a80b0c516773286cc30e743dc90a2d19df23
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jan 16 19:11:22 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 16 19:11:22 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4af5a80b

_rc_deptree_load - return NULL if the stat() call is not successful

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

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

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index 33a17b35..21c06fc5 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -380,7 +380,10 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen)
eend (retval, "Failed to update the dependency tree");
 
if (retval == 0) {
-   stat(RC_DEPTREE_CACHE, );
+   if (stat(RC_DEPTREE_CACHE, ) != 0) {
+   eerror("stat(%s): %s", RC_DEPTREE_CACHE, 
strerror(errno));
+   return NULL;
+   }
if (st.st_mtime < t) {
eerror("Clock skew detected with `%s'", file);
eerrorn("Adjusting mtime of `" RC_DEPTREE_CACHE



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

2018-01-09 Thread William Hubbs
commit: 918d955fd2de1f594b83508f5ddd5271534e3591
Author: William Hubbs  gmail  com>
AuthorDate: Tue Jan  9 23:20:39 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan  9 23:25:28 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=918d955f

checkpath: use lchown instead of chown

Checkpath should never follow symbolic links when changing ownership of a file.

This is for https://github.com/openrc/openrc/issues/195.

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

diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c
index b1509940..8846761b 100644
--- a/src/rc/checkpath.c
+++ b/src/rc/checkpath.c
@@ -168,7 +168,7 @@ static int do_check(char *path, uid_t uid, gid_t gid, 
mode_t mode,
return -1;
}
einfo("%s: correcting owner", path);
-   if (chown(path, uid, gid)) {
+   if (lchown(path, uid, gid)) {
eerror("%s: chown: %s", applet, strerror(errno));
return -1;
}



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

2017-12-04 Thread William Hubbs
commit: a2447dfb420cbd97a65cc085404c031d42cb3dfb
Author: William Hubbs  gmail  com>
AuthorDate: Mon Dec  4 23:17:17 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Dec  4 23:17:17 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a2447dfb

rc-service: add --ifcrashed option

This works like the other --if options. If the service is crashed, run
the command.

This fixes #154.

 man/rc-service.8|  4 
 src/rc/rc-service.c | 10 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/man/rc-service.8 b/man/rc-service.8
index 80deb5eb..8f075de4 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -16,6 +16,10 @@
 .Nd locate and run an OpenRC service with the given arguments
 .Sh SYNOPSIS
 .Nm
+.Op Fl c , -ifcrashed
+.Ar service cmd
+.Op Ar ...
+.Nm
 .Op Fl i , -ifexists
 .Ar service cmd
 .Op Ar ...

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index d0a64999..8e7b00dc 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -29,9 +29,10 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "e:ilr:IN" getoptstring_COMMON;
+const char *getoptstring = "ce:ilr:IN" getoptstring_COMMON;
 const struct option longopts[] = {
{ "exists",   1, NULL, 'e' },
+   { "ifcrashed", 0, NULL, 'c' },
{ "ifexists", 0, NULL, 'i' },
{ "ifinactive", 0, NULL, 'I' },
{ "ifnotstarted", 0, NULL, 'N' },
@@ -41,6 +42,7 @@ const struct option longopts[] = {
 };
 const char * const longopts_help[] = {
"tests if the service exists or not",
+   "if the service is crashed then run the command",
"if the service exists then run the command",
"if the service is inactive then run the command",
"if the service is not started then run the command",
@@ -61,6 +63,7 @@ int main(int argc, char **argv)
RC_STRINGLIST *list;
RC_STRING *s;
RC_SERVICE state;
+   bool if_crashed = false;
bool if_exists = false;
bool if_inactive = false;
bool if_notstarted = false;
@@ -79,6 +82,9 @@ int main(int argc, char **argv)
free(service);
return opt;
/* NOTREACHED */
+   case 'c':
+   if_crashed = true;
+   break;
case 'i':
if_exists = true;
break;
@@ -121,6 +127,8 @@ int main(int argc, char **argv)
eerrorx("%s: service `%s' does not exist", applet, *argv);
}
state = rc_service_state(*argv);
+   if (if_crashed &&  ! (rc_service_daemons_crashed(*argv) && errno != 
EACCES))
+   return 0;
if (if_inactive && ! (state & RC_SERVICE_INACTIVE))
return 0;
if (if_notstarted && (state & RC_SERVICE_STARTED))



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

2017-11-29 Thread William Hubbs
commit: c84ebb94d19ca856fe064e15d2068d5671e360c9
Author: Doug Freed  mtu  edu>
AuthorDate: Wed Nov 29 20:10:39 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Nov 29 20:10:39 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c84ebb94

start-stop-daemon: properly handle missing pidfile

X-Gentoo-Bug: 639218
X-Gentoo-Bug-URL: https://bugs.gentoo.org/639218

 src/rc/start-stop-daemon.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index e98f8ba3..54b89b2a 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -657,8 +657,15 @@ int main(int argc, char **argv)
parse_schedule(applet, "0", sig);
else
parse_schedule(applet, NULL, sig);
+   if (pidfile) {
+   pid = get_pid(applet, pidfile);
+   if (pid == -1)
+   exit(EXIT_FAILURE);
+   } else {
+   pid = 0;
+   }
i = run_stop_schedule(applet, exec, (const char *const *)margv,
-   get_pid(applet, pidfile), uid, test, progress, false);
+   pid, uid, test, progress, false);
 
if (i < 0)
/* We failed to stop something */



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

2017-11-28 Thread William Hubbs
commit: a192caf88f527e09508e32baa623ef85549612ae
Author: Doug Freed  mtu  edu>
AuthorDate: Sun Nov 19 16:05:30 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Nov 19 16:05:30 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a192caf8

rc-schedules: if given nothing to look for, stop

This avoids trying to kill everything.

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

 src/rc/rc-schedules.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index d60c2822..8f36f073 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -307,6 +307,9 @@ int run_stop_schedule(const char *applet,
const char *const *p;
bool progressed = false;
 
+   if (!(pid > 0 || exec || uid || (argv && *argv)))
+   return 0;
+
if (exec)
einfov("Will stop %s", exec);
if (pid > 0)



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

2017-11-28 Thread William Hubbs
commit: 6bb7ebec483a96e258c64ea3fea18358d7893fee
Author: William Hubbs  gmail  com>
AuthorDate: Mon Nov 27 17:09:43 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Nov 27 17:10:00 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6bb7ebec

fix FreeBSD build

This is for #186.

 src/rc/supervise-daemon.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index f3f51ff0..06d0bdb3 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -159,7 +159,7 @@ static void cleanup(void)
free(changeuser);
 }
 
-static void re_exec(void)
+static void re_exec_supervisor(void)
 {
syslog(LOG_WARNING, "Re-executing for %s", svcname);
execlp("supervise-daemon", "supervise-daemon", svcname, "--reexec",
@@ -180,7 +180,7 @@ static void handle_signal(int sig)
/* Restore errno */
errno = serrno;
if (! exiting)
-   re_exec();
+   re_exec_supervisor();
 }
 
 static char * expand_home(const char *home, const char *path)
@@ -435,7 +435,9 @@ static void supervisor(char *exec, char **argv)
signal_setup_restart(SIGUSR1, handle_signal);
signal_setup_restart(SIGUSR2, handle_signal);
signal_setup_restart(SIGBUS, handle_signal);
+#ifdef SIGPOLL
signal_setup_restart(SIGPOLL, handle_signal);
+#endif
signal_setup_restart(SIGPROF, handle_signal);
signal_setup_restart(SIGSYS, handle_signal);
signal_setup_restart(SIGTRAP, handle_signal);
@@ -446,7 +448,9 @@ static void supervisor(char *exec, char **argv)
signal_setup_restart(SIGEMT, handle_signal);
 #endif
signal_setup_restart(SIGIO, handle_signal);
+#ifdef SIGPWR
signal_setup_restart(SIGPWR, handle_signal);
+#endif
 #ifdef SIGUNUSED
signal_setup_restart(SIGUNUSED, handle_signal);
 #endif



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

2017-11-07 Thread William Hubbs
commit: a3d1c8a0e7d5586be13e2cd9b5029fd729bc1594
Author: William Hubbs  gmail  com>
AuthorDate: Mon Oct 30 23:21:39 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Oct 30 23:21:39 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a3d1c8a0

fix issue with --reexec call

 src/rc/supervise-daemon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 3989cbc7..f3f51ff0 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -162,7 +162,8 @@ static void cleanup(void)
 static void re_exec(void)
 {
syslog(LOG_WARNING, "Re-executing for %s", svcname);
-   execlp("supervise-daemon", "supervise-daemon", "--reexec", (char *) 
NULL);
+   execlp("supervise-daemon", "supervise-daemon", svcname, "--reexec",
+   (char *) NULL);
syslog(LOG_ERR, "Unable to execute supervise-daemon: %s",
strerror(errno));
exit(EXIT_FAILURE);



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

2017-11-07 Thread William Hubbs
commit: 90d9ea656ff7c6b5d618df4e4261ebfa4033f1a8
Author: William Hubbs  gmail  com>
AuthorDate: Tue Nov  7 21:30:21 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Nov  7 21:30:34 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=90d9ea65

start-stop-daemon: do not use do_stop to verify whether a daemon is running

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

 src/rc/start-stop-daemon.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index dab8b3b1..e98f8ba3 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -279,6 +279,7 @@ int main(int argc, char **argv)
int stdout_fd;
int stderr_fd;
pid_t pid, spid;
+   RC_PIDLIST *pids;
int i;
char *svcname = getenv("RC_SVCNAME");
RC_STRINGLIST *env_list;
@@ -683,10 +684,14 @@ int main(int argc, char **argv)
else
pid = 0;
 
-   if (do_stop(applet, exec, (const char * const *)margv, pid, uid,
-   0, test, false) > 0)
+   if (pid)
+   pids = rc_find_pids(NULL, NULL, 0, pid);
+   else
+   pids = rc_find_pids(exec, (const char * const *) argv, uid, 0);
+   if (pids)
eerrorx("%s: %s is already running", applet, exec);
 
+   free(pids);
if (test) {
if (rc_yesno(getenv("EINFO_QUIET")))
exit (EXIT_SUCCESS);



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

2017-11-07 Thread William Hubbs
commit: 27b8183de2f2bfd7411c14c1ec28543ca8a36602
Author: William Hubbs  gmail  com>
AuthorDate: Fri Oct 27 20:32:26 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Oct 27 20:33:47 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=27b8183d

log as supervise-daemon not the service

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 3c3d7c7e..bf27ad18 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -561,7 +561,7 @@ int main(int argc, char **argv)
applet = basename_c(argv[0]);
atexit(cleanup);
svcname = getenv("RC_SVCNAME");
-   openlog(svcname, LOG_PID, LOG_DAEMON);
+   openlog(applet, LOG_PID, LOG_DAEMON);
 
if ((tmp = getenv("SSD_NICELEVEL")))
if (sscanf(tmp, "%d", ) != 1)



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

2017-11-07 Thread William Hubbs
commit: 3fe99c8b8264269dd935d52a1a52581cc0f14e8e
Author: William Hubbs  gmail  com>
AuthorDate: Fri Oct 27 22:34:29 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Oct 27 22:34:29 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3fe99c8b

supervise-daemon: fix logging for reexec and the child command line

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index bf27ad18..1d0c3407 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -161,7 +161,7 @@ static void cleanup(void)
 
 static void re_exec(void)
 {
-   syslog(LOG_WARNING, "Re-executing supervise-daemon");
+   syslog(LOG_WARNING, "Re-executing for %s", svcname);
execlp("supervise-daemon", "supervise-daemon", "--reexec", (char *) 
NULL);
syslog(LOG_ERR, "Unable to execute supervise-daemon: %s",
strerror(errno));
@@ -402,7 +402,7 @@ static void child_process(char *exec, char **argv)
strcat(cmdline, " ");
c++;
}
-   syslog(LOG_INFO, "Running command line: %s", cmdline);
+   syslog(LOG_INFO, "Child command line: %s", cmdline);
execvp(exec, argv);
 
 #ifdef HAVE_PAM



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

2017-10-26 Thread William Hubbs
commit: f32d8e1bfe16caf233d1180921f4aeed77d7476d
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 19:15:40 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 22:01:17 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f32d8e1b

supervise-daemon: clarify a log message

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index abb4a59e..3c3d7c7e 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -826,7 +826,7 @@ int main(int argc, char **argv)
parse_schedule(applet, NULL, sig);
 
einfov("Detaching to start `%s'", exec);
-   syslog(LOG_INFO, "Running command line: %s", cmdline);
+   syslog(LOG_INFO, "Supervisor command line: %s", cmdline);
 
/* Remove existing pidfile */
if (pidfile)



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

2017-10-26 Thread William Hubbs
commit: 667a09983ca5311824aa88c42d39a495c540fc4c
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 17:58:59 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 17:58:59 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=667a0998

supervise-daemon: remove child_pid from saved options during shutdown

This allows us to detect when the supervisor dies unexpectedly because
in that case child_pid will still exist.

 src/rc/supervise-daemon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 998a01bc..b232e215 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -523,6 +523,7 @@ static void supervisor(char *exec, char **argv)
rc_service_daemon_set(svcname, exec, (const char *const *)argv,
pidfile, false);
rc_service_mark(svcname, RC_SERVICE_STOPPED);
+   rc_service_value_set(svcname, "child_pid", NULL);
}
exit(EXIT_SUCCESS);
 }



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

2017-10-26 Thread William Hubbs
commit: d019f34a83b0ad5e890f685b1263b281ab54ce54
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 18:57:04 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 18:57:04 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d019f34a

supervise-daemon: log the command line we run to spawn the child process

 src/rc/supervise-daemon.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 6c3c55bf..abb4a59e 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -556,6 +556,7 @@ int main(int argc, char **argv)
int child_argc = 0;
char **child_argv = NULL;
char *str = NULL;
+   char cmdline[PATH_MAX];
 
applet = basename_c(argv[0]);
atexit(cleanup);
@@ -721,6 +722,13 @@ int main(int argc, char **argv)
if (!pidfile && !reexec)
eerrorx("%s: --pidfile must be specified", applet);
 
+   *cmdline = '\0';
+   c = argv;
+   while (c && *c) {
+   strcat(cmdline, *c);
+   strcat(cmdline, " ");
+   c++;
+   }
endpwent();
argc -= optind;
argv += optind;
@@ -818,6 +826,7 @@ int main(int argc, char **argv)
parse_schedule(applet, NULL, sig);
 
einfov("Detaching to start `%s'", exec);
+   syslog(LOG_INFO, "Running command line: %s", cmdline);
 
/* Remove existing pidfile */
if (pidfile)



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

2017-10-26 Thread William Hubbs
commit: bb9c481f02cb1843e00bf32e98caf18b6b56bb4d
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 18:36:41 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 18:36:41 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=bb9c481f

supervise-daemon: log with the service name instead of "supervise-daemon"

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index b232e215..6c3c55bf 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -420,7 +420,6 @@ static void supervisor(char *exec, char **argv)
time_t respawn_now= 0;
time_t first_spawn= 0;
 
-   openlog(applet, LOG_PID, LOG_DAEMON);
 #ifndef RC_DEBUG
signal_setup_restart(SIGHUP, handle_signal);
signal_setup_restart(SIGINT, handle_signal);
@@ -561,6 +560,7 @@ int main(int argc, char **argv)
applet = basename_c(argv[0]);
atexit(cleanup);
svcname = getenv("RC_SVCNAME");
+   openlog(svcname, LOG_PID, LOG_DAEMON);
 
if ((tmp = getenv("SSD_NICELEVEL")))
if (sscanf(tmp, "%d", ) != 1)



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

2017-10-25 Thread William Hubbs
commit: 3219ecd6085231d7cc1268323a5be6a69f8c9143
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct 24 21:47:53 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct 24 21:47:53 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3219ecd6

supervise-daemon: fix build issue for >=glibc-2.26

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

 src/rc/supervise-daemon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index df59eb67..998a01bc 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -447,7 +447,9 @@ static void supervisor(char *exec, char **argv)
 #endif
signal_setup_restart(SIGIO, handle_signal);
signal_setup_restart(SIGPWR, handle_signal);
+#ifdef SIGUNUSED
signal_setup_restart(SIGUNUSED, handle_signal);
+#endif
 #ifdef SIGRTMIN
for (i = SIGRTMIN; i <= SIGRTMAX; i++)
signal_setup_restart(i, handle_signal);



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

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

supervise-daemon: multiple fixes

- Harden against dying by handling all signals that would terminate the
program and adding --reexec support
- factor the supervisor into its own function
- fix test for whether we are already running

 src/includes/rc-misc.h|   1 +
 src/rc/rc-misc.c  |  12 +
 src/rc/supervise-daemon.c | 570 +++---
 3 files changed, 343 insertions(+), 240 deletions(-)

diff --git a/src/includes/rc-misc.h b/src/includes/rc-misc.h
index 9a55c413..e6789911 100644
--- a/src/includes/rc-misc.h
+++ b/src/includes/rc-misc.h
@@ -47,6 +47,7 @@ bool rc_conf_yesno(const char *var);
 void env_filter(void);
 void env_config(void);
 int signal_setup(int sig, void (*handler)(int));
+int signal_setup_restart(int sig, void (*handler)(int));
 int svc_lock(const char *);
 int svc_unlock(const char *, int);
 pid_t exec_service(const char *, const char *);

diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index d43f1274..33a17b35 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -218,6 +218,18 @@ signal_setup(int sig, void (*handler)(int))
 }
 
 int
+signal_setup_restart(int sig, void (*handler)(int))
+{
+   struct sigaction sa;
+
+   memset(, 0, sizeof (sa));
+   sigemptyset(_mask);
+   sa.sa_handler = handler;
+   sa.sa_flags = SA_RESTART;
+   return sigaction(sig, , NULL);
+}
+
+int
 svc_lock(const char *applet)
 {
char file[PATH_MAX];

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index f1e8ea16..df59eb67 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -67,7 +67,7 @@ static struct pam_conv conv = { NULL, NULL};
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "D:d:e:g:I:Kk:m:N:p:R:r:Su:1:2:" \
+const char *getoptstring = "D:d:e:g:I:Kk:m:N:p:R:r:Su:1:2:3" \
getoptstring_COMMON;
 const struct option longopts[] = {
{ "respawn-delay",1, NULL, 'D'},
@@ -87,6 +87,7 @@ const struct option longopts[] = {
{ "user", 1, NULL, 'u'},
{ "stdout",   1, NULL, '1'},
{ "stderr",   1, NULL, '2'},
+   { "reexec",   0, NULL, '3'},
longopts_COMMON
 };
 const char * const longopts_help[] = {
@@ -107,6 +108,7 @@ const char * const longopts_help[] = {
"Change the process user",
"Redirect stdout to file",
"Redirect stderr to file",
+   "reexec (used internally)",
longopts_help_COMMON
 };
 const char *usagestring = NULL;
@@ -127,6 +129,13 @@ static bool exiting = false;
 #ifdef TIOCNOTTY
 static int tty_fd = -1;
 #endif
+static pid_t child_pid;
+static int respawn_count = 0;
+static int respawn_delay = 0;
+static int respawn_max = 10;
+static int respawn_period = 5;
+static char *pidfile = NULL;
+static char *svcname = NULL;
 
 extern char **environ;
 
@@ -150,8 +159,71 @@ static void cleanup(void)
free(changeuser);
 }
 
-static void child_process(char *exec, char **argv, char *svcname,
-   int start_count)
+static void re_exec(void)
+{
+   syslog(LOG_WARNING, "Re-executing supervise-daemon");
+   execlp("supervise-daemon", "supervise-daemon", "--reexec", (char *) 
NULL);
+   syslog(LOG_ERR, "Unable to execute supervise-daemon: %s",
+   strerror(errno));
+   exit(EXIT_FAILURE);
+}
+
+static void handle_signal(int sig)
+{
+   int serrno = errno;
+
+   syslog(LOG_WARNING, "caught signal %d", sig);
+
+   if (sig == SIGTERM)
+   exiting = true;
+   /* Restore errno */
+   errno = serrno;
+   if (! exiting)
+   re_exec();
+}
+
+static char * expand_home(const char *home, const char *path)
+{
+   char *opath, *ppath, *p, *nh;
+   size_t len;
+   struct passwd *pw;
+
+   if (!path || *path != '~')
+   return xstrdup(path);
+
+   opath = ppath = xstrdup(path);
+   if (ppath[1] != '/' && ppath[1] != '\0') {
+   p = strchr(ppath + 1, '/');
+   if (p)
+   *p = '\0';
+   pw = getpwnam(ppath + 1);
+   if (pw) {
+   home = pw->pw_dir;
+   ppath = p;
+   if (ppath)
+   *ppath = '/';
+   } else
+   home = NULL;
+   } else
+   ppath++;
+
+   if (!home) {
+   free(opath);
+   return xstrdup(path);
+   }
+   if (!ppath) {
+   free(opath);
+   return xstrdup(home);
+   }
+
+   len = strlen(ppath) + strlen(home) + 1;
+   nh = xmalloc(len);
+   snprintf(nh, len, "%s%s", home, 

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

2017-10-18 Thread William Hubbs
commit: 35b1996704f6635bb29ea3604410e133209e6432
Author: William Hubbs  gmail  com>
AuthorDate: Wed Oct 18 23:07:50 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Oct 18 23:07:50 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=35b19967

supervise-daemon: elevate some log messages to warnings

Prior to this change, we were logging unexpected terminations of daemons
we were supervising at the info level. This change moves the logs to
warnings.

 src/rc/supervise-daemon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index a781ad9d..f1e8ea16 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -771,17 +771,17 @@ int main(int argc, char **argv)
} else
respawn_count++;
if (respawn_count >= respawn_max) {
-   syslog(LOG_INFO, "respawned 
\"%s\" too many times, "
+   syslog(LOG_WARNING, "respawned 
\"%s\" too many times, "
"exiting", 
exec);
exiting = true;
continue;
}
}
if (WIFEXITED(i))
-   syslog(LOG_INFO, "%s, pid %d, exited 
with return code %d",
+   syslog(LOG_WARNING, "%s, pid %d, exited 
with return code %d",
exec, child_pid, 
WEXITSTATUS(i));
else if (WIFSIGNALED(i))
-   syslog(LOG_INFO, "%s, pid %d, 
terminated by signal %d",
+   syslog(LOG_WARNING, "%s, pid %d, 
terminated by signal %d",
exec, child_pid, 
WTERMSIG(i));
child_pid = fork();
if (child_pid == -1)



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

2017-10-05 Thread William Hubbs
commit: 1e9af2cd421423404ffe1491bd35af76c2885f1f
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct  5 23:31:07 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct  5 23:31:07 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1e9af2cd

fix compiler warning

 src/rc/rc-schedules.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 9568e51d..d60c2822 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -408,11 +408,12 @@ int run_stop_schedule(const char *applet,
 
if (progressed)
printf("\n");
-   if (! quiet)
+   if (! quiet) {
if (nrunning == 1)
eerror("%s: %d process refused to stop", applet, 
nrunning);
else
eerror("%s: %d process(es) refused to stop", applet, 
nrunning);
+   }
 
return -nrunning;
 }



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

2017-10-02 Thread William Hubbs
commit: 3c05db74f6e733890e9035c183a774db3d512512
Author: William Hubbs  gmail  com>
AuthorDate: Mon Oct  2 23:09:03 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Oct  2 23:09:09 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3c05db74

remove service binary

The service binary was just a synonym for rc-service, so use rc-service
instead of service. If you want a "service" binary, it should be
something that can determine which service manager you are running and
run the appropriate service manager commands.

 guide.md| 3 ---
 src/rc/Makefile | 4 ++--
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/guide.md b/guide.md
index e7e8f4b4..f8c23194 100644
--- a/guide.md
+++ b/guide.md
@@ -53,9 +53,6 @@ Calling `openrc` without any arguments will try to reset all 
services so
 that the current runlevel is satisfied; if you manually started apache it will 
be 
 stopped, and if squid died but is in the current runlevel it'll be restarted.
 
-There is a `service` helper that emulates the syntax seen on e.g. older Redhat
-and Ubuntu (`service nginx start` etc.)
-
 # Runlevels
 
 OpenRC has a concept of runlevels, similar to what sysvinit historically 

diff --git a/src/rc/Makefile b/src/rc/Makefile
index a2c7c306..cb90875c 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -24,7 +24,7 @@ SBINDIR=  ${PREFIX}/sbin
 LINKDIR=   ${LIBEXECDIR}
 
 BINPROGS=  rc-status
-SBINPROGS = openrc openrc-run rc rc-service rc-update runscript service \
+SBINPROGS = openrc openrc-run rc rc-service rc-update runscript \
start-stop-daemon supervise-daemon
 RC_BINPROGS=   einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \
eindent eoutdent esyslog eval_ecolors ewaitfile 
\
@@ -150,7 +150,7 @@ rc-depend: rc-depend.o _usage.o rc-misc.o
 rc-status: rc-status.o _usage.o rc-misc.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
-rc-service service: rc-service.o _usage.o rc-misc.o
+rc-service: rc-service.o _usage.o rc-misc.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 rc-update: rc-update.o _usage.o rc-misc.o



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

2017-09-22 Thread William Hubbs
commit: 1cac8b080c16f9aab19c7a3ae1ca155c20dfa14d
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 18 21:59:18 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 18 21:59:18 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1cac8b08

ignore sigchld when shutting down the supervised process

We need to do this to skip the zombie state for the child process since
we are not easily able to wait() for it.

 src/rc/supervise-daemon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 09db1912..a781ad9d 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -753,6 +753,7 @@ int main(int argc, char **argv)
while (!exiting) {
wait();
if (exiting) {
+   signal_setup(SIGCHLD, SIG_IGN);
syslog(LOG_INFO, "stopping %s, pid %d", exec, 
child_pid);
nkilled = run_stop_schedule(applet, exec, NULL, 
child_pid,
0, false, false, true);



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

2017-09-18 Thread William Hubbs
commit: b58194ef63ec8c0a7e0ea3c291da9c19aa83cb1a
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 18 18:30:56 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 18 18:30:56 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b58194ef

typo fix

 src/rc/supervise-daemon.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 3d39906e..09db1912 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -670,6 +670,7 @@ int main(int argc, char **argv)
ts.tv_sec = 0;
ts.tv_nsec = 1;
nanosleep(, NULL);
+   }
}
 
/* Even if we have not actually killed anything, we should



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

2017-09-18 Thread William Hubbs
commit: 3cf19b0f30a90157d23d09ded304439f1eb42d4a
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 18 17:25:37 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 18 17:25:37 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3cf19b0f

supervise-daemon: code cleanup

Clean up the process for killing an active supervisor when stopping.

 src/rc/supervise-daemon.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 7b894e7b..2800d1a2 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -432,6 +432,7 @@ int main(int argc, char **argv)
int respawn_period = 5;
time_t respawn_now= 0;
time_t first_spawn= 0;
+   struct timespec ts;
struct passwd *pw;
struct group *gr;
FILE *fp;
@@ -658,17 +659,18 @@ int main(int argc, char **argv)
 
if (stop) {
pid = get_pid(applet, pidfile);
-   if (pid == -1)
-   i = pid;
-   else
+   if (pid != -1) {
i = kill(pid, SIGTERM);
-   if (i != 0)
-   /* We failed to send the signal */
-   exit(EXIT_FAILURE);
-
-   /* wait for the supervisor to go down */
-   while (kill(pid, 0) == 0)
-   sleep(1);
+   if (i != 0)
+   /* We failed to send the signal */
+   exit(EXIT_FAILURE);
+
+   /* wait for the supervisor to go down */
+   while (kill(pid, 0) == 0)
+   ts.tv_sec = 0;
+   ts.tv_nsec = 1;
+   nanosleep(, NULL);
+   }
 
/* Even if we have not actually killed anything, we should
 * remove information about it as it may have unexpectedly



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

2017-09-18 Thread William Hubbs
commit: b1c3422f453921e838d419640fe39144dbf8d13d
Author: Jason Zaman  perfinion  com>
AuthorDate: Sun Sep 17 13:15:13 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Sep 17 16:40:07 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b1c3422f

selinux: use openrc contexts path to get contexts

The minimum requirement for libselinux is now >=2.6
The refpolicy and the gentoo policy contain the
contexts since version 2.20170204-r4

 src/rc/rc-selinux.c | 23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/rc/rc-selinux.c b/src/rc/rc-selinux.c
index 2eb631a6..514ca5e5 100644
--- a/src/rc/rc-selinux.c
+++ b/src/rc/rc-selinux.c
@@ -39,7 +39,6 @@
 #include "rc-selinux.h"
 
 /* the context files for selinux */
-#define RUN_INIT_FILE "run_init_type"
 #define INITRC_FILE "initrc_context"
 
 #ifdef HAVE_AUDIT
@@ -299,6 +298,26 @@ static int read_context_file(const char *filename, char 
**context)
return ret;
 }
 
+static int read_run_init_context(char **context)
+{
+   int ret = -1;
+   RC_STRINGLIST *list;
+   char *value = NULL;
+
+   list = rc_config_list(selinux_openrc_contexts_path());
+   if (list == NULL)
+   return ret;
+
+   value = rc_config_value(list, "run_init");
+   if (value != NULL && strlen(value) > 0) {
+   *context = xstrdup(value);
+   ret = 0;
+   }
+
+   rc_stringlist_free(list);
+   return ret;
+}
+
 void selinux_setup(char **argv)
 {
char *new_context = NULL;
@@ -312,7 +331,7 @@ void selinux_setup(char **argv)
return;
}
 
-   if (read_context_file(RUN_INIT_FILE, _init_t) != 0) {
+   if (read_run_init_context(_init_t) != 0) {
/* assume a reasonable default, rather than bailing out */
run_init_t = xstrdup("run_init_t");
ewarn("Assuming SELinux run_init type is %s", run_init_t);



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

2017-09-18 Thread William Hubbs
commit: 0eb47b9af340dd07209a3920944ed085fe7bd359
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 18 15:36:17 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 18 15:36:17 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0eb47b9a

initialize the stop schedule

 src/rc/rc-schedules.c | 6 +-
 src/rc/rc-schedules.h | 1 -
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 164581d6..9568e51d 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -56,11 +56,6 @@ typedef struct scheduleitem {
 
 static TAILQ_HEAD(, scheduleitem) schedule;
 
-void initialize_schedulelist(void)
-{
-   TAILQ_INIT();
-}
-
 void free_schedulelist(void)
 {
SCHEDULEITEM *s1 = TAILQ_FIRST();
@@ -186,6 +181,7 @@ void parse_schedule(const char *applet, const char *string, 
int timeout)
size_t len;
SCHEDULEITEM *item;
 
+   TAILQ_INIT();
if (string)
for (slash = string; *slash; slash++)
if (*slash == '/')

diff --git a/src/rc/rc-schedules.h b/src/rc/rc-schedules.h
index 234e62df..e5dd64c2 100644
--- a/src/rc/rc-schedules.h
+++ b/src/rc/rc-schedules.h
@@ -13,7 +13,6 @@
 #ifndef __RC_SCHEDULES_H
 #define __RC_SCHEDULES_H
 
-void initialize_schedulelist(void);
 void free_schedulelist(void);
 int parse_signal(const char *applet, const char *sig);
 void parse_schedule(const char *applet, const char *string, int timeout);



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

2017-09-18 Thread William Hubbs
commit: b28c0d6f66e42b1e6d2a39c286a18c8d92881790
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 18 18:03:34 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 18 18:03:34 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b28c0d6f

typo fix

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

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 2800d1a2..3d39906e 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -666,7 +666,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
 
/* wait for the supervisor to go down */
-   while (kill(pid, 0) == 0)
+   while (kill(pid, 0) == 0) {
ts.tv_sec = 0;
ts.tv_nsec = 1;
nanosleep(, NULL);



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

2017-09-18 Thread William Hubbs
commit: db4a578273dbfa15b8b96686391bcc9ecc04b646
Author: Jason Zaman  perfinion  com>
AuthorDate: Sun Sep 17 15:52:52 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Sep 17 16:41:24 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=db4a5782

selinux: fix const qualifier warning

rc-selinux.c: In function ‘selinux_setup’:
rc-selinux.c:361:9: warning: assignment discards ‘const’ qualifier from pointer 
target type [-Wdiscarded-qualifiers]
  curr_t = context_type_get(curr_con);
 ^

 src/rc/rc-selinux.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/rc/rc-selinux.c b/src/rc/rc-selinux.c
index 514ca5e5..bfaf1556 100644
--- a/src/rc/rc-selinux.c
+++ b/src/rc/rc-selinux.c
@@ -358,14 +358,13 @@ void selinux_setup(char **argv)
goto out;
}
 
-   curr_t = context_type_get(curr_con);
+   curr_t = xstrdup(context_type_get(curr_con));
if (!curr_t) {
context_free(curr_con);
free(curr_context);
goto out;
}
 
-   curr_t = xstrdup(curr_t);
/* dont need them anymore so free() now */
context_free(curr_con);
free(curr_context);



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

2017-09-18 Thread William Hubbs
commit: 4ab60ff10935122277bbaed437f82a765279cd19
Author: William Hubbs  gmail  com>
AuthorDate: Sun Sep 17 19:20:05 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Sep 17 19:20:05 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4ab60ff1

rc-schedules.c: pass the correct pid to rc_find_pids

This is for #163.

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

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 13f615ee..164581d6 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -261,10 +261,10 @@ int do_stop(const char *applet, const char *exec, const 
char *const *argv,
bool killed;
int nkilled = 0;
 
-   if (pid)
+   if (pid > 0)
pids = rc_find_pids(NULL, NULL, 0, pid);
else
-   pids = rc_find_pids(exec, argv, uid, pid);
+   pids = rc_find_pids(exec, argv, uid, 0);
 
if (!pids)
return 0;



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

2017-09-15 Thread William Hubbs
commit: b0a077a35f85e266fdb82a245dcbda18664a8567
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 14 23:24:31 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 14 23:24:39 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b0a077a3

add quiet switch to do_stop in src-schedules.c

This allows supervise-daemon to run this code without attempting to
print some status messages used by start-stop-daemon.

 src/rc/rc-schedules.c  | 13 -
 src/rc/rc-schedules.h  |  2 +-
 src/rc/start-stop-daemon.c |  4 ++--
 src/rc/supervise-daemon.c  |  7 ++-
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 1b235a8d..13f615ee 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -253,7 +253,7 @@ void parse_schedule(const char *applet, const char *string, 
int timeout)
 
 /* return number of processes killed, -1 on error */
 int do_stop(const char *applet, const char *exec, const char *const *argv,
-pid_t pid, uid_t uid,int sig, bool test)
+pid_t pid, uid_t uid,int sig, bool test, bool quiet)
 {
RC_PIDLIST *pids;
RC_PID *pi;
@@ -274,11 +274,13 @@ int do_stop(const char *applet, const char *exec, const 
char *const *argv,
einfo("Would send signal %d to PID %d", sig, pi->pid);
nkilled++;
} else {
-   ebeginv("Sending signal %d to PID %d", sig, pi->pid);
+   if (!quiet)
+   ebeginv("Sending signal %d to PID %d", sig, 
pi->pid);
errno = 0;
killed = (kill(pi->pid, sig) == 0 ||
errno == ESRCH ? true : false);
-   eendv(killed ? 0 : 1,
+   if (! quiet)
+   eendv(killed ? 0 : 1,
"%s: failed to send signal %d to PID %d: %s",
applet, sig, pi->pid, strerror(errno));
if (!killed) {
@@ -335,7 +337,8 @@ int run_stop_schedule(const char *applet,
 
case SC_SIGNAL:
nrunning = 0;
-   nkilled = do_stop(applet, exec, argv, pid, uid, 
item->value, test);
+   nkilled = do_stop(applet, exec, argv, pid, uid, 
item->value, test,
+   quiet);
if (nkilled == 0) {
if (tkilled == 0) {
if (progressed)
@@ -364,7 +367,7 @@ int run_stop_schedule(const char *applet,
 nloops++)
{
if ((nrunning = do_stop(applet, exec, 
argv,
-   pid, uid, 0, test)) == 0)
+   pid, uid, 0, test, quiet)) 
== 0)
return 0;
 
 

diff --git a/src/rc/rc-schedules.h b/src/rc/rc-schedules.h
index a42ea0e3..234e62df 100644
--- a/src/rc/rc-schedules.h
+++ b/src/rc/rc-schedules.h
@@ -18,7 +18,7 @@ void free_schedulelist(void);
 int parse_signal(const char *applet, const char *sig);
 void parse_schedule(const char *applet, const char *string, int timeout);
 int do_stop(const char *applet, const char *exec, const char *const *argv,
-   pid_t pid, uid_t uid,int sig, bool test);
+   pid_t pid, uid_t uid,int sig, bool test, bool quiet);
 int run_stop_schedule(const char *applet,
const char *exec, const char *const *argv,
pid_t pid, uid_t uid,

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 46784b26..dab8b3b1 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -684,7 +684,7 @@ int main(int argc, char **argv)
pid = 0;
 
if (do_stop(applet, exec, (const char * const *)margv, pid, uid,
-   0, test) > 0)
+   0, test, false) > 0)
eerrorx("%s: %s is already running", applet, exec);
 
if (test) {
@@ -964,7 +964,7 @@ int main(int argc, char **argv)
} else
pid = 0;
if (do_stop(applet, exec, (const char *const *)margv,
-   pid, uid, 0, test) > 0)
+   pid, uid, 0, test, false) > 0)
alive = true;
}
 

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index a702a25c..7b894e7b 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -440,11 +440,6 @@ int main(int argc, char **argv)
applet = basename_c(argv[0]);
atexit(cleanup);
 
-   signal_setup(SIGINT, handle_signal);
-   signal_setup(SIGQUIT, 

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

2017-09-06 Thread William Hubbs
commit: 382efdbfcb99703d03211efacd800c9575e64230
Author: William Hubbs  gmail  com>
AuthorDate: Wed Sep  6 21:43:28 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Sep  6 22:22:35 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=382efdbf

add quiet parameter to run_stop_schedule

 src/rc/rc-schedules.c  | 11 ++-
 src/rc/rc-schedules.h  |  2 +-
 src/rc/start-stop-daemon.c |  2 +-
 src/rc/supervise-daemon.c  |  2 +-
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 7eb28372..1b235a8d 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -298,7 +298,7 @@ int do_stop(const char *applet, const char *exec, const 
char *const *argv,
 int run_stop_schedule(const char *applet,
const char *exec, const char *const *argv,
pid_t pid, uid_t uid,
-bool test, bool progress)
+bool test, bool progress, bool quiet)
 {
SCHEDULEITEM *item = TAILQ_FIRST();
int nkilled = 0;
@@ -409,10 +409,11 @@ int run_stop_schedule(const char *applet,
 
if (progressed)
printf("\n");
-   if (nrunning == 1)
-   eerror("%s: %d process refused to stop", applet, nrunning);
-   else
-   eerror("%s: %d process(es) refused to stop", applet, nrunning);
+   if (! quiet)
+   if (nrunning == 1)
+   eerror("%s: %d process refused to stop", applet, 
nrunning);
+   else
+   eerror("%s: %d process(es) refused to stop", applet, 
nrunning);
 
return -nrunning;
 }

diff --git a/src/rc/rc-schedules.h b/src/rc/rc-schedules.h
index 0a10b381..a42ea0e3 100644
--- a/src/rc/rc-schedules.h
+++ b/src/rc/rc-schedules.h
@@ -22,6 +22,6 @@ int do_stop(const char *applet, const char *exec, const char 
*const *argv,
 int run_stop_schedule(const char *applet,
const char *exec, const char *const *argv,
pid_t pid, uid_t uid,
-   bool test, bool progress);
+   bool test, bool progress, bool quiet);
 
 #endif

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 4cda6102..46784b26 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -657,7 +657,7 @@ int main(int argc, char **argv)
else
parse_schedule(applet, NULL, sig);
i = run_stop_schedule(applet, exec, (const char *const *)margv,
-   get_pid(applet, pidfile), uid, test, progress);
+   get_pid(applet, pidfile), uid, test, progress, false);
 
if (i < 0)
/* We failed to stop something */

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 3923dab5..a702a25c 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -755,7 +755,7 @@ int main(int argc, char **argv)
if (exiting) {
syslog(LOG_INFO, "stopping %s, pid %d", exec, 
child_pid);
nkilled = run_stop_schedule(applet, exec, NULL, 
child_pid,
-   0, false, false);
+   0, false, false, true);
if (nkilled > 0)
syslog(LOG_INFO, "killed %d processes", 
nkilled);
} else {



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

2017-08-25 Thread William Hubbs
commit: 36a0ab9054512ade413226fb8e8b28060045e9a4
Author: William Hubbs  gmail  com>
AuthorDate: Fri Aug 25 16:36:45 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Aug 25 16:36:45 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=36a0ab90

make run_stop_schedule accept a pid instead of a pid file

 src/rc/rc-schedules.c  | 13 +++--
 src/rc/rc-schedules.h  |  2 +-
 src/rc/start-stop-daemon.c |  2 +-
 3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
index 0390ef9c..7eb28372 100644
--- a/src/rc/rc-schedules.c
+++ b/src/rc/rc-schedules.c
@@ -297,7 +297,7 @@ int do_stop(const char *applet, const char *exec, const 
char *const *argv,
 
 int run_stop_schedule(const char *applet,
const char *exec, const char *const *argv,
-   const char *pidfile, uid_t uid,
+   pid_t pid, uid_t uid,
 bool test, bool progress)
 {
SCHEDULEITEM *item = TAILQ_FIRST();
@@ -306,14 +306,13 @@ int run_stop_schedule(const char *applet,
int nrunning = 0;
long nloops, nsecs;
struct timespec ts;
-   pid_t pid = 0;
const char *const *p;
bool progressed = false;
 
if (exec)
einfov("Will stop %s", exec);
-   if (pidfile)
-   einfov("Will stop PID in pidfile `%s'", pidfile);
+   if (pid > 0)
+   einfov("Will stop PID %d", pid);
if (uid)
einfov("Will stop processes owned by UID %d", uid);
if (argv && *argv) {
@@ -328,12 +327,6 @@ int run_stop_schedule(const char *applet,
}
}
 
-   if (pidfile) {
-   pid = get_pid(applet, pidfile);
-   if (pid == -1)
-   return 0;
-   }
-
while (item) {
switch (item->type) {
case SC_GOTO:

diff --git a/src/rc/rc-schedules.h b/src/rc/rc-schedules.h
index 6bed7916..0a10b381 100644
--- a/src/rc/rc-schedules.h
+++ b/src/rc/rc-schedules.h
@@ -21,7 +21,7 @@ int do_stop(const char *applet, const char *exec, const char 
*const *argv,
pid_t pid, uid_t uid,int sig, bool test);
 int run_stop_schedule(const char *applet,
const char *exec, const char *const *argv,
-   const char *pidfile, uid_t uid,
+   pid_t pid, uid_t uid,
bool test, bool progress);
 
 #endif

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index df5b3184..4cda6102 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -657,7 +657,7 @@ int main(int argc, char **argv)
else
parse_schedule(applet, NULL, sig);
i = run_stop_schedule(applet, exec, (const char *const *)margv,
-   pidfile, uid, test, progress);
+   get_pid(applet, pidfile), uid, test, progress);
 
if (i < 0)
/* We failed to stop something */



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

2017-08-24 Thread William Hubbs
commit: d7938f54f29193251e083ad35a7d464949829096
Author: William Hubbs  gmail  com>
AuthorDate: Thu Aug 24 16:34:18 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Aug 24 16:34:18 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d7938f54

start-stop-daemon: move --retry processing code to a shared module

This was part of start-stop-daemon; however, it needs to be shared in
order to be used by supervise-daemon.

 src/rc/Makefile|   2 +-
 src/rc/rc-schedules.c  | 425 +
 src/rc/rc-schedules.h  |  27 +++
 src/rc/start-stop-daemon.c | 402 +-
 4 files changed, 461 insertions(+), 395 deletions(-)

diff --git a/src/rc/Makefile b/src/rc/Makefile
index 19adcafb..e6c9f4a2 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -156,7 +156,7 @@ rc-service service: rc-service.o _usage.o rc-misc.o
 rc-update: rc-update.o _usage.o rc-misc.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
-start-stop-daemon: start-stop-daemon.o _usage.o rc-misc.o
+start-stop-daemon: start-stop-daemon.o _usage.o rc-misc.o rc-schedules.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 supervise-daemon: supervise-daemon.o _usage.o rc-misc.o

diff --git a/src/rc/rc-schedules.c b/src/rc/rc-schedules.c
new file mode 100644
index ..0390ef9c
--- /dev/null
+++ b/src/rc/rc-schedules.c
@@ -0,0 +1,425 @@
+/*
+ * The functions in this file control the stopping of daemons by
+ * start-stop-daemon and supervise-daemon.
+ */
+
+/*
+ * Copyright (c) 2015 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.
+ */
+
+/* nano seconds */
+#define POLL_INTERVAL   2000
+#define WAIT_PIDFILE   5
+#define ONE_SECOND10
+#define ONE_MS   100
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "einfo.h"
+#include "queue.h"
+#include "rc.h"
+#include "rc-misc.h"
+#include "rc-schedules.h"
+#include "helpers.h"
+
+typedef struct scheduleitem {
+   enum {
+   SC_TIMEOUT,
+   SC_SIGNAL,
+   SC_GOTO,
+   SC_FOREVER,
+   } type;
+   int value;
+   struct scheduleitem *gotoitem;
+   TAILQ_ENTRY(scheduleitem) entries;
+} SCHEDULEITEM;
+
+static TAILQ_HEAD(, scheduleitem) schedule;
+
+void initialize_schedulelist(void)
+{
+   TAILQ_INIT();
+}
+
+void free_schedulelist(void)
+{
+   SCHEDULEITEM *s1 = TAILQ_FIRST();
+   SCHEDULEITEM *s2;
+
+   while (s1) {
+   s2 = TAILQ_NEXT(s1, entries);
+   free(s1);
+   s1 = s2;
+   }
+   TAILQ_INIT();
+}
+
+int parse_signal(const char *applet, const char *sig)
+{
+   typedef struct signalpair
+   {
+   const char *name;
+   int signal;
+   } SIGNALPAIR;
+
+#define signalpair_item(name) { #name, SIG##name },
+
+   static const SIGNALPAIR signallist[] = {
+   signalpair_item(HUP)
+   signalpair_item(INT)
+   signalpair_item(QUIT)
+   signalpair_item(ILL)
+   signalpair_item(TRAP)
+   signalpair_item(ABRT)
+   signalpair_item(BUS)
+   signalpair_item(FPE)
+   signalpair_item(KILL)
+   signalpair_item(USR1)
+   signalpair_item(SEGV)
+   signalpair_item(USR2)
+   signalpair_item(PIPE)
+   signalpair_item(ALRM)
+   signalpair_item(TERM)
+   signalpair_item(CHLD)
+   signalpair_item(CONT)
+   signalpair_item(STOP)
+   signalpair_item(TSTP)
+   signalpair_item(TTIN)
+   signalpair_item(TTOU)
+   signalpair_item(URG)
+   signalpair_item(XCPU)
+   signalpair_item(XFSZ)
+   signalpair_item(VTALRM)
+   signalpair_item(PROF)
+#ifdef SIGWINCH
+   signalpair_item(WINCH)
+#endif
+#ifdef SIGIO
+   signalpair_item(IO)
+#endif
+#ifdef SIGPWR
+   signalpair_item(PWR)
+#endif
+   signalpair_item(SYS)
+   { "NULL",   0 },
+   };
+
+   unsigned int i = 0;
+   const char *s;
+
+   if (!sig || *sig == '\0')
+   return -1;
+
+   if (sscanf(sig, "%u", ) == 1) {
+ 

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

2017-07-24 Thread William Hubbs
commit: 6d4e8433974fd8567885635ae0454031290f96b1
Author: Jason Graham  gmail  com>
AuthorDate: Mon Jul 24 23:22:46 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jul 24 23:24:18 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6d4e8433

fix ENT macro usage

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

 src/rc/fstabinfo.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/rc/fstabinfo.c b/src/rc/fstabinfo.c
index 75c8bc2b..a2e707aa 100644
--- a/src/rc/fstabinfo.c
+++ b/src/rc/fstabinfo.c
@@ -35,11 +35,11 @@
 #  define GET_ENT getmntent (fp)
 #  define GET_ENT_FILE(_name) getmntfile (_name)
 #  define END_ENT endmntent (fp)
-#  define ENT_BLOCKDEVICE(_ent) ent->mnt_fsname
-#  define ENT_FILE(_ent) ent->mnt_dir
-#  define ENT_TYPE(_ent) ent->mnt_type
-#  define ENT_OPTS(_ent) ent->mnt_opts
-#  define ENT_PASS(_ent) ent->mnt_passno
+#  define ENT_BLOCKDEVICE(_ent) (_ent)->mnt_fsname
+#  define ENT_FILE(_ent) (_ent)->mnt_dir
+#  define ENT_TYPE(_ent) (_ent)->mnt_type
+#  define ENT_OPTS(_ent) (_ent)->mnt_opts
+#  define ENT_PASS(_ent) (_ent)->mnt_passno
 #else
 #  define HAVE_GETFSENT
 #  include 
@@ -48,11 +48,11 @@
 #  define GET_ENT getfsent ()
 #  define GET_ENT_FILE(_name) getfsfile (_name)
 #  define END_ENT endfsent ()
-#  define ENT_BLOCKDEVICE(_ent) ent->fs_spec
-#  define ENT_TYPE(_ent) ent->fs_vfstype
-#  define ENT_FILE(_ent) ent->fs_file
-#  define ENT_OPTS(_ent) ent->fs_mntops
-#  define ENT_PASS(_ent) ent->fs_passno
+#  define ENT_BLOCKDEVICE(_ent) (_ent)->fs_spec
+#  define ENT_TYPE(_ent) (_ent)->fs_vfstype
+#  define ENT_FILE(_ent) (_ent)->fs_file
+#  define ENT_OPTS(_ent) (_ent)->fs_mntops
+#  define ENT_PASS(_ent) (_ent)->fs_passno
 #endif
 
 #include "einfo.h"
@@ -114,24 +114,24 @@ do_mount(struct ENT *ent, bool remount)
 
argv[0] = UNCONST("mount");
argv[1] = UNCONST("-o");
-   argv[2] = ENT_OPTS(*ent);
+   argv[2] = ENT_OPTS(ent);
argv[3] = UNCONST("-t");
-   argv[4] = ENT_TYPE(*ent);
+   argv[4] = ENT_TYPE(ent);
if (!remount) {
-   argv[5] = ENT_BLOCKDEVICE(*ent);
-   argv[6] = ENT_FILE(*ent);
+   argv[5] = ENT_BLOCKDEVICE(ent);
+   argv[6] = ENT_FILE(ent);
argv[7] = NULL;
} else {
 #ifdef __linux__
argv[5] = UNCONST("-o");
argv[6] = UNCONST("remount");
-   argv[7] = ENT_BLOCKDEVICE(*ent);
-   argv[8] = ENT_FILE(*ent);
+   argv[7] = ENT_BLOCKDEVICE(ent);
+   argv[8] = ENT_FILE(ent);
argv[9] = NULL;
 #else
argv[5] = UNCONST("-u");
-   argv[6] = ENT_BLOCKDEVICE(*ent);
-   argv[7] = ENT_FILE(*ent);
+   argv[6] = ENT_BLOCKDEVICE(ent);
+   argv[7] = ENT_FILE(ent);
argv[8] = NULL;
 #endif
}



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

2017-06-12 Thread William Hubbs
commit: 11243f85b67e5f450ddf50346ffd4a1b2c6faeb5
Author: Jory A. Pratt  gentoo  org>
AuthorDate: Thu Jun  8 14:14:10 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jun  8 15:04:19 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=11243f85

kill_all: include limits.h for PATH_MAX

 src/rc/kill_all.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/kill_all.c b/src/rc/kill_all.c
index a4b15c87..f3500227 100644
--- a/src/rc/kill_all.c
+++ b/src/rc/kill_all.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 



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

2017-06-12 Thread William Hubbs
commit: 560d874d2fee63bf7ca11f17cf9933021b639a1d
Author: William Hubbs  gmail  com>
AuthorDate: Thu Jun  8 13:43:42 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jun  8 13:43:42 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=560d874d

fix compile issue for musl

 src/rc/rc-wtmp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/rc/rc-wtmp.c b/src/rc/rc-wtmp.c
index 913fa06b..8d494303 100644
--- a/src/rc/rc-wtmp.c
+++ b/src/rc/rc-wtmp.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 



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

2017-06-07 Thread William Hubbs
commit: ee886c44824b1dd892eaff2c6da666286e61bc73
Author: William Hubbs  gmail  com>
AuthorDate: Mon Jun  5 20:49:22 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jun  5 20:49:22 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ee886c44

openrc-shutdown: add --single option and clean up option processing

 src/rc/openrc-shutdown.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/rc/openrc-shutdown.c b/src/rc/openrc-shutdown.c
index 4ba619c5..b17a63d8 100644
--- a/src/rc/openrc-shutdown.c
+++ b/src/rc/openrc-shutdown.c
@@ -37,7 +37,7 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "dDHKpRrw" getoptstring_COMMON;
+const char *getoptstring = "dDHKpRrsw" getoptstring_COMMON;
 const struct option longopts[] = {
{ "no-write",no_argument, NULL, 'd'},
{ "dry-run",no_argument, NULL, 'D'},
@@ -46,6 +46,7 @@ const struct option longopts[] = {
{ "poweroff",no_argument, NULL, 'p'},
{ "reexec",no_argument, NULL, 'R'},
{ "reboot",no_argument, NULL, 'r'},
+   { "single",no_argument, NULL, 's'},
{ "write-only",no_argument, NULL, 'w'},
longopts_COMMON
 };
@@ -57,12 +58,13 @@ const char * const longopts_help[] = {
"power off the system",
"re-execute init (use after upgrading)",
"reboot the system",
+   "single user mode",
"write wtmp boot record and exit",
longopts_help_COMMON
 };
 const char *usagestring = NULL;
 const char *exclusive = "Select one of "
-"--halt, --kexec, --poweroff, --reexec or --reboot";
+"--halt, --kexec, --poweroff, --reexec, --reboot, --single or --write-only";
 
 static bool do_dryrun = false;
 static bool do_halt = false;
@@ -70,6 +72,7 @@ static bool do_kexec = false;
 static bool do_poweroff = false;
 static bool do_reboot = false;
 static bool do_reexec = false;
+static bool do_single = false;
 static bool do_wtmp = true;
 static bool do_wtmp_only = false;
 
@@ -132,15 +135,20 @@ int main(int argc, char **argv)
do_reboot = true;
cmd_count++;
break;
+   case 's':
+   do_single = true;
+   cmd_count++;
+   break;
case 'w':
do_wtmp_only = true;
+   cmd_count++;
break;
case_RC_COMMON_GETOPT
}
}
if (geteuid() != 0 && ! do_dryrun)
eerrorx("%s: you must be root\n", applet);
-   if (cmd_count > 1) {
+   if (cmd_count != 1) {
eerror("%s: %s\n", applet, exclusive);
usage(EXIT_FAILURE);
}
@@ -156,7 +164,7 @@ int main(int argc, char **argv)
send_cmd("reexec");
else if (do_wtmp_only)
log_wtmp("shutdown", "~~", 0, RUN_LVL, "~~");
-   else
+   else if (do_single)
send_cmd("single");
return 0;
 }



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

2017-06-05 Thread William Hubbs
commit: 7689106aa10f7852b707b4c21ec080ccb2767280
Author: William Hubbs  gmail  com>
AuthorDate: Fri Jun  2 19:07:40 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jun  5 01:56:03 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7689106a

add support for writing reboot and shutdown records to wtmp

 src/includes/rc-wtmp.h   | 26 +
 src/rc/Makefile  |  6 ++---
 src/rc/openrc-init.c |  2 ++
 src/rc/openrc-shutdown.c | 61 +++-
 src/rc/rc-wtmp.c | 50 +++
 5 files changed, 121 insertions(+), 24 deletions(-)

diff --git a/src/includes/rc-wtmp.h b/src/includes/rc-wtmp.h
new file mode 100644
index ..6645774b
--- /dev/null
+++ b/src/includes/rc-wtmp.h
@@ -0,0 +1,26 @@
+/*
+ * rc-wtmp.h
+ * This is private to us and not for user consumption
+*/
+
+/*
+ * 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.
+ */
+
+#ifndef __RC_WTMP_H__
+#define __RC_WTMP_H__
+
+#include 
+
+void log_wtmp(const char *user, const char *id, pid_t pid, int type,
+   const char *line);
+
+#endif

diff --git a/src/rc/Makefile b/src/rc/Makefile
index 5874ed17..19adcafb 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -14,7 +14,7 @@ SRCS+=rc-selinux.c
 endif
 
 ifeq (${OS},Linux)
-SRCS+= kill_all.c openrc-init.c openrc-shutdown.c
+SRCS+= kill_all.c openrc-init.c openrc-shutdown.c rc-wtmp.c
 endif
 
 CLEANFILES=version.h rc-selinux.o
@@ -111,7 +111,7 @@ veinfo vewarn vebegin veend vewend veindent veoutdent: 
do_e.o rc-misc.o
 fstabinfo: fstabinfo.o _usage.o rc-misc.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
-openrc-init: openrc-init.o
+openrc-init: openrc-init.o rc-wtmp.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 is_newer_than: is_newer_than.o rc-misc.o
@@ -132,7 +132,7 @@ mountinfo: mountinfo.o _usage.o rc-misc.o
 openrc rc: rc.o rc-logger.o rc-misc.o rc-plugin.o _usage.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
-openrc-shutdown: openrc-shutdown.o _usage.o
+openrc-shutdown: openrc-shutdown.o _usage.o rc-wtmp.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ 
${LDADD}
 
 openrc-run runscript: openrc-run.o _usage.o rc-misc.o rc-plugin.o

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index 003ce31f..eb346f59 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -32,6 +32,7 @@
 
 #include "helpers.h"
 #include "rc.h"
+#include "rc-wtmp.h"
 #include "version.h"
 
 static const char *rc_default_runlevel = "default";
@@ -82,6 +83,7 @@ static void init(const char *default_runlevel)
}
pid = do_openrc(runlevel);
waitpid(pid, NULL, 0);
+   log_wtmp("reboot", "~~", 0, RUN_LVL, "~~");
 }
 
 static void handle_reexec(char *my_name)

diff --git a/src/rc/openrc-shutdown.c b/src/rc/openrc-shutdown.c
index ecb251a8..4ba619c5 100644
--- a/src/rc/openrc-shutdown.c
+++ b/src/rc/openrc-shutdown.c
@@ -27,46 +27,63 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "einfo.h"
 #include "rc.h"
 #include "helpers.h"
 #include "_usage.h"
+#include "rc-wtmp.h"
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "dHkpRr" getoptstring_COMMON;
+const char *getoptstring = "dDHKpRrw" getoptstring_COMMON;
 const struct option longopts[] = {
-   { "dry-run",no_argument, NULL, 'd'},
+   { "no-write",no_argument, NULL, 'd'},
+   { "dry-run",no_argument, NULL, 'D'},
{ "halt",no_argument, NULL, 'H'},
-   { "kexec",no_argument, NULL, 'k'},
+   { "kexec",no_argument, NULL, 'K'},
{ "poweroff",no_argument, NULL, 'p'},
{ "reexec",no_argument, NULL, 'R'},
{ "reboot",no_argument, NULL, 'r'},
+   { "write-only",no_argument, NULL, 'w'},
longopts_COMMON
 };
 const char * const longopts_help[] = {
+   "do not write wtmp record",
"print actions instead of executing them",
"halt the system",
"reboot the system using kexec",
"power off the system",
"re-execute init (use after upgrading)",
"reboot the system",
+   "write wtmp boot record and exit",
longopts_help_COMMON
 };
 const char *usagestring = NULL;
 const char *exclusive = 

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

2017-05-30 Thread William Hubbs
commit: 0ddee9b7d2b8dea810e252ca6a95c457876df120
Author: Sergei Trofimovich  gentoo  org>
AuthorDate: Tue May 30 20:58:32 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 30 21:21:23 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0ddee9b7

openrc-init: fix buffer overflow in init.ctl

How to reproduce 1-byte overflow:

```
$ FEATURES=-test CFLAGS="-fsanitize=address -O0 -ggdb3" emerge -1 openrc

=
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff0efd8710
at pc 0x00402076 bp 0x7fff0efd7d50 sp 0x7fff0efd7d40
WRITE of size 1 at 0x7fff0efd8710 thread T0
#0 0x402075  (/sbin/openrc-init+0x402075)
#1 0x3cf6e2070f in __libc_start_main (/lib64/libc.so.6+0x3cf6e2070f)
#2 0x4013b8  (/sbin/openrc-init+0x4013b8)

Address 0x7fff0efd8710 is located in stack of thread T0 at offset 2432 in frame
#0 0x401cfb  (/sbin/openrc-init+0x401cfb)

  This frame has 3 object(s):
[32, 160) 'signals'
[192, 344) 'sa'
[384, 2432) 'buf' <== Memory access at offset 2432 overflows this variable
HINT: this may be a false positive if your program uses some custom stack 
unwind mechanism or swapcontext
  (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow ??:0 ??
```

The problem here is in the code handling reads from 'init.ctl':

```
int main(int argc, char **argv) {
...
char buf[2048];
for (;;) {
/* This will block until a command is sent down the pipe... */
fifo = fopen(RC_INIT_FIFO, "r");
count = fread(buf, 1, 2048, fifo);
buf[count] = 0;
...
}
```

`buf[count] = 0;` writes outside the buffer when `fread()` returns 
non-truncated read.

This fixes #138.

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

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index 398259cc..003ce31f 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -195,7 +195,7 @@ int main(int argc, char **argv)
perror("fopen");
continue;
}
-   count = fread(buf, 1, 2048, fifo);
+   count = fread(buf, 1, sizeof(buf) - 1, fifo);
buf[count] = 0;
fclose(fifo);
printf("PID1: Received \"%s\" from FIFO...\n", buf);



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

2017-05-30 Thread William Hubbs
commit: 7185e242ffaa8cd1b672fe4726502a196fd779c2
Author: Sergei Trofimovich  inbox  ru>
AuthorDate: Tue May 30 07:47:55 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 30 07:47:55 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7185e242

rc-logger.c: fix crash on fclose(NULL) (#137)

Only close the log if we successfully opened it.

Reported-by: Brian Evans  gentoo.org>
Tested-by: Brian Evans  gentoo.org>
Signed-off-by: Sergei Trofimovich  gentoo.org>

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

diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index b4bd0eae..062ce3d9 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -261,12 +261,12 @@ rc_logger_open(const char *level)
break;
}
}
+   fclose(log);
} else {
log_error = 1;
eerror("Error: fopen(%s) failed: %s", TMPLOG, 
strerror(errno));
}
 
-   fclose(log);
fclose(plog);
} else {
/*



  1   2   >