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

2018-05-15 Thread William Hubbs
commit: 4d47ce440c3e8f193cff82a77e6691ee6e7fac33
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 15 21:59:21 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May 15 21:59:21 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4d47ce44

rc-service: add -d/--debug and -D/--nodeps options

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

diff --git a/man/rc-service.8 b/man/rc-service.8
index a0202a8e..3613f8b8 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -20,6 +20,14 @@
 .Ar service cmd
 .Op Ar ...
 .Nm
+.Fl d , -debug
+.Ar service cmd
+.Op Ar ...
+.Nm
+.Fl D , -nodeps
+.Ar service cmd
+.Op Ar ...
+.Nm
 .Op Fl i , -ifexists
 .Ar service cmd
 .Op Ar ...
@@ -72,6 +80,12 @@ otherwise -1.
 .Fl r , -resolve
 does the same and also prints the full path of the service to stdout.
 .Pp
+.Fl d , -debug
+sets -x when running the service script(s).
+.Pp
+.Fl D , -nodeps
+ignores dependencies when running the service.
+.Pp
 .Fl Z , -dry-run
 prints out the commands it would execute rather than executing them.
 .Sh SEE ALSO

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index 77f0336b..ea69dab5 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -29,8 +29,10 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "ce:ilr:INZ" getoptstring_COMMON;
+const char *getoptstring = "cdDe:ilr:INZ" getoptstring_COMMON;
 const struct option longopts[] = {
+   { "debug", 0, NULL, 'd' },
+   { "nodeps", 0, NULL, 'D' },
{ "exists",   1, NULL, 'e' },
{ "ifcrashed", 0, NULL, 'c' },
{ "ifexists", 0, NULL, 'i' },
@@ -42,6 +44,8 @@ const struct option longopts[] = {
longopts_COMMON
 };
 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",
@@ -78,6 +82,12 @@ int main(int argc, char **argv)
longopts, (int *) 0)) != -1)
{
switch (opt) {
+   case 'd':
+   setenv("RC_DEBUG", "yes", 1);
+   break;
+   case 'D':
+   setenv("RC_NODEPS", "yes", 1);
+   break;
case 'e':
service = rc_service_resolve(optarg);
opt = service ? EXIT_SUCCESS : EXIT_FAILURE;



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

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

rc-service: add a --dry-run option

This is for #225.

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

diff --git a/man/rc-service.8 b/man/rc-service.8
index 8f075de4..a0202a8e 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -35,6 +35,9 @@
 .Fl e , -exists
 .Ar service
 .Nm
+.Fl Z , -dry-run
+.Ar service
+.Nm
 .Fl l , -list
 .Nm
 .Fl r , -resolve
@@ -68,6 +71,9 @@ return 0 if it can find
 otherwise -1.
 .Fl r , -resolve
 does the same and also prints the full path of the service to stdout.
+.Pp
+.Fl Z , -dry-run
+prints out the commands it would execute rather than executing them.
 .Sh SEE ALSO
 .Xr openrc 8 ,
 .Xr stdout 3

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index 8e7b00dc..77f0336b 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 = "ce:ilr:IN" getoptstring_COMMON;
+const char *getoptstring = "ce:ilr:INZ" getoptstring_COMMON;
 const struct option longopts[] = {
{ "exists",   1, NULL, 'e' },
{ "ifcrashed", 0, NULL, 'c' },
@@ -38,6 +38,7 @@ const struct option longopts[] = {
{ "ifnotstarted", 0, NULL, 'N' },
{ "list", 0, NULL, 'l' },
{ "resolve",  1, NULL, 'r' },
+   { "dry-run", 0, NULL, 'Z' },
longopts_COMMON
 };
 const char * const longopts_help[] = {
@@ -48,6 +49,7 @@ const char * const longopts_help[] = {
"if the service is not started then run the command",
"list all available services",
"resolve the service name to an init script",
+   "dry run (show what would happen)",
longopts_help_COMMON
 };
 const char *usagestring = ""   
\
@@ -112,6 +114,9 @@ int main(int argc, char **argv)
free(service);
return EXIT_SUCCESS;
/* NOTREACHED */
+   case 'Z':
+   setenv("IN_DRYRUN", "yes", 1);
+   break;
 
case_RC_COMMON_GETOPT
}



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

2017-09-06 Thread William Hubbs
commit: 17b5cc78d35dc5fe4904e5951715c3e0d07d6343
Author: William Hubbs  gmail  com>
AuthorDate: Wed Sep  6 18:22:30 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Sep  6 22:22:21 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=17b5cc78

add retry option to supervise-daemon

The --retry option for supervise-daemon defines how the supervisor will
attempt to stop the child process it is monitoring. It is defined when
the supervisor is started since stopping the supervisor just sends a
signal to the active supervisor.

This fixes #160.

 man/supervise-daemon.8|  5 +
 sh/supervise-daemon.sh|  1 +
 src/rc/Makefile   |  2 +-
 src/rc/supervise-daemon.c | 26 +++---
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/man/supervise-daemon.8 b/man/supervise-daemon.8
index 34a4e936..0d34a249 100644
--- a/man/supervise-daemon.8
+++ b/man/supervise-daemon.8
@@ -36,6 +36,8 @@
 .Ar pidfile
 .Fl P , -respawn-period
 .Ar seconds
+.Fl R , -retry
+.Ar arg
 .Fl r , -chroot
 .Ar chrootpath
 .Fl u , -user
@@ -115,6 +117,9 @@ Modifies the scheduling priority of the daemon.
 .It Fl P , -respawn-period Ar seconds
 Sets the length of a respawn period. The default is 10 seconds. See the
 description of --respawn-max for more information.
+.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
+The retry specification can be either a timeout in seconds or multiple
+signal/timeout pairs (like SIGTERM/5).
 .It Fl r , -chroot Ar path
 chroot to this directory before starting the daemon. All other paths, such
 as the path to the daemon, chdir and pidfile, should be relative to the chroot.

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 8add2147..1c1b840d 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -23,6 +23,7 @@ supervise_start()
# command_args="this \"is a\" test"
# to work properly.
eval supervise-daemon --start \
+   ${retry:+--retry} $retry \
${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
${respawn_delay:+--respawn-delay} $respawn_delay \

diff --git a/src/rc/Makefile b/src/rc/Makefile
index e6c9f4a2..a2c7c306 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -159,7 +159,7 @@ rc-update: rc-update.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
+supervise-daemon: supervise-daemon.o _usage.o rc-misc.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 c59fb099..3923dab5 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -61,12 +61,13 @@ static struct pam_conv conv = { NULL, NULL};
 #include "queue.h"
 #include "rc.h"
 #include "rc-misc.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:Su:1:2:" \
+const char *getoptstring = "D:d:e:g:I:Kk:m:N:p:R:r:Su:1:2:" \
getoptstring_COMMON;
 const struct option longopts[] = {
{ "respawn-delay",1, NULL, 'D'},
@@ -80,6 +81,7 @@ const struct option longopts[] = {
{ "nicelevel",1, NULL, 'N'},
{ "pidfile",  1, NULL, 'p'},
{ "respawn-period",1, NULL, 'P'},
+   { "retry",   1, NULL, 'R'},
{ "chroot",   1, NULL, 'r'},
{ "start",0, NULL, 'S'},
{ "user", 1, NULL, 'u'},
@@ -99,6 +101,7 @@ const char * const longopts_help[] = {
"Set a nicelevel when starting",
"Match pid found in this file",
"Set respawn time period",
+   "Retry schedule to use when stopping",
"Chroot to this directory",
"Start daemon",
"Change the process user",
@@ -410,6 +413,9 @@ int main(int argc, char **argv)
bool stop = false;
char *exec = NULL;
char *pidfile = NULL;
+   char *retry = NULL;
+   int nkilled;
+   int sig = SIGTERM;
char *home = NULL;
int tid = 0;
pid_t child_pid, pid;
@@ -534,6 +540,9 @@ int main(int argc, char **argv)
pidfile = optarg;
break;
 
+   case 'R':  /* --retry |timeout */
+   retry = optarg;
+   break;
case 'r':  /* --chroot /new/root */
ch_root = optarg;
break;
@@ -605,6 +614,10 @@ int main(int argc, char **argv)
"than %d to avoid infinite respawning", applet, 

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

2017-05-22 Thread William Hubbs
commit: 0cfd0dd9ef580ed9dc563ccc164d70efe8f299db
Author: William Hubbs  gmail  com>
AuthorDate: Mon May 22 17:15:15 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon May 22 17:15:15 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0cfd0dd9

openrc-shutdown: move to single user mode by default

To be more compatible with sysvinit, move to single user mode if no
options are specified on the command line.

 man/openrc-shutdown.8| 5 -
 src/rc/openrc-shutdown.c | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/man/openrc-shutdown.8 b/man/openrc-shutdown.8
index eae16ae8..d0e95e24 100644
--- a/man/openrc-shutdown.8
+++ b/man/openrc-shutdown.8
@@ -8,7 +8,7 @@
 .\" This file may not be copied, modified, propagated, or distributed
 .\"except according to the terms contained in the LICENSE file.
 .\"
-.Dd April 6, 2017
+.Dd May 22, 2017
 .Dt openrc-shutdown 8 SMM
 .Os OpenRC
 .Sh NAME
@@ -40,6 +40,9 @@ upgrade of OpenRC if you are using openrc-init as your init 
process.
 .It Fl r , -reboot
 Stop all services, kill all processes and reboot the system.
 .El
+.Pp
+If none of these options are given, the default is to move the system
+into single user mode.
 .Sh SEE ALSO
 .Xr openrc-init 8 ,
 .Xr kexec 8 ,

diff --git a/src/rc/openrc-shutdown.c b/src/rc/openrc-shutdown.c
index 8905d354..0ed77445 100644
--- a/src/rc/openrc-shutdown.c
+++ b/src/rc/openrc-shutdown.c
@@ -114,7 +114,7 @@ if (geteuid() != 0)
case_RC_COMMON_GETOPT
}
}
-   if (cmd_count != 1) {
+   if (cmd_count > 1) {
eerror("%s: %s\n", applet, exclusive);
usage(EXIT_FAILURE);
}
@@ -128,5 +128,7 @@ if (geteuid() != 0)
send_cmd("reboot");
else if (do_reexec)
send_cmd("reexec");
+   else
+   send_cmd("single");
return 0;
 }



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

2017-05-22 Thread William Hubbs
commit: 1ece16bfcd0ab71d2f9fe17a75ee6184e0fa4828
Author: William Hubbs  gmail  com>
AuthorDate: Mon May 22 17:42:37 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon May 22 17:42:37 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1ece16bf

openrc-shutdown: add dry-run option

 man/openrc-shutdown.8|  3 +++
 src/rc/openrc-shutdown.c | 31 ---
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/man/openrc-shutdown.8 b/man/openrc-shutdown.8
index d0e95e24..5d81c4af 100644
--- a/man/openrc-shutdown.8
+++ b/man/openrc-shutdown.8
@@ -27,6 +27,9 @@ is the utility that communicates with openrc-init(8) to bring 
down the
 system or instruct openrc-init to re-execute itself. It supports the
 following options:
 .Bl -tag -width "poweroff"
+.It Fl d , -dry-run
+Print the action that would be taken without executing it. This is to
+allow testing.
 .It Fl H , -halt
 Stop all services, kill all remaining processes and halt the system.
 .It Fl k , -kexec

diff --git a/src/rc/openrc-shutdown.c b/src/rc/openrc-shutdown.c
index 0ed77445..ecb251a8 100644
--- a/src/rc/openrc-shutdown.c
+++ b/src/rc/openrc-shutdown.c
@@ -35,8 +35,9 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "HkpRr" getoptstring_COMMON;
+const char *getoptstring = "dHkpRr" getoptstring_COMMON;
 const struct option longopts[] = {
+   { "dry-run",no_argument, NULL, 'd'},
{ "halt",no_argument, NULL, 'H'},
{ "kexec",no_argument, NULL, 'k'},
{ "poweroff",no_argument, NULL, 'p'},
@@ -45,6 +46,7 @@ const struct option longopts[] = {
longopts_COMMON
 };
 const char * const longopts_help[] = {
+   "print actions instead of executing them",
"halt the system",
"reboot the system using kexec",
"power off the system",
@@ -56,13 +58,16 @@ const char *usagestring = NULL;
 const char *exclusive = "Select one of "
 "--halt, --kexec, --poweroff, --reexec or --reboot";
 
-static void send_cmd(const char *cmd)
+static void send_cmd(const char *cmd, bool dryrun)
 {
FILE *fifo;
size_t ignored;
 
+   if (dryrun) {
+   einfo("Would send %s to init", cmd);
+   return;
+   }
fifo = fopen(RC_INIT_FIFO, "w");
-
if (!fifo) {
perror("fopen");
return;
@@ -78,6 +83,7 @@ int main(int argc, char **argv)
 {
int opt;
int cmd_count = 0;
+   bool do_dryrun = false;
bool do_halt = false;
bool do_kexec = false;
bool do_poweroff = false;
@@ -85,12 +91,13 @@ int main(int argc, char **argv)
bool do_reexec = false;
 
applet = basename_c(argv[0]);
-if (geteuid() != 0)
-   eerrorx("%s: you must be root\n", applet);
while ((opt = getopt_long(argc, argv, getoptstring,
longopts, (int *) 0)) != -1)
{
switch (opt) {
+   case 'd':
+   do_dryrun = true;
+   break;
case 'H':
do_halt = true;
cmd_count++;
@@ -114,21 +121,23 @@ if (geteuid() != 0)
case_RC_COMMON_GETOPT
}
}
+if (geteuid() != 0 && ! do_dryrun)
+   eerrorx("%s: you must be root\n", applet);
if (cmd_count > 1) {
eerror("%s: %s\n", applet, exclusive);
usage(EXIT_FAILURE);
}
if (do_halt)
-   send_cmd("halt");
+   send_cmd("halt", do_dryrun);
else if (do_kexec)
-   send_cmd("kexec");
+   send_cmd("kexec", do_dryrun);
else if (do_poweroff)
-   send_cmd("poweroff");
+   send_cmd("poweroff", do_dryrun);
else if (do_reboot)
-   send_cmd("reboot");
+   send_cmd("reboot", do_dryrun);
else if (do_reexec)
-   send_cmd("reexec");
+   send_cmd("reexec", do_dryrun);
else
-   send_cmd("single");
+   send_cmd("single", do_dryrun);
return 0;
 }



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

2017-04-12 Thread William Hubbs
commit: 05738bfce120114037d4f02c67ec740813f94b89
Author: William Hubbs  gmail  com>
AuthorDate: Wed Apr 12 22:56:30 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Apr 12 22:56:36 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=05738bfc

init: add re-exec capability

This will allow the re-execution of the init process after upgrading
OpenRC.

 man/openrc-shutdown.8|  7 ++-
 src/rc/openrc-init.c | 22 +++---
 src/rc/openrc-shutdown.c | 14 --
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/man/openrc-shutdown.8 b/man/openrc-shutdown.8
index 98ec64a6..eae16ae8 100644
--- a/man/openrc-shutdown.8
+++ b/man/openrc-shutdown.8
@@ -19,11 +19,13 @@
 .Op Fl H , -halt
 .Op Fl k , -kexec
 .Op Fl p , -poweroff
+.Op Fl R , -reexec
 .Op Fl r , -reboot
 .Sh DESCRIPTION
 .Nm
 is the utility that communicates with openrc-init(8) to bring down the
-system.  The following options affect how the system is brought down:
+system or instruct openrc-init to re-execute itself. It supports the
+following options:
 .Bl -tag -width "poweroff"
 .It Fl H , -halt
 Stop all services, kill all remaining processes and halt the system.
@@ -32,6 +34,9 @@ Stop all services, kill all processes and boot directly into 
a new
 kernel loaded via kexec(8).
 .It Fl p , -poweroff
 Stop all services, kill all processes and power off the system.
+.It Fl R , -reexec
+instruct openrc-init to re-exec itself. This should be used after an
+upgrade of OpenRC if you are using openrc-init as your init process.
 .It Fl r , -reboot
 Stop all services, kill all processes and reboot the system.
 .El

diff --git a/src/rc/openrc-init.c b/src/rc/openrc-init.c
index fb3347a4..61052806 100644
--- a/src/rc/openrc-init.c
+++ b/src/rc/openrc-init.c
@@ -20,6 +20,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -79,6 +80,12 @@ static void init(const char *default_runlevel)
waitpid(pid, NULL, 0);
 }
 
+static void handle_reexec(char *my_name)
+{
+   execl(my_name, my_name, "reexec", NULL);
+   return;
+}
+
 static void handle_shutdown(const char *runlevel, int cmd)
 {
pid_t pid;
@@ -123,10 +130,11 @@ static void signal_handler(int sig)
 
 int main(int argc, char **argv)
 {
-   char *default_runlevel = NULL;
+   char *default_runlevel;
char buf[2048];
int count;
FILE *fifo;
+   bool reexec = false;
struct sigaction sa;
 
if (getpid() != 1)
@@ -134,16 +142,22 @@ int main(int argc, char **argv)
 
if (argc > 1)
default_runlevel = argv[1];
+   else
+   default_runlevel = NULL;
+
+   if (default_runlevel && strcmp(default_runlevel, "reexec") == 0)
+   reexec = true;
 
printf("OpenRC init version %s starting\n", VERSION);
-   init(default_runlevel);
+   if (! reexec)
+   init(default_runlevel);
memset(, 0, sizeof(sa));
sa.sa_handler = signal_handler;
sigaction(SIGCHLD, , NULL);
sigaction(SIGINT, , NULL);
reboot(RB_DISABLE_CAD);
 
-   if (mkfifo(RC_INIT_FIFO, 0600) == -1)
+   if (mkfifo(RC_INIT_FIFO, 0600) == -1 && errno != EEXIST)
perror("mkfifo");
 
for (;;) {
@@ -166,6 +180,8 @@ int main(int argc, char **argv)
handle_shutdown("shutdown", RB_POWER_OFF);
else if (strcmp(buf, "reboot") == 0)
handle_shutdown("reboot", RB_AUTOBOOT);
+   else if (strcmp(buf, "reexec") == 0)
+   handle_reexec(argv[0]);
}
return 0;
 }

diff --git a/src/rc/openrc-shutdown.c b/src/rc/openrc-shutdown.c
index 978e8a68..8905d354 100644
--- a/src/rc/openrc-shutdown.c
+++ b/src/rc/openrc-shutdown.c
@@ -35,11 +35,12 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "kpr" getoptstring_COMMON;
+const char *getoptstring = "HkpRr" getoptstring_COMMON;
 const struct option longopts[] = {
{ "halt",no_argument, NULL, 'H'},
{ "kexec",no_argument, NULL, 'k'},
{ "poweroff",no_argument, NULL, 'p'},
+   { "reexec",no_argument, NULL, 'R'},
{ "reboot",no_argument, NULL, 'r'},
longopts_COMMON
 };
@@ -47,11 +48,13 @@ const char * const longopts_help[] = {
"halt the system",
"reboot the system using kexec",
"power off the system",
+   "re-execute init (use after upgrading)",
"reboot the system",
longopts_help_COMMON
 };
 const char *usagestring = NULL;
-const char *exclusive = "Select one of --halt, --kexec, --poweroff or 
--reboot";
+const char *exclusive = "Select one of "
+"--halt, --kexec, --poweroff, --reexec or --reboot";
 
 static void send_cmd(const char *cmd)
 {
@@ -79,6 +82,7 @@ int main(int argc, char **argv)
bool do_kexec = false;
bool do_poweroff = false;
  

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

2016-07-26 Thread William Hubbs
commit: 94b98430cb83a8f4e62d837100fc357e9eb12ca6
Author: Kenneth Lakin  gmail  com>
AuthorDate: Tue Nov  3 11:33:06 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jul 26 17:30:39 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=94b98430

start-stop-daemon: Add SSD_IONICELEVEL

This is the disk IO counterpart to SSD_NICELEVEL.
Modified by William Hubbs to add the variable to the start-stop-daemon
man page.

This fixes #69.

 etc/rc.conf|  3 +++
 man/start-stop-daemon.8|  4 
 src/rc/start-stop-daemon.c | 14 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/etc/rc.conf b/etc/rc.conf
index 80f68dd..cbb660a 100644
--- a/etc/rc.conf
+++ b/etc/rc.conf
@@ -117,6 +117,9 @@
 # Some daemons are started and stopped via start-stop-daemon.
 # We can set some things on a per service basis, like the nicelevel.
 #SSD_NICELEVEL="-19"
+# Or the ionice level. The format is class[:data] , just like the
+# --ionice start-stop-daemon parameter.
+#SSD_IONICELEVEL="2:2"
 
 # Pass ulimit parameters
 # If you are using bash in POSIX mode for your shell, note that the

diff --git a/man/start-stop-daemon.8 b/man/start-stop-daemon.8
index c328895..112cd5f 100644
--- a/man/start-stop-daemon.8
+++ b/man/start-stop-daemon.8
@@ -153,6 +153,10 @@ The retry specification can be either a timeout in seconds 
or multiple
 signal/timeout pairs (like SIGTERM/5).
 .El
 .Sh ENVIRONMENT
+.Va SSD_IONICELEVEL
+can also set the IO scheduling priority of the daemon, but the command line
+option takes precedence.
+.Pp
 .Va SSD_NICELEVEL
 can also set the scheduling priority of the daemon, but the command line
 option takes precedence.

diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 27939c2..188169f 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -696,6 +696,17 @@ int main(int argc, char **argv)
if (sscanf(tmp, "%d", ) != 1)
eerror("%s: invalid nice level `%s' (SSD_NICELEVEL)",
applet, tmp);
+   if ((tmp = getenv("SSD_IONICELEVEL"))) {
+   int n = sscanf(tmp, "%d:%d", , );
+   if (n != 1 && n != 2)
+   eerror("%s: invalid ionice level `%s' 
(SSD_IONICELEVEL)",
+   applet, tmp);
+   if (ionicec == 0)
+   ioniced = 0;
+   else if (ionicec == 3)
+   ioniced = 7;
+   ionicec <<= 13; /* class shift */
+   }
 
/* Get our user name and initial dir */
p = getenv("USER");
@@ -1195,7 +1206,8 @@ int main(int argc, char **argv)
if ((strncmp(env->value, "RC_", 3) == 0 &&
strncmp(env->value, "RC_SERVICE=", 10) != 0 &&
strncmp(env->value, "RC_SVCNAME=", 10) != 0) ||
-   strncmp(env->value, "SSD_NICELEVEL=", 14) == 0)
+   strncmp(env->value, "SSD_NICELEVEL=", 14) == 0 
||
+   strncmp(env->value, "SSD_IONICELEVEL=", 16) == 
0)
{
p = strchr(env->value, '=');
*p = '\0';



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

2016-01-28 Thread William Hubbs
commit: 8a7e4d38a74c714e1a532e1b7a53fd2a5c528b63
Author: William Hubbs  gmail  com>
AuthorDate: Sun Sep 21 18:54:51 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jan 28 18:57:11 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8a7e4d38

rc-service: add --ifinactive and --ifnotstarted flags

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

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

diff --git a/man/rc-service.8 b/man/rc-service.8
index 9260329..80deb5e 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -20,6 +20,14 @@
 .Ar service cmd
 .Op Ar ...
 .Nm
+.Op Fl I , -ifinactive
+.Ar service cmd
+.Op Ar ...
+.Nm
+.Op Fl N , -ifnotstarted
+.Ar service cmd
+.Op Ar ...
+.Nm
 .Fl e , -exists
 .Ar service
 .Nm
@@ -36,6 +44,13 @@ If
 is given then
 .Nm
 returns 0 even if the service does not exist.
+If
+.Fl I , -ifinactive
+or
+.Fl N , -ifnotstarted
+is given then
+.Nm
+returns 0 if the service exists but is in the wrong state.
 .Pp
 If given the
 .Fl l , -list

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index 8e9da44..3fd94b2 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -29,10 +29,12 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "e:ilr:" getoptstring_COMMON;
+const char *getoptstring = "e:ilr:IN" getoptstring_COMMON;
 const struct option longopts[] = {
{ "exists",   1, NULL, 'e' },
{ "ifexists", 0, NULL, 'i' },
+   { "ifinactive", 0, NULL, 'I' },
+   { "ifnotstarted", 0, NULL, 'N' },
{ "list", 0, NULL, 'l' },
{ "resolve",  1, NULL, 'r' },
longopts_COMMON
@@ -40,6 +42,8 @@ const struct option longopts[] = {
 const char * const longopts_help[] = {
"tests if the service exists or not",
"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",
"list all available services",
"resolve the service name to an init script",
longopts_help_COMMON
@@ -56,7 +60,10 @@ int main(int argc, char **argv)
char *service;
RC_STRINGLIST *list;
RC_STRING *s;
+   RC_SERVICE state;
bool if_exists = false;
+   bool if_inactive = false;
+   bool if_notstarted = false;
 
applet = basename_c(argv[0]);
/* Ensure that we are only quiet when explicitly told to be */
@@ -77,6 +84,12 @@ int main(int argc, char **argv)
case 'i':
if_exists = true;
break;
+   case 'I':
+   if_inactive = true;
+   break;
+   case 'N':
+   if_notstarted = true;
+   break;
case 'l':
list = rc_services_in_runlevel(NULL);
if (TAILQ_FIRST(list) == NULL)
@@ -113,6 +126,11 @@ int main(int argc, char **argv)
return 0;
eerrorx("%s: service `%s' does not exist", applet, *argv);
}
+   state = rc_service_state(*argv);
+   if (if_inactive && ! (state & RC_SERVICE_INACTIVE))
+   return 0;
+   if (if_notstarted && (state & RC_SERVICE_STARTED))
+   return 0;
*argv = service;
execv(*argv, argv);
eerrorx("%s: %s", applet, strerror(errno));