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

2018-07-09 Thread William Hubbs
commit: 2eea73bfd5ce2f9993d52293fe7d25c0c804d592
Author: William Hubbs  gmail  com>
AuthorDate: Mon Jul  9 23:02:54 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jul 10 00:44:40 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=2eea73bf

rc-functions.sh: Remove addon support

This is an old relic from Gentoo baselayout-1.x which should not be used
any longer.

 NEWS.md|  7 ++
 sh/.gitignore  |  1 -
 sh/Makefile|  2 +-
 sh/{rc-functions.sh.in => rc-functions.sh} | 36 --
 4 files changed, 8 insertions(+), 38 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 13c62d6e..e9605031 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -4,6 +4,13 @@ OpenRC NEWS
 This file will contain a list of notable changes for each release. Note
 the information in this file is in reverse order.
 
+## OpenRC 0.39
+
+This version removes the support for addons.
+The only place I know that this was used was Gentoo Baselayout 1.x, so
+it shouldn't affect anyone since baselayout-1 has been dead for a few
+years.
+
 ## OpenRC 0.37
 
 start-stop-daemon now supports logging stdout and stderr of daemons to

diff --git a/sh/.gitignore b/sh/.gitignore
index 8a007103..186a409c 100644
--- a/sh/.gitignore
+++ b/sh/.gitignore
@@ -1,6 +1,5 @@
 functions.sh
 gendepends.sh
-rc-functions.sh
 openrc-run.sh
 cgroup-release-agent.sh
 init.sh

diff --git a/sh/Makefile b/sh/Makefile
index 4d7148fb..e5029bcd 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -1,6 +1,6 @@
 DIR=   ${LIBEXECDIR}/sh
 SRCS=  init.sh.in functions.sh.in gendepends.sh.in \
-   openrc-run.sh.in rc-functions.sh.in ${SRCS-${OS}}
+   openrc-run.sh.in ${SRCS-${OS}}
 INC=   rc-mount.sh functions.sh rc-functions.sh runit.sh s6.sh \
start-stop-daemon.sh supervise-daemon.sh
 BIN=   gendepends.sh init.sh openrc-run.sh ${BIN-${OS}}

diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh
similarity index 83%
rename from sh/rc-functions.sh.in
rename to sh/rc-functions.sh
index d6336a18..d77c5dd3 100644
--- a/sh/rc-functions.sh.in
+++ b/sh/rc-functions.sh
@@ -2,42 +2,6 @@
 # Copyright (c) 2007-2009 Roy Marples 
 # Released under the 2-clause BSD license.
 
-has_addon()
-{
-   [ -e /@LIB@/rc/addons/"$1".sh -o -e /@LIB@/rcscripts/addons/"$1".sh ]
-}
-
-_addon_warn()
-{
-   eindent
-   ewarn "$RC_SVCNAME uses addon code which is deprecated"
-   ewarn "and may not be available in the future."
-   eoutdent
-}
-
-import_addon()
-{
-   if [ -e /@LIB@/rc/addons/"$1".sh ]; then
-   _addon_warn
-   . /@LIB@/rc/addons/"$1".sh
-   elif [ -e /@LIB@/rcscripts/addons/"$1".sh ]; then
-   _addon_warn
-   . /@LIB@/rcscripts/addons/"$1".sh
-   else
-   return 1
-   fi
-}
-
-start_addon()
-{
-   ( import_addon "$1-start" )
-}
-
-stop_addon()
-{
-   ( import_addon "$1-stop" )
-}
-
 net_fs_list="afs ceph cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre
 ncpfs nfs nfs4 ocfs2 shfs smbfs"
 is_net_fs()



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

2018-06-15 Thread William Hubbs
commit: a097933edab9d7221df1831e098415d604437c98
Author: William Hubbs  gmail  com>
AuthorDate: Fri Jun 15 22:44:39 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Jun 15 22:44:39 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a097933e

sh/start-stop-daemon.sh: fix processing of the logger arguments

 sh/start-stop-daemon.sh | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 69666ff7..e68b47ef 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -38,6 +38,10 @@ ssd_start()
service_inactive && _inactive=true
mark_service_inactive
fi
+   [ -n "$output_logger" ] && 
+   output_logger_arg="--stdout-logger \"$output_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"
# to work properly.
@@ -47,8 +51,8 @@ ssd_start()
${directory:+--chdir} $directory \
${output_log+--stdout} $output_log \
${error_log+--stderr} $error_log \
-   ${output_logger+--stdout-logger} \"$output_logger\" \
-   ${error_logger+--stderr-logger} \"$error_logger\" \
+   ${output_logger_arg} \
+   ${error_logger_arg} \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \



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

2018-05-31 Thread William Hubbs
commit: 6edf516a1fe0ad4f4e8738f9fdd1bf0bc7718361
Author: Austin English  gmail  com>
AuthorDate: Wed May 30 16:11:10 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May 30 16:11:10 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6edf516a

sh/supervise-daemon.sh: use start_stop_daemon_args if supervise_daemon_args is 
undefined

 man/openrc-run.8   | 3 +++
 sh/supervise-daemon.sh | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index f9109ef3..f0750406 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -119,6 +119,9 @@ The amount of time, in milliseconds, s6-svc should wait for 
the service
 to go down when stopping the service. The default is 6.
 .It Ar start_stop_daemon_args
 List of arguments passed to start-stop-daemon when starting the daemon.
+.It Ar supervise_daemon_args
+List of arguments passed to supervise-daemon when starting the daemon.
+If undefined, start_stop_daemon_args is used as a fallback.
 .It Ar command
 Daemon to start or stop via
 .Nm start-stop-daemon

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index b600b9c6..80e0260c 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -34,7 +34,7 @@ supervise_start()
${respawn_period:+--respawn-period} $respawn_period \
${command_user+--user} $command_user \
${umask+--umask} $umask \
-   $supervise_daemon_args \
+   ${supervise_daemon_args:-${start_stop_daemon_args}} \
$command \
-- $command_args $command_args_foreground
rc=$?



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

2018-05-22 Thread William Hubbs
commit: fa5aea80c50fb724d2c98a6542307adbafd0e62d
Author: William Hubbs  gmail  com>
AuthorDate: Tue May 22 16:12: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=fa5aea80

openrc-run.sh: move crashed test outside started test

This is handled inside librc, so we don't need the nesting in this
script.

 sh/openrc-run.sh.in | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index e3dff6ce..7e9064c2 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -133,11 +133,10 @@ _status()
elif service_inactive; then
ewarn "status: inactive"
return 16
+   elif service_crashed; then
+   eerror "status: crashed"
+   return 32
elif service_started; then
-   if service_crashed; then
-   eerror "status: crashed"
-   return 32
-   fi
einfo "status: started"
return 0
else



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

2018-03-11 Thread William Hubbs
commit: 61905bfcf560219939c902dbb8fe9bc5088a42cf
Author: William Hubbs  gmail  com>
AuthorDate: Mon Mar 12 02:40:57 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Mar 12 02:41:01 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=61905bfc

Clean up cgroups v2 code

Remove the IFS manipulation and simplify the loop that processes the
settings.

 sh/rc-cgroup.sh.in | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 5bc7db54..d4b68ada 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -184,18 +184,17 @@ cgroup2_set_limits()
cgroup_path="$(cgroup2_find_path)"
[ -d "${cgroup_path}" ] || return 0
rc_cgroup_path="${cgroup_path}/${RC_SVCNAME}"
-   local OIFS="$IFS"
-   IFS="
-"
[ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}"
-   printf "%d" 0 > "${rc_cgroup_path}/cgroup.procs"
-   echo "${rc_cgroup_settings}" | while IFS="$OIFS" read -r key value; do
-   [ -z "${key}" ] || [ -z "${value}" ] && continue
-   [ ! -e "${rc_cgroup_path}/${key}" ] && continue
-   veinfo "${RC_SVCNAME}: cgroups: ${key} ${value}"
-   printf "%s" "${value}" > "${rc_cgroup_path}/${key}"
+   [ -f "${rc_cgroup_path}"/cgroup.procs ] &&
+   printf 0 > "${rc_cgroup_path}"/cgroup.procs
+   [ -z "${rc_cgroup_settings}" ] && return 0
+   echo "${rc_cgroup_settings}" | while read -r key value; do
+   [ -z "${key}" ] && continue
+   [ -z "${value}" ] && continue
+   [ ! -f "${rc_cgroup_path}/${key}" ] && continue
+   veinfo "${RC_SVCNAME}: cgroups: setting ${key} to ${value}"
+   printf "%s\n" "${value}" > "${rc_cgroup_path}/${key}"
done
-   IFS="$OIFS"
return 0
 }
 



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

2018-02-28 Thread William Hubbs
commit: 1ab8541a6ccb9d72c6faeaf2d616fc49f6cdfaf6
Author: Jason Zaman  perfinion  com>
AuthorDate: Wed Feb 28 17:24:55 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Feb 28 17:24:55 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1ab8541a

init-early.sh.Linux.in: apply the selinux label to /dev/console early

/dev/console is relabelled later in the devfs init script, but by then we
have already missed some of the messages, so fix that label early.

 sh/init-early.sh.Linux.in | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sh/init-early.sh.Linux.in b/sh/init-early.sh.Linux.in
index 1898c440..f07bc11b 100644
--- a/sh/init-early.sh.Linux.in
+++ b/sh/init-early.sh.Linux.in
@@ -33,6 +33,9 @@ else
kmode="-a"
 fi
 
+# Set the SELinux label on console before everything so we dont lose output
+[ -x /sbin/restorecon ] && /sbin/restorecon -F /dev/console
+
 # Try and set a font and as early as we can
 if service_present "$RC_DEFAULTLEVEL" consolefont ||
service_present "$RC_BOOTLEVEL" consolefont; then



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

2018-02-28 Thread William Hubbs
commit: 5bb6f9aa318a6d0507971b74d88c3fd2803bae4b
Author: Jason Zaman  perfinion  com>
AuthorDate: Wed Feb 28 18:41:54 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Feb 28 18:42:58 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=5bb6f9aa

init.sh: apply SELinux label for /run early in boot

Some initramfs mount /run which then ends up with the wrong labels.
Force relabel all of /run right after its mounted to fix.

 sh/init.sh.Linux.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index b07463b3..7ee25b57 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -83,6 +83,7 @@ elif ! mountinfo -q /run; then
fi
 fi
 
+[ -x /sbin/restorecon ] && /sbin/restorecon -rF /run
 checkpath -d $RC_SVCDIR
 checkpath -d -m 0775 -o root:uucp /run/lock
 



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

2018-02-23 Thread William Hubbs
commit: 16ff3cd8df6169f73e3d7cf00758a4703f62cbf0
Author: Christian Brauner  ubuntu  com>
AuthorDate: Mon Feb 12 12:32:01 2018 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Feb 23 21:51:12 2018 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=16ff3cd8

check whether /sys/fs/cgroup is a mountpoint

The current check only tries to detect whether /sys/fs/cgroup exists and
whether it is writable or not. But when the init system doesn't mount
cgroups then /sys/fs/cgroup will just be an empty directory. When paired
with unprivileged containers that mount sysfs this will cause misleading
errors to be printed since /sys/fs/cgroup will be owned by user
nobody:nogroup in this case. Independent of this specific problem this
check will also be misleading when the /sys/fs/cgroup exists and is in
fact writable by the init system but isn't actually a mountpoint.

Note from William. "grep -qs" doesn't need to redirect output to
/dev/null since it is completely silent.

This fixes #209.

 sh/openrc-run.sh.in | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 95d0ecab..e3dff6ce 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -260,9 +260,12 @@ for _cmd; do
# Apply cgroups settings if defined
if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]
then
-   if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
-   eerror "No permission to apply cgroup settings"
-   break
+   if grep -qs /sys/fs/cgroup /proc/1/mountinfo
+   then
+   if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup 
]; then
+   eerror "No permission to apply cgroup 
settings"
+   break
+   fi
fi
cgroup_add_service
fi



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

2017-12-01 Thread William Hubbs
commit: cee3919908c2d715fd75a796873e3308209a4c2e
Author: William Hubbs  gmail  com>
AuthorDate: Fri Dec  1 21:43:09 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Dec  1 21:43:09 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cee39199

Clean up the calls to group_add_service

This function should only be called once and it does not take any
arguments.

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

 sh/openrc-run.sh.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 05cb972b..95d0ecab 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -264,8 +264,7 @@ for _cmd; do
eerror "No permission to apply cgroup settings"
break
fi
-   cgroup_add_service /sys/fs/cgroup/openrc
-   cgroup_add_service /sys/fs/cgroup/systemd/system
+   cgroup_add_service
fi
[ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] &&
cgroup_set_limits



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

2017-11-29 Thread William Hubbs
commit: ddbdb696582e9fd61995f15d6a3a53055a151e41
Author: Julien Reichardt  jrei  ch>
AuthorDate: Mon Nov 20 22:45:51 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Nov 29 21:06:06 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ddbdb696

add more variables for start-stop-daemon and supervise-daemon options

Add the following variables to expose more arguments that can be passed
to start-stop-daemon or supervise-daemon:

- directory will be passed to --chdir
- error_log will be passed to --stderr
- output_log will be passed to --stdout
- umask will be passed to umask

This is for #184.

 man/openrc-run.8| 20 
 sh/start-stop-daemon.sh |  4 
 sh/supervise-daemon.sh  |  4 
 3 files changed, 28 insertions(+)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 3f4f7e81..e1db58bd 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -157,6 +157,24 @@ use this to change the user id before
 or
 .Xr supervise-daemon 8
 launches the daemon
+.It Ar output_log
+This is the path to a file or named pipe where the standard output from
+the service will be redirected. If you are starting this service with
+.Xr start-stop-daemon 8 ,
+,  you must set
+.Pa command_background
+to true. Keep in mind that this path will be inside the chroot if the
+.Pa chroot
+variable is set.
+.It Ar error_log
+The same thing as
+.Pa output_log
+but for the standard error output.
+.It Ar directory
+.Xr start-stop-daemon 8
+and
+.Xr supervise-daemon 8
+will chdir to this directory before starting the daemon.
 .It Ar chroot
 .Xr start-stop-daemon 8
 and
@@ -201,6 +219,8 @@ used along with in_background_fake to support re-entrant 
services.
 .It Ar in_background_fake
 Space separated list of commands which should always succeed when
 in_background is yes.
+.It Ar umask
+Set the umask of the daemon.
 .Pp
 Keep in mind that eval is used to process chroot, command, command_args_*,
 command_user, pidfile and procname. This may affect how they are

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 0793b19a..35c642c0 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -44,9 +44,13 @@ ssd_start()
eval start-stop-daemon --start \
--exec $command \
${chroot:+--chroot} $chroot \
+   ${directory:+--chdir} $directory \
+   ${output_log+--stdout} $output_log \
+   ${error_log+--stderr} $error_log \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \
+   ${umask+--umask} $umask \
$_background $start_stop_daemon_args \
-- $command_args $command_args_background
if eend $? "Failed to start ${name:-$RC_SVCNAME}"; then

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index f6e599d5..b600b9c6 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -24,12 +24,16 @@ supervise_start()
# to work properly.
eval supervise-daemon "${RC_SVCNAME}" --start \
${retry:+--retry} $retry \
+   ${directory:+--chdir} $directory  \
${chroot:+--chroot} $chroot \
+   ${output_log+--stdout} ${output_log} \
+   ${error_log+--stderr} $error_log \
${pidfile:+--pidfile} $pidfile \
${respawn_delay:+--respawn-delay} $respawn_delay \
${respawn_max:+--respawn-max} $respawn_max \
${respawn_period:+--respawn-period} $respawn_period \
${command_user+--user} $command_user \
+   ${umask+--umask} $umask \
$supervise_daemon_args \
$command \
-- $command_args $command_args_foreground



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

2017-11-16 Thread William Hubbs
commit: e805c74d31113c75058d860588e83bca120decf6
Author: William Hubbs  gmail  com>
AuthorDate: Thu Nov 16 21:35:35 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Nov 16 21:35:35 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e805c74d

s6 supervisor fixes

Add the ability to force-kill a service if it does not go down
successfully. Also, adjust the default wait time for an s6 service to go
down to 60 seconds.

 man/openrc-run.8 |  5 -
 s6-guide.md  |  4 
 sh/s6.sh | 20 +++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 471f63e5..3f4f7e81 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -111,9 +111,12 @@ The path to the s6 service directory if you are monitoring 
this service
 with S6. The default is /var/svc.d/${RC_SVCNAME}.
 .It Ar s6_svwait_options_start
 The options to pass to s6-svwait when starting the service via s6.
+.It Ar s6_force_kill
+Should we force-kill this service if s6_service_timeout_stop expires
+but the service doesn't go down during shutdown? The default is yes.
 .It Ar s6_service_timeout_stop
 The amount of time, in milliseconds, s6-svc should wait for the service
-to go down when stopping the service. The default is 1.
+to go down when stopping the service. The default is 6.
 .It Ar start_stop_daemon_args
 List of arguments passed to start-stop-daemon when starting the daemon.
 .It Ar command

diff --git a/s6-guide.md b/s6-guide.md
index 52262b3c..bcc3ac28 100644
--- a/s6-guide.md
+++ b/s6-guide.md
@@ -39,6 +39,10 @@ s6_service_path - the path to the s6 service directory. The 
default is
 s6_svwait_options_start - the options to pass to s6-svwait when starting
 the service. If this is not set, s6-svwait will not be called.
 
+s6_force_kill - Should we try to force kill this service if the
+s6_service_timeout_stop timeout expires when shutting down this service?
+The default is yes.
+
 s6_service_timeout_stop - the amount of time, in milliseconds, s6-svc
 should wait for a service to go down when stopping.
 

diff --git a/sh/s6.sh b/sh/s6.sh
index d1b9c103..33c478ad 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -12,6 +12,20 @@
 
 [ -z "${s6_service_path}" ] && s6_service_path="/var/svc.d/${RC_SVCNAME}"
 
+_s6_force_kill() {
+   local pid
+   s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
+   pid="${3%)}"
+   [ -z "${pid}" ] && return 0
+   if kill -0 "${pid}" 2> /dev/null; then
+   ewarn "Sending DOWN & KILL for ${RC_SVCNAME}"
+   s6-svc -dk "${s6_service_link}"
+   sleep 1
+   kill -0 "${pid}" 2>/dev/null && return 1
+   fi
+   return 0
+}
+
 s6_start()
 {
if [ ! -d "${s6_service_path}" ]; then
@@ -41,7 +55,11 @@ s6_stop()
  fi
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Stopping ${name:-$RC_SVCNAME}"
-   s6-svc -wD -d -T ${s6_service_timeout_stop:-1} "${s6_service_link}"
+   s6-svc -d -wD -T ${s6_service_timeout_stop:-6} "${s6_service_link}"
+   set -- $(s6-svstat "${s6_service_link}")
+   [ "$1" = "up" ] && 
+   yesno "${s6_force_kill:-yes}" &&
+   _s6_force_kill "$@"
set -- $(s6-svstat "${s6_service_link}")
[ "$1" = "down" ]
eend $? "Failed to stop ${name:-$RC_SVCNAME}"



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

2017-11-07 Thread William Hubbs
commit: 913b2ca53771742385d5c69164aefcaab634f012
Author: William Hubbs  gmail  com>
AuthorDate: Sat Oct 28 00:22:09 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Oct 28 00:22:09 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=913b2ca5

supervise-daemon: use RC_SVCNAME as the first argument to the daemon

This makes ps show which service the supervisor is monitoring.

 sh/supervise-daemon.sh|  4 ++--
 src/rc/supervise-daemon.c | 24 
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index e5d8d461..f6e599d5 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -22,7 +22,7 @@ supervise_start()
# The eval call is necessary for cases like:
# command_args="this \"is a\" test"
# to work properly.
-   eval supervise-daemon --start \
+   eval supervise-daemon "${RC_SVCNAME}" --start \
${retry:+--retry} $retry \
${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
@@ -49,7 +49,7 @@ supervise_stop()
pidfile="${startpidfile:-$pidfile}"
[ -n "$pidfile" ] || return 0
ebegin "Stopping ${name:-$RC_SVCNAME}"
-   supervise-daemon --stop \
+   supervise-daemon "${RC_SVCNAME}" --stop \
${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
 

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 1d0c3407..3989cbc7 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -561,8 +561,13 @@ int main(int argc, char **argv)
applet = basename_c(argv[0]);
atexit(cleanup);
svcname = getenv("RC_SVCNAME");
+   if (!svcname)
+   eerrorx("%s: The RC_SVCNAME environment variable is not set", 
applet);
openlog(applet, LOG_PID, LOG_DAEMON);
 
+   if (argc >= 1 && svcname && strcmp(argv[1], svcname))
+   eerrorx("%s: the first argument must be %s", applet, svcname);
+
if ((tmp = getenv("SSD_NICELEVEL")))
if (sscanf(tmp, "%d", &nicelevel) != 1)
eerror("%s: invalid nice level `%s' (SSD_NICELEVEL)",
@@ -583,6 +588,17 @@ int main(int argc, char **argv)
}
}
 
+   *cmdline = '\0';
+   c = argv;
+   while (c && *c) {
+   strcat(cmdline, *c);
+   strcat(cmdline, " ");
+   c++;
+   }
+   if (svcname) {
+   argc--;
+   argv++;
+   }
while ((opt = getopt_long(argc, argv, getoptstring, longopts,
(int *) 0)) != -1)
switch (opt) {
@@ -721,14 +737,6 @@ 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;



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

2017-10-26 Thread William Hubbs
commit: 35b88fb42bb8e0a56cdc1947342f1b89c98658bc
Author: Patrick McLean  gentoo  org>
AuthorDate: Thu Oct 26 02:19:15 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 02:19:15 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=35b88fb4

cgroups_cleanup: clean up shutdown signaling

- do not sleep for the full 90 seconds if processes are dead
- re-arrange the order of signals we attempt to send to the processes

 sh/rc-cgroup.sh.in | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index d48957ac..5bc7db54 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -203,15 +203,21 @@ cgroup_cleanup()
 {
cgroup_running || return 0
ebegin "starting cgroups cleanup"
-   local pids
+   local pids loops=0
pids="$(cgroup_get_pids)"
if [ -n "${pids}" ]; then
-   kill -s "${stopsig:-TERM}" ${pids} 2> /dev/null
kill -s CONT ${pids} 2> /dev/null
+   kill -s "${stopsig:-TERM}" ${pids} 2> /dev/null
yesno "${rc_send_sighup:-no}" &&
kill -s HUP ${pids} 2> /dev/null
-   sleep "${rc_timeout_stopsec:-90}"
-   yesno "${rc_send_sigkill:-yes}" &&
+   kill -s "${stopsig:-TERM}" ${pids} 2> /dev/null
+   while [ -n "$(cgroup_get_pids)" ] &&
+   [ "${loops}" -lt "${rc_timeout_stopsec:-90}" ]; do
+   loops=$((loops+1))
+   sleep 1
+   done
+   pids="$(cgroup_get_pids)"
+   [ -n "${pids}" ] && yesno "${rc_send_sigkill:-yes}" &&
kill -s KILL ${pids} 2> /dev/null
fi
cgroup2_remove



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

2017-10-26 Thread William Hubbs
commit: 6f3e2e2d7de61ab28cf03937ccf2e5f80b62190a
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 02:20:15 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 02:20:15 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6f3e2e2d

supervise-daemon.sh: fix status function with no namespaces

 sh/supervise-daemon.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index bccfd06a..d2cfe932 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -70,6 +70,8 @@ _check_supervised()
if [ "${n1}" = "${n2}" ]; then
return 1
fi
+   else
+   return 1
fi
fi
fi



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

2017-10-26 Thread William Hubbs
commit: 82da844b42ff83b2ebf944198e56ac2d81851897
Author: William Hubbs  gmail  com>
AuthorDate: Thu Oct 26 18:11:12 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Oct 26 18:11:12 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=82da844b

implement "unsupervised" status

The unsupervised status is to be used when a supervisor of a supervised
service dies but leaves the service daemon itself running.

 sh/supervise-daemon.sh | 21 +
 src/rc/rc-status.c | 11 ++-
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index d2cfe932..e5d8d461 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -58,22 +58,11 @@ supervise_stop()
 
 _check_supervised()
 {
-   [ "$RC_UNAME" != Linux ] && return 0
-   local child_pid="$(service_get_value "child_pid")"
-   local pid="$(cat ${pidfile})"
-   if [ -n "${child_pid}" ]; then
-   if ! [ -e "/proc/${pid}" ] && [ -e "/proc/${child_pid}" ]; then
-   if [ -e "/proc/self/ns/pid" ] && [ -e 
"/proc/${child_pid}/ns/pid" ]; then
-   local n1 n2
-   n1=$(readlink "/proc/self/ns/pid")
-   n2=$(readlink "/proc/${child_pid}/ns/pid")
-   if [ "${n1}" = "${n2}" ]; then
-   return 1
-   fi
-   else
-   return 1
-   fi
-   fi
+   local child_pid start_time
+   child_pid="$(service_get_value "child_pid")"
+   start_time="$(service_get_value "start_time")"
+   if [ -n "${child_pid}" ] && [ -n "${start_time}" ]; then
+   return 1
fi
return 0
 }

diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index 9a094d47..d29f876a 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -128,6 +128,8 @@ print_service(const char *service)
 {
char status[60];
char uptime [40];
+   char *child_pid = NULL;
+   char *start_time = NULL;
int cols =  printf(" %s", service);
const char *c = ecolor(ECOLOR_GOOD);
RC_SERVICE state = rc_service_state(service);
@@ -147,7 +149,14 @@ print_service(const char *service)
rc_service_daemons_crashed(service) &&
errno != EACCES)
{
-   snprintf(status, sizeof(status), " crashed ");
+   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 
");
+   else
+   snprintf(status, sizeof(status), " crashed ");
+   free(child_pid);
+   free(start_time);
} else {
get_uptime(service, uptime, 40);
snprintf(status, sizeof(status), " started %s", uptime);



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

2017-10-25 Thread William Hubbs
commit: a428c325a902bba55a849a07a59c0c1567404db2
Author: William Hubbs  gmail  com>
AuthorDate: Wed Oct 25 20:07:19 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Oct 25 20:09:42 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a428c325

add "unsupervised" status and return code 64 to supervise-daemon status function

This is to be used if the service is being supervised and the
supervisor is somehow killed.

Currently, this is very linux specific, but I will expand to other
platforms, patches are welcome.

 sh/supervise-daemon.sh | 45 -
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 1c1b840d..bccfd06a 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -56,7 +56,50 @@ supervise_stop()
eend $? "Failed to stop ${name:-$RC_SVCNAME}"
 }
 
+_check_supervised()
+{
+   [ "$RC_UNAME" != Linux ] && return 0
+   local child_pid="$(service_get_value "child_pid")"
+   local pid="$(cat ${pidfile})"
+   if [ -n "${child_pid}" ]; then
+   if ! [ -e "/proc/${pid}" ] && [ -e "/proc/${child_pid}" ]; then
+   if [ -e "/proc/self/ns/pid" ] && [ -e 
"/proc/${child_pid}/ns/pid" ]; then
+   local n1 n2
+   n1=$(readlink "/proc/self/ns/pid")
+   n2=$(readlink "/proc/${child_pid}/ns/pid")
+   if [ "${n1}" = "${n2}" ]; then
+   return 1
+   fi
+   fi
+   fi
+   fi
+   return 0
+}
+
 supervise_status()
 {
-   _status
+   if service_stopping; then
+   ewarn "status: stopping"
+   return 4
+   elif service_starting; then
+   ewarn "status: starting"
+   return 8
+   elif service_inactive; then
+   ewarn "status: inactive"
+   return 16
+   elif service_started; then
+   if service_crashed; then
+   if ! _check_supervised; then
+   eerror "status: unsupervised"
+   return 64
+   fi
+   eerror "status: crashed"
+   return 32
+   fi
+   einfo "status: started"
+   return 0
+   else
+   einfo "status: stopped"
+   return 3
+   fi
 }



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

2017-09-29 Thread William Hubbs
commit: 7f3b4139e3a96a15b0fb473b44f422e903e9
Author: William Hubbs  gmail  com>
AuthorDate: Fri Sep 29 17:50:05 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Sep 29 17:51:12 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7f3b4131

use printf consistently in cgroups handling

This makes the cgroups handling consistent between cgroups v1 and v2.
Also, it fixes #167.

 sh/rc-cgroup.sh.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 9e93d841..d48957ac 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -165,7 +165,7 @@ cgroup2_remove()
[ ! -e "${rc_cgroup_path}"/cgroup.events ] &&
return 0
grep -qx "$$" "${rc_cgroup_path}/cgroup.procs" &&
-   echo 0 > "${cgroup_path}/cgroup.procs"
+   printf "%d" 0 > "${cgroup_path}/cgroup.procs"
local key populated vvalue
while read -r key value; do
case "${key}" in
@@ -188,12 +188,12 @@ cgroup2_set_limits()
IFS="
 "
[ ! -d "${rc_cgroup_path}" ] && mkdir "${rc_cgroup_path}"
-   echo 0 > "${rc_cgroup_path}/cgroup.procs"
+   printf "%d" 0 > "${rc_cgroup_path}/cgroup.procs"
echo "${rc_cgroup_settings}" | while IFS="$OIFS" read -r key value; do
[ -z "${key}" ] || [ -z "${value}" ] && continue
[ ! -e "${rc_cgroup_path}/${key}" ] && continue
veinfo "${RC_SVCNAME}: cgroups: ${key} ${value}"
-   echo "${value}" > "${rc_cgroup_path}/${key}"
+   printf "%s" "${value}" > "${rc_cgroup_path}/${key}"
done
IFS="$OIFS"
return 0



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

2017-09-22 Thread William Hubbs
commit: 1ccba056584ee1a8e09fb1d5eebd988b47912c06
Author: William Hubbs  gmail  com>
AuthorDate: Fri Sep 22 22:22:50 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Sep 22 22:22:50 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1ccba056

sh/rc-functions.sh: add need_if_exists convenience function

 sh/rc-functions.sh.in | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in
index 7b771f82..d6336a18 100644
--- a/sh/rc-functions.sh.in
+++ b/sh/rc-functions.sh.in
@@ -119,6 +119,13 @@ get_bootparam_value()
echo $result
 }
 
+need_if_exists()
+{
+   for x; do
+   rc-service --exists "${x}" && need "${x}"
+   done
+}
+
 # Called from openrc-run.sh or gendepends.sh
 _get_containers() {
local c



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

2017-09-18 Thread William Hubbs
commit: cd5722aca50f0eaddde7ce04ee00da53c313ba7d
Author: William Hubbs  gmail  com>
AuthorDate: Sat Sep 16 21:46:42 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Sep 16 21:49:22 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cd5722ac

cgroup2_find_path: use legacy mode if cgroup2 is not in the kernel

This is related to #164.

 sh/rc-cgroup.sh.in | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 930eeefc..9e93d841 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -146,10 +146,12 @@ cgroup_set_limits()
 
 cgroup2_find_path()
 {
-   case "${rc_cgroup_mode:-hybrid}" in
-   hybrid) printf "/sys/fs/cgroup/unified" ;;
-   unified) printf "/sys/fs/cgroup" ;;
+   if grep -qw cgroup2 /proc/filesystems; then
+   case "${rc_cgroup_mode:-hybrid}" in
+   hybrid) printf "/sys/fs/cgroup/unified" ;;
+   unified) printf "/sys/fs/cgroup" ;;
esac
+   fi
return 0
 }
 
@@ -180,7 +182,7 @@ cgroup2_set_limits()
 {
local cgroup_path
cgroup_path="$(cgroup2_find_path)"
-   [ -z "${cgroup_path}" ] && return 0
+   [ -d "${cgroup_path}" ] || return 0
rc_cgroup_path="${cgroup_path}/${RC_SVCNAME}"
local OIFS="$IFS"
IFS="



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

2017-09-15 Thread William Hubbs
commit: 25b45a5a239318fb57c405c3fe64e53b0738ad68
Author: William Hubbs  gmail  com>
AuthorDate: Fri Sep 15 19:22:34 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Sep 15 19:22:34 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=25b45a5a

cgroup_cleanup: try to remove the cgroup version 2 cgroup

If we were able to kill all the processes in the cgroup, it should be
removed.

 sh/rc-cgroup.sh.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 2a54ee4a..930eeefc 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -212,6 +212,7 @@ cgroup_cleanup()
yesno "${rc_send_sigkill:-yes}" &&
kill -s KILL ${pids} 2> /dev/null
fi
+   cgroup2_remove
[ -z "$(cgroup_get_pids)" ]
eend $? "Unable to stop all processes"
return 0



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

2017-09-15 Thread William Hubbs
commit: 4651b8c7e9e2ef9c1ea1fb8d174d1ca4693627af
Author: William Hubbs  gmail  com>
AuthorDate: Fri Sep 15 18:42:50 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Sep 15 18:42:50 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4651b8c7

rc-cgroup.sh: cgroup_cleanup fix error handling

cgroup_cleanup should warn if it is unable to clean up all processes in
the control group, but it will always return success.

 sh/rc-cgroup.sh.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 3c7558cd..2a54ee4a 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -212,5 +212,7 @@ cgroup_cleanup()
yesno "${rc_send_sigkill:-yes}" &&
kill -s KILL ${pids} 2> /dev/null
fi
-   eend 0
+   [ -z "$(cgroup_get_pids)" ]
+   eend $? "Unable to stop all processes"
+   return 0
 }



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

2017-09-15 Thread William Hubbs
commit: 50608b54ed98acb54fec5fe3323909ea684d3af9
Author: William Hubbs  gmail  com>
AuthorDate: Fri Sep 15 18:27:49 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Sep 15 18:28:15 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=50608b54

rc-cgroup.sh: fix signal names

The "SIG" prefix on signal names passed to kill -s isn't portable.

 sh/rc-cgroup.sh.in | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 4b713594..3c7558cd 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -204,13 +204,13 @@ cgroup_cleanup()
local pids
pids="$(cgroup_get_pids)"
if [ -n "${pids}" ]; then
-   kill -s "${stopsig:-SIGTERM}" ${pids} 2> /dev/null
-   kill -s SIGCONT ${pids} 2> /dev/null
+   kill -s "${stopsig:-TERM}" ${pids} 2> /dev/null
+   kill -s CONT ${pids} 2> /dev/null
yesno "${rc_send_sighup:-no}" &&
-   kill -s SIGHUP ${pids} 2> /dev/null
+   kill -s HUP ${pids} 2> /dev/null
sleep "${rc_timeout_stopsec:-90}"
yesno "${rc_send_sigkill:-yes}" &&
-   kill -s SIGKILL ${pids} 2> /dev/null
+   kill -s KILL ${pids} 2> /dev/null
fi
eend 0
 }



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

2017-09-15 Thread William Hubbs
commit: 6a5ca2ab368d0a85f51bb559672dba2e3ffcc6be
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 14 16:40:26 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 14 21:17:20 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6a5ca2ab

make the procedure for killing child processes of services configurable

 etc/rc.conf| 29 ++---
 sh/rc-cgroup.sh.in | 13 -
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/etc/rc.conf b/etc/rc.conf
index d9ad911d..b7296d35 100644
--- a/etc/rc.conf
+++ b/etc/rc.conf
@@ -277,10 +277,33 @@ rc_tty_number=12
 
 # Set this to YES if you want all of the processes in a service's cgroup
 # killed when the service is stopped or restarted.
-# This should not be set globally because it kills all of the service's
-# child processes, and most of the time this is undesirable. Please set
-# it in /etc/conf.d/.
+# Be aware that setting this to yes means all of a service's
+# child processes will be killed. Keep this in mind if you set this to
+# yes here instead of for the individual services in
+# /etc/conf.d/.
 # To perform this cleanup manually for a stopped service, you can
 # execute cgroup_cleanup with /etc/init.d/ cgroup_cleanup or
 # rc-service  cgroup_cleanup.
+# The process followed in this cleanup is the following:
+# 1. send stopsig (sigterm if it isn't set) to all processes left in the
+# cgroup immediately followed by sigcont.
+# 2. Send sighup to all processes in the cgroup if rc_send_sighup is
+# yes.
+# 3. delay for rc_timeout_stopsec seconds.
+# 4. send sigkill to all processes in the cgroup unless disabled by
+# setting rc_send_sigkill to no.
 # rc_cgroup_cleanup="NO"
+
+# If this is yes, we will send sighup to the processes in the cgroup
+# immediately after stopsig and sigcont.
+#rc_send_sighup="NO"
+
+# This is the amount of time in seconds that we delay after sending sigcont
+# and optionally sighup, before we optionally send sigkill to all
+# processes in the # cgroup.
+# The default is 90 seconds.
+#rc_timeout_stopsec="90"
+
+# If this is set to no, we do not send sigkill to all processes in the
+# cgroup.
+#rc_send_sigkill="YES"

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 47a007b6..4b713594 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -204,10 +204,13 @@ cgroup_cleanup()
local pids
pids="$(cgroup_get_pids)"
if [ -n "${pids}" ]; then
-   kill -s TERM "${pids}"
-   sleep 1
-   pids="$(cgroup_get_pids)"
-   [ -n "${pids}" ] &&
-   kill -s KILL "${pids}"
+   kill -s "${stopsig:-SIGTERM}" ${pids} 2> /dev/null
+   kill -s SIGCONT ${pids} 2> /dev/null
+   yesno "${rc_send_sighup:-no}" &&
+   kill -s SIGHUP ${pids} 2> /dev/null
+   sleep "${rc_timeout_stopsec:-90}"
+   yesno "${rc_send_sigkill:-yes}" &&
+   kill -s SIGKILL ${pids} 2> /dev/null
fi
+   eend 0
 }



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

2017-09-14 Thread William Hubbs
commit: 2b0345165e5af57ca61a4000c3671bbe6d677cf9
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 14 15:55:06 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 14 15:55:06 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=2b034516

Make cgroup_cleanup send only one sigterm and sigkill

Instead of looping and sending multiple signals to child processes in
cgroup_cleanup, we send sigterm followed by sleeping one second then
sigkill.

This brings us more in line with systemd's "control group" killmode
setting.

Also, this commit includes several shellcheck cleanups.

 sh/openrc-run.sh.in |  6 ++---
 sh/rc-cgroup.sh.in  | 72 +
 2 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index e778bd09..05cb972b 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -365,9 +365,9 @@ while [ -n "$1" ]; do
then
"$1"_post || exit $?
fi
-   [ "$(command -v cgroup_cleanup)" = 
"cgroup_cleanup" -a \
-   "$1" = "stop" ] && \
-   yesno "${rc_cgroup_cleanup}" && \
+   [ "$(command -v cgroup_cleanup)" = 
"cgroup_cleanup" ] &&
+   [ "$1" = "stop" ] &&
+   yesno "${rc_cgroup_cleanup}" && \
cgroup_cleanup
if [ "$(command -v cgroup2_remove)" = 
"cgroup2_remove" ]; then
[ "$1" = stop ] || [ -z "${command}" ] 
&&

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 1bf819e7..47a007b6 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -14,46 +14,56 @@ description_cgroup_cleanup="Kill all processes in the 
cgroup"
 
 cgroup_find_path()
 {
-   local OIFS n name dir result
+   local OIFS name dir result
[ -n "$1" ] || return 0
OIFS="$IFS"
IFS=":"
-   while read n name dir; do
+   while read -r _ name dir; do
[ "$name" = "$1" ] && result="$dir"
done < /proc/1/cgroup
IFS="$OIFS"
-   echo $result
+   printf "%s" "${result}"
 }
 
 cgroup_get_pids()
 {
-   local p
-   pids=
-   while read p; do
-   [ $p -eq $$ ] || pids="${pids} ${p}"
-   done < /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks
-   [ -n "$pids" ]
+   local cgroup_procs p pids
+   cgroup_procs="$(cgroup2_find_path)"
+   [ -n "${cgroup_procs}" ] &&
+   cgroup_procs="${cgroup_procs}/${RC_SVCNAME}/cgroup.procs" ||
+   cgroup_procs="/sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks"
+   [ -f "${cgroup_procs}" ] || return 0
+   while read -r p; do
+   [ "$p" -eq $$ ] || pids="${pids} ${p}"
+   done < "${cgroup_procs}"
+   printf "%s" "${pids}"
+   return 0
 }
 
 cgroup_running()
 {
-   [ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
+   [ -d "/sys/fs/cgroup/unified/${RC_SVCNAME}" ] ||
+   [ -d "/sys/fs/cgroup/${RC_SVCNAME}" ] ||
+   [ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
 }
 
 cgroup_set_values()
 {
-   [ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0
+   [ -n "$1" ] && [ -n "$2" ] && [ -d "/sys/fs/cgroup/$1" ] || return 0
 
-   local controller="$1" h=$(cgroup_find_path "$1")
+   local controller h
+   controller="$1"
+   h=$(cgroup_find_path "$1")
cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
[ -d "$cgroup" ] || mkdir -p "$cgroup"
 
set -- $2
local name val
-   while [ -n "$1" -a "$controller" != "cpuacct" ]; do
+   while [ -n "$1" ] && [ "$controller" != "cpuacct" ]; do
case "$1" in
$controller.*)
-   if [ -n "$name" -a -w "$cgroup/$name" -a -n 
"$val" ]; then
+   if [ -n "${name}" ] && [ -w "${cgroup}/${name}" 
] && 
+   [ -n "${val}" ]; then
veinfo "$RC_SVCNAME: Setting 
$cgroup/$name to $val"
printf "%s" "$val" > "$cgroup/$name"
fi
@@ -68,7 +78,7 @@ cgroup_set_values()
esac
shift
done
-   if [ -n "$name" -a -w "$cgroup/$name" -a -n "$val" ]; then
+   if [ -n "${name}" ] && [ -w "${cgroup}/${name}" ] && [ -n "${val}" ]; 
then
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
printf "%s" "$val" > "$cgroup/$name"
fi
@@ -145,7 +155,8 @@ cgroup2_find_path()
 
 cgroup2_remove()
 {
-   local cgroup_path="$(cgroup2_find_path)" rc_cgroup_path
+   local cgroup_path rc_cgroup_path

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

2017-09-14 Thread William Hubbs
commit: 457f928e793cb1f6ef254935ad07f58b8762c72f
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 14 15:38:10 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 14 15:38:10 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=457f928e

add support for control groups version 2

This is for #94.

 etc/rc.conf |  45 +++
 init.d/sysfs.in | 100 +++-
 sh/openrc-run.sh.in |  15 +---
 sh/rc-cgroup.sh.in  |  51 +++
 4 files changed, 182 insertions(+), 29 deletions(-)

diff --git a/etc/rc.conf b/etc/rc.conf
index 689e6be2..d9ad911d 100644
--- a/etc/rc.conf
+++ b/etc/rc.conf
@@ -191,13 +191,43 @@ rc_tty_number=12
 ##
 # LINUX CGROUPS RESOURCE MANAGEMENT
 
-# If you have cgroups turned on in your kernel, this switch controls
-# whether or not a group for each controller is mounted under
-# /sys/fs/cgroup.
-# None of the other options in this section work if this is set to "NO".
+# This sets the mode used to mount cgroups.
+# "hybrid" mounts cgroups version 2 on /sys/fs/cgroup/unified and
+# cgroups version 1 on /sys/fs/cgroup.
+# "legacy" mounts cgroups version 1 on /sys/fs/cgroup
+# "unified" mounts cgroups version 2 on /sys/fs/cgroup
+#rc_cgroup_mode="hybrid"
+
+# This is a list of controllers which should be enabled for cgroups version 2.
+# If hybrid mode is being used, controllers listed here will not be
+# available for cgroups version 1.
+# This is a global setting.
+#rc_cgroup_controllers=""
+
+# This variable contains the cgroups version 2 settings for your services.
+# If this is set in this file, the settings will apply to all services.
+# If you want different settings for each service, place the settings in
+# /etc/conf.d/foo for service foo.
+# The format is to specify the setting and value followed by a newline.
+# Multiple settings and values can be specified.
+# For example, you would use this to set the maximum memory and maximum
+# number of pids for a service.
+#rc_cgroup_settings="
+#memory.max 10485760
+#pids.max max
+#"
+#
+# For more information about the adjustments that can be made with
+# cgroups version 2, see Documentation/cgroups-v2.txt in the linux kernel
+# source tree.
+#rc_cgroup_settings=""
+
+# This switch controls whether or not cgroups version 1 controllers are
+# individually mounted under
+# /sys/fs/cgroup in hybrid or legacy mode.
 #rc_controller_cgroups="YES"
 
-# The following settings allow you to set up values for the cgroup
+# The following settings allow you to set up values for the cgroups version 1
 # controllers for your services.
 # They can be set in this file;, however, if you do this, the settings
 # will apply to all of your services.
@@ -211,8 +241,9 @@ rc_tty_number=12
 # cpu.shares 512
 # "
 #
-#For more information about the adjustments that can be made with
-#cgroups, see Documentation/cgroups/* in the linux kernel source tree.
+# For more information about the adjustments that can be made with
+# cgroups version 1, see Documentation/cgroups-v1/* in the linux kernel
+# source tree.
 
 # Set the blkio controller settings for this service.
 #rc_cgroup_blkio=""

diff --git a/init.d/sysfs.in b/init.d/sysfs.in
index a2538114..9f39fb57 100644
--- a/init.d/sysfs.in
+++ b/init.d/sysfs.in
@@ -107,20 +107,16 @@ mount_misc()
fi
 }
 
-mount_cgroups()
+cgroup1_base()
 {
-   # set up kernel support for cgroups
-   if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then
-   if grep -qs cgroup /proc/filesystems; then
-   ebegin "Mounting cgroup filesystem"
-   local 
opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}"
-   mount -n -t tmpfs -o ${opts} cgroup_root /sys/fs/cgroup
-   eend $?
-   fi
+   grep -qw cgroup /proc/filesystems || return 0
+   if ! mountinfo -q /sys/fs/cgroup; then
+   ebegin "Mounting cgroup filesystem"
+   local opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}"
+   mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
+   eend $?
fi
 
-   mountinfo -q /sys/fs/cgroup || return 0
-
if ! mountinfo -q /sys/fs/cgroup/openrc; then
local agent="@LIBEXECDIR@/sh/cgroup-release-agent.sh"
mkdir /sys/fs/cgroup/openrc
@@ -129,17 +125,87 @@ mount_cgroups()
openrc /sys/fs/cgroup/openrc
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
fi
+   return 0
+}
 
-   yesno ${rc_controller_cgroups:-YES} && [ -e /proc/cgroups ] || return 0
-   while read name hier groups enabled rest; do
+cgroup1_controllers()
+{
+   yesno "${rc_controller_cgroups:-YES}" && [ -e /proc/cgroups ] || return 0
+   while read -r name _ _ enabled 

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

2017-09-14 Thread William Hubbs
commit: 8885580986ab8adc951fe32b9323c8b16130fb4f
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 14 15:44:52 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 14 15:44:52 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=88855809

rc-cgroup.sh: move cgroup_cleanup to the end of the file

 sh/rc-cgroup.sh.in | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 40501f22..1bf819e7 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -134,25 +134,6 @@ cgroup_set_limits()
return 0
 }
 
-cgroup_cleanup()
-{
-   cgroup_running || return 0
-   ebegin "starting cgroups cleanup"
-   for sig in TERM QUIT INT; do
-   cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
-   for i in 0 1; do
-   kill -s $sig $pids
-   for j in 0 1 2; do
-   cgroup_get_pids || { eend 0 "finished" ; return 
0 ; }
-   sleep 1
-   done
-   done 2>/dev/null
-   done
-   cgroup_get_pids || { eend 0 "finished" ; return 0; }
-   kill -9 $pids
-   eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes"
-}
-
 cgroup2_find_path()
 {
case "${rc_cgroup_mode:-hybrid}" in
@@ -203,3 +184,22 @@ cgroup2_set_limits()
IFS="$OIFS"
return 0
 }
+
+cgroup_cleanup()
+{
+   cgroup_running || return 0
+   ebegin "starting cgroups cleanup"
+   for sig in TERM QUIT INT; do
+   cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
+   for i in 0 1; do
+   kill -s $sig $pids
+   for j in 0 1 2; do
+   cgroup_get_pids || { eend 0 "finished" ; return 
0 ; }
+   sleep 1
+   done
+   done 2>/dev/null
+   done
+   cgroup_get_pids || { eend 0 "finished" ; return 0; }
+   kill -9 $pids
+   eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes"
+}



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

2017-08-15 Thread William Hubbs
commit: 66ed8082d0c865a0b4f4cc436cf9e13351e3d6fe
Author: William Hubbs  gmail  com>
AuthorDate: Tue Aug 15 22:15:14 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Aug 15 22:15:14 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=66ed8082

sh/openrc-run: source service script before ulimit is processed

This is needed to allow the service script author to set a default for
rc_ulimit inside the service script.

 sh/openrc-run.sh.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index f5ffe17e..a38d46d6 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -243,6 +243,9 @@ sourcex "@LIBEXECDIR@/sh/s6.sh"
 sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
 sourcex "@LIBEXECDIR@/sh/supervise-daemon.sh"
 
+# Load our script
+sourcex "$RC_SERVICE"
+
 # Set verbose mode
 if yesno "${rc_verbose:-$RC_VERBOSE}"; then
EINFO_VERBOSE=yes
@@ -272,9 +275,6 @@ for _cmd; do
fi
 done
 
-# Load our script
-sourcex "$RC_SERVICE"
-
 eval "printf '%s\n' $required_dirs" | while read _d; do
if [ -n "$_d" ] && [ ! -d "$_d" ]; then
eerror "$RC_SVCNAME: \`$_d' is not a directory"



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

2017-05-09 Thread William Hubbs
commit: 3673040722b75c0a4d06fbeb272f917c7d1ea7c4
Author: William Hubbs  gmail  com>
AuthorDate: Tue May  9 23:20:52 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue May  9 23:30:08 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=36730407

supervise-daemon: add a --respawn-limit option

Allow limiting the number of times supervise-daemon will attempt to respawn a
daemon once it has died to prevent infinite respawning. Also, set a
reasonable default limit (10 times in a 5 second period).

This is for issue #126.

 man/openrc-run.8  |  6 ++
 man/supervise-daemon.8| 20 
 sh/supervise-daemon.sh|  1 +
 src/rc/supervise-daemon.c | 37 -
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 25ec5b91..c7ac2ac1 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -167,6 +167,12 @@ Display name used for the above defined command.
 Process name to match when signaling the daemon.
 .It Ar stopsig
 Signal to send when stopping the daemon.
+.It Ar respawn_limit
+Respawn limit
+.Xr supervise-daemon 8
+will use for this daemon.  See
+.Xr supervise-daemon 8
+for more information about this setting.
 .It Ar retry
 Retry schedule to use when stopping the daemon. It can either be a
 timeout in seconds or multiple signal/timeout pairs (like SIGTERM/5).

diff --git a/man/supervise-daemon.8 b/man/supervise-daemon.8
index 06087675..43e74ef7 100644
--- a/man/supervise-daemon.8
+++ b/man/supervise-daemon.8
@@ -34,6 +34,8 @@
 .Ar user
 .Fl r , -chroot
 .Ar chrootpath
+.Fl R , -respawn-limit
+.Ar limit
 .Fl 1 , -stdout
 .Ar logfile
 .Fl 2 , -stderr
@@ -99,6 +101,24 @@ Modifies the scheduling priority of the daemon.
 .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.
+.It Fl R , -respawn-limit Ar limit
+Control how agressively
+.Nm
+will try to respawn a daemon when it fails to start. The limit argument
+can be a pair of integers separated bya colon or the string unlimited.
+.Pp
+If a pair of integers is given, the first is a maximum number of respawn
+attempts and the second is a time period. It should be interpreted as:
+If the daemon dies and has to be respawned more than 
+times in any time period of  seconds, exit and give up.
+.Pp
+For example, the default is 10:5.
+This means if the supervisor respawns a daemon more than ten times
+in any 5 second period, it gives up and exits.
+.Pp
+if unlimited is given as the limit, it means that the supervisor will
+not exit or give up, no matter how many times the daemon it is
+supervising needs to be respawned.
 .It Fl u , -user Ar user
 Start the daemon as the specified user.
 .It Fl 1 , -stdout Ar logfile

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index bff68a4c..c6130edb 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -25,6 +25,7 @@ supervise_start()
eval supervise-daemon --start \
${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
+   ${respawn_limit:+--respawn-limit} $respawn_limit \
${command_user+--user} $command_user \
$supervise_daemon_args \
$command \

diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c
index 2080e4a6..bd24d782 100644
--- a/src/rc/supervise-daemon.c
+++ b/src/rc/supervise-daemon.c
@@ -66,7 +66,7 @@ static struct pam_conv conv = { NULL, NULL};
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "d:e:g:I:Kk:N:p:r:Su:1:2:" \
+const char *getoptstring = "d:e:g:I:Kk:N:p:r:R:Su:1:2:" \
getoptstring_COMMON;
 const struct option longopts[] = {
{ "chdir",1, NULL, 'd'},
@@ -79,6 +79,7 @@ const struct option longopts[] = {
{ "pidfile",  1, NULL, 'p'},
{ "user", 1, NULL, 'u'},
{ "chroot",   1, NULL, 'r'},
+   { "respawn-limit",1, NULL, 'R'},
{ "start",0, NULL, 'S'},
{ "stdout",   1, NULL, '1'},
{ "stderr",   1, NULL, '2'},
@@ -95,6 +96,7 @@ const char * const longopts_help[] = {
"Match pid found in this file",
"Change the process user",
"Chroot to this directory",
+   "set a respawn limit",
"Start daemon",
"Redirect stdout to file",
"Redirect stderr to file",
@@ -424,7 +426,13 @@ int main(int argc, char **argv)
char *p;
char *token;
int i;
+   int n;
char exec_file[PATH_MAX];
+   int respawn_count = 0;
+   int respawn_max = 10;
+   int respawn_period = 5;
+   time_t respawn_now= 0;
+   time_t first_spawn= 0;
struct passwd *pw;
struct group *gr;
FILE *fp;
@@ -519,6 +527,17 @@ int main(int argc, char **argv)
  

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

2017-03-23 Thread William Hubbs
commit: 50fccf47d4bd2ed6e7ea6ff7f72577c8e7b95d0d
Author: William Hubbs  gmail  com>
AuthorDate: Thu Mar 23 18:17:11 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Mar 23 18:17:11 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=50fccf47

sh/gendepends.sh.in: fix detection of service scripts

We do not need to care about the path on the shebang line of a service
script as long as the shebang line ends with "openrc-run".
This fixes #119 and #120.

 sh/gendepends.sh.in | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
index 82088c51..45147e6a 100644
--- a/sh/gendepends.sh.in
+++ b/sh/gendepends.sh.in
@@ -74,11 +74,22 @@ do
 
# Only generate dependencies for OpenRC scripts
read one two three <"$RC_SERVICE"
-   [ "$one" = "#!@SBINDIR@/runscript" ] || \
-   [ "$one" = "#!@SBINDIR@/openrc-run" ] || \
-   [ "$one" = "#!" -a "$two" = "@SBINDIR@/runscript" ] || \
-   [ "$one" = "#!" -a "$two" = "@SBINDIR@/openrc-run" ] || \
-   continue
+   case "$one" in
+   \#*/openrc-run) ;;
+   \#*/runscript) ;;
+   \#!)
+   case "$two" in
+   */openrc-run) ;;
+   */runscript) ;;
+   *)
+   continue
+   ;;
+   esac
+   ;;
+   *)
+   continue
+   ;;
+   esac
unset one two three
 
RC_SVCNAME=${RC_SERVICE##*/} ; export RC_SVCNAME



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

2017-02-23 Thread William Hubbs
commit: 1cb44092fce298004ab4c4547c6fbcac29c5997f
Author: William Hubbs  gmail  com>
AuthorDate: Thu Feb 23 18:50:33 2017 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Feb 24 00:16:15 2017 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1cb44092

sh/rc-functions.sh.in: add get_bootparam_value function

 sh/rc-functions.sh.in | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in
index 12eb4e2a..7b771f82 100644
--- a/sh/rc-functions.sh.in
+++ b/sh/rc-functions.sh.in
@@ -85,6 +85,40 @@ get_bootparam()
return 1
 }
 
+get_bootparam_value()
+{
+   local match="$1" which_value="$2" sep="$3" result value
+   if [ -n "$match" -a -r /proc/cmdline ]; then
+   set -- $(cat /proc/cmdline)
+   while [ -n "$1" ]; do
+   case "$1" in
+   $match=*)
+   value="${1##*=}"
+   case "$which_value" in
+   all)
+   [ -z "$sep" ] && sep=' '
+   if [ -z "$result" ]; 
then
+   result="$value"
+   else
+   
result="${result}${sep}${value}"
+   fi
+   ;;
+   last)
+   result="$value"
+   ;;
+   *)
+   result="$value"
+   break
+   ;;
+   esac
+   ;;
+   esac
+   shift
+   done
+   fi
+   echo $result
+}
+
 # Called from openrc-run.sh or gendepends.sh
 _get_containers() {
local c



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

2016-12-18 Thread William Hubbs
commit: d3f833179b39368442221c448f90b87f76d28ee8
Author: William Hubbs  gmail  com>
AuthorDate: Sun Dec 18 17:52:54 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Dec 18 17:53:12 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d3f83317

sh/init.sh.Linux.in: remove unused check for Gnu/KFreeBSD

This script only runs on Linux, so the check will always be false.

 sh/init.sh.Linux.in | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index 96555d2..b07463b 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -44,11 +44,9 @@ fi
 unset f
 
 if $mountproc; then
-   procfs="proc"
-   [ "$RC_UNAME" = "GNU/kFreeBSD" ] && procfs="linprocfs"
ebegin "Mounting /proc"
if ! fstabinfo --mount /proc; then
-   mount -n -t "$procfs" -o noexec,nosuid,nodev proc /proc
+   mount -n -t proc -o noexec,nosuid,nodev proc /proc
fi
eend $?
 fi



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

2016-12-18 Thread William Hubbs
commit: 856eafb006655b7dda630a94cbd16f5db9f781be
Author: Doug Freed  mtu  edu>
AuthorDate: Sat Dec 17 19:59:45 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Dec 17 23:27:37 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=856eafb0

sh/init.sh.Linux.in: skip /proc test if no md5sum

This will also warn users if md5sum is missing, which serves as a pretty
good indicator that /usr is not mounted.

 sh/init.sh.Linux.in | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index fcae0d2..96555d2 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -11,6 +11,16 @@ if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
done
 fi
 
+# check for md5sum, and probably /usr too
+if command -v md5sum >/dev/null; then
+   got_md5sum=true
+else
+   eerror "md5sum is missing, which suggests /usr is not mounted"
+   eerror "If you have separate /usr, it must be mounted by initramfs"
+   eerror "If not, you should check coreutils is installed correctly"
+   got_md5sum=false
+fi
+
 # By default VServer already has /proc mounted, but OpenVZ does not!
 # However, some of our users have an old proc image in /proc
 # NFC how they managed that, but the end result means we have to test if
@@ -21,9 +31,12 @@ fi
 mountproc=true
 f=/proc/self/environ
 if [ -e $f ]; then
-   if [ "$(VAR=a md5sum $f)" = "$(VAR=b md5sum $f)" ]; then
+   if $got_md5sum && [ "$(VAR=a md5sum $f)" = "$(VAR=b md5sum $f)" ]; then
eerror "You have cruft in /proc that should be deleted"
else
+   # If they don't have md5sum, this will fail in pretty ways if
+   # /proc isn't really mounted.  Oh well, their system is busted
+   # anyway, and they get to keep the pieces.
einfo "/proc is already mounted"
mountproc=false
fi



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

2016-12-17 Thread William Hubbs
commit: f27d60add9ee1ef8a90ea0034edf6f4e4e6d0ed8
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Thu Dec 15 22:43:34 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Dec 17 22:50:11 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f27d60ad

sh/openrc-run.sh: expose default start/stop/status

Supervisor setups break easily when start/stop/status functions are not
default.

Applications that write multiple PIDs to a pidfile (eg HAProxy as
described in bug 601540), can also benefit from being able to call the
default start/stop/status with modified environment variables.

Expose the default start/stop/status functions as
default_start/stop/status, and use them for the defaults
start/stop/status.

Trivial usage example:
```
  stop()
  {
t=$(mktemp)
for pid in $(cat $pidfile) ; do
  echo $pid >$t
  pidfile=$t default_stop
done
rm -f $t
  }
```

X-Gentoo-Bug: 601540
X-Gentoo-Bug-URL: https://bugs.gentoo.org/601540
Signed-off-by: Robin H. Johnson  gentoo.org>

 sh/openrc-run.sh.in | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 4cbfb16..f5ffe17 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -146,10 +146,9 @@ _status()
fi
 }
 
-# Template start / stop / status functions
 # These functions select the appropriate function to call from the
 # supervisor modules
-start()
+default_start()
 {
local func=ssd_start
case "$supervisor" in
@@ -163,7 +162,7 @@ start()
$func
 }
 
-stop()
+default_stop()
 {
local func=ssd_stop
case "$supervisor" in
@@ -177,7 +176,7 @@ stop()
$func
 }
 
-status()
+default_status()
 {
local func=ssd_status
case "$supervisor" in
@@ -191,6 +190,26 @@ status()
$func
 }
 
+# Template start / stop / status functions
+# package init scripts may override these, but the bodies are as minimal as
+# possible, so that the init scripts can creatively wrap default_*
+# functions.
+start()
+{
+   default_start
+}
+
+stop()
+{
+   default_stop
+}
+
+status()
+{
+   default_status
+}
+
+# Start debug output
 yesno $RC_DEBUG && set -x
 
 # Load configuration settings. First the global ones, then any



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

2016-12-17 Thread William Hubbs
commit: 8ad460c54ce66aa0900cf872d9ebfacf0c03f9da
Author: Doug Freed  mtu  edu>
AuthorDate: Sat Dec 17 18:41:02 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Dec 17 18:41:02 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8ad460c5

Fix typos

Fixes #99

 etc/rc.shutdown.in  | 2 +-
 sh/init.sh.Linux.in | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/etc/rc.shutdown.in b/etc/rc.shutdown.in
index b85a962..de3e09b 100644
--- a/etc/rc.shutdown.in
+++ b/etc/rc.shutdown.in
@@ -14,7 +14,7 @@ trap : SIGINT SIGQUIT
 
 # Try and use stuff in /lib over anywhere else so we can shutdown
 # local mounts correctly.
-LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}" ; export 
LD_LIBRARY_PATH
+LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" ; export 
LD_LIBRARY_PATH
 
 # If $TERM is not set then assume default of @TERM@
 # This gives us a nice colour boot :)

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index 7645775..fcae0d2 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -32,7 +32,7 @@ unset f
 
 if $mountproc; then
procfs="proc"
-   [ "$RC_UNAME" = "GNU/kFreeBSD" ] && proc="linprocfs"
+   [ "$RC_UNAME" = "GNU/kFreeBSD" ] && procfs="linprocfs"
ebegin "Mounting /proc"
if ! fstabinfo --mount /proc; then
mount -n -t "$procfs" -o noexec,nosuid,nodev proc /proc



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

2016-12-01 Thread William Hubbs
commit: e0ac661419042cb39c1ccf93df2981504d1e6339
Author: William Hubbs  gmail  com>
AuthorDate: Tue Nov 15 00:12:06 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Dec  1 18:04:54 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e0ac6614

split tmpfiles processing into opentmpfiles

The openntmpfiles package is designed so that it can be used on systems
independently of whether openrc is used.

 NEWS.md  |   8 +
 conf.d/Makefile  |   3 +-
 conf.d/tmpfiles  |   3 -
 init.d/.gitignore|   2 -
 init.d/Makefile  |   6 +-
 init.d/tmpfiles.dev.in   |  20 ---
 init.d/tmpfiles.setup.in |  19 --
 runlevels/Makefile   |   3 +-
 sh/.gitignore|   1 -
 sh/Makefile  |   4 +-
 sh/tmpfiles.sh.in| 457 ---
 11 files changed, 15 insertions(+), 511 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index 931d0ab..6027aa0 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -3,6 +3,14 @@
 This file will contain a list of notable changes for each release. Note
 the information in this file is in reverse order.
 
+## OpenRC-0.23
+
+The tmpfiles.d processing code, which was part of previous versions of
+OpenRC, has been separated into its own package [1]. If you need to
+process systemd style tmpfiles.d files, please install this package.
+
+[1] https://github.com/openrc/opentmpfiles
+
 ## OpenRC-0.22
 
 In previous versions of OpenRC, configuration information was processed

diff --git a/conf.d/Makefile b/conf.d/Makefile
index a18ca74..6c7962b 100644
--- a/conf.d/Makefile
+++ b/conf.d/Makefile
@@ -1,8 +1,7 @@
 include ../mk/net.mk
 
 DIR=   ${CONFDIR}
-CONF=  bootmisc fsck hostname localmount netmount swap urandom tmpfiles \
-   ${CONF-${OS}}
+CONF=  bootmisc fsck hostname localmount netmount swap urandom ${CONF-${OS}}
 
 ifeq (${MKNET},yes)
 CONF+= network staticroute

diff --git a/conf.d/tmpfiles b/conf.d/tmpfiles
deleted file mode 100644
index c3f208f..000
--- a/conf.d/tmpfiles
+++ /dev/null
@@ -1,3 +0,0 @@
-# Extra options for tmpfiles.sh
-#tmpfiles_opts="--verbose"
-tmpfiles_opts=""

diff --git a/init.d/.gitignore b/init.d/.gitignore
index 98748c7..b8cbb48 100644
--- a/init.d/.gitignore
+++ b/init.d/.gitignore
@@ -45,5 +45,3 @@ syslogd
 termencoding
 ttys
 wscons
-tmpfiles.dev
-tmpfiles.setup

diff --git a/init.d/Makefile b/init.d/Makefile
index bec4eaf..75c88ad 100644
--- a/init.d/Makefile
+++ b/init.d/Makefile
@@ -2,8 +2,8 @@ include ../mk/net.mk
 
 DIR=   ${INITDIR}
 SRCS=  bootmisc.in fsck.in hostname.in local.in localmount.in loopback.in \
-   netmount.in osclock.in root.in savecache.in swap.in tmpfiles.setup.in  \
-   swclock.in sysctl.in runsvdir.in urandom.in s6-svscan.in ${SRCS-${OS}}
+   netmount.in osclock.in root.in savecache.in swap.in swclock.in \
+   sysctl.in runsvdir.in urandom.in s6-svscan.in ${SRCS-${OS}}
 BIN=   ${OBJS}
 
 # Are we installing our network scripts?
@@ -23,7 +23,7 @@ SRCS-FreeBSD+=adjkerntz.in devd.in dumpon.in 
encswap.in ipfw.in \
 
 SRCS-Linux=binfmt.in devfs.in dmesg.in hwclock.in consolefont.in 
keymaps.in \
killprocs.in modules.in modules-load.in mount-ro.in mtab.in 
numlock.in \
-   procfs.in net-online.in sysfs.in termencoding.in tmpfiles.dev.in
+   procfs.in net-online.in sysfs.in termencoding.in
 
 # Generic BSD scripts
 SRCS-NetBSD=   hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \

diff --git a/init.d/tmpfiles.dev.in b/init.d/tmpfiles.dev.in
deleted file mode 100644
index c70a29e..000
--- a/init.d/tmpfiles.dev.in
+++ /dev/null
@@ -1,20 +0,0 @@
-#!@SBINDIR@/openrc-run
-# Copyright 1999-2012 Gentoo Foundation
-# Released under the 2-clause BSD license.
-
-description="Set up tmpfiles.d entries"
-
-depend()
-{
-   use dev-mount
-   before dev
-   keyword -prefix -vserver
-}
-
-start()
-{
-   ebegin "Setting up tmpfiles.d entries for /dev"
-   @LIBEXECDIR@/sh/tmpfiles.sh --prefix=/dev --create --boot 
${tmpfiles_opts}
-   eend $?
-   return 0
-}

diff --git a/init.d/tmpfiles.setup.in b/init.d/tmpfiles.setup.in
deleted file mode 100644
index 5872fea..000
--- a/init.d/tmpfiles.setup.in
+++ /dev/null
@@ -1,19 +0,0 @@
-#!@SBINDIR@/openrc-run
-# Copyright 1999-2012 Gentoo Foundation
-# Released under the 2-clause BSD license.
-
-description="Set up tmpfiles.d entries"
-
-depend()
-{
-   need localmount
-}
-
-start()
-{
-   ebegin "Setting up tmpfiles.d entries"
-   @LIBEXECDIR@/sh/tmpfiles.sh --exclude-prefix=/dev --create --remove 
--boot \
-   ${tmpfiles_opts}
-   eend $?
-   return 0
-}

diff --git a/runlevels/Makefile b/runlevels/Makefile
index 6abd8c5..103577a 100644
--- a/runlevels/Makefile
+++ b/runlevels/Makefile
@@ -37,9 +37,8 @@ BOOT-FreeBSD+=hostid modules newsyslog savecore 
syslogd
 BOOT-FreeBSD+= adjkerntz dumpon syscons
 
 BOOT-Linux+=   binfm

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

2016-09-22 Thread William Hubbs
commit: bbf98befb86337a36ef5af7f273e503a6de4b9bd
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 22 22:22:03 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 22 22:37:09 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=bbf98bef

sh/init.sh.Linux.in: update test for live /proc to use md5sum

This allows us to avoid the warnings from bash-4.4 about null bytes in
command substitutions.

If you have separate /usr, are not using an initramfs, and have a file
called /proc/self/environ on your root file system, this will break.
X-Gentoo-Bug: 594534
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=594534

 sh/init.sh.Linux.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index 344f627..7645775 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -21,7 +21,7 @@ fi
 mountproc=true
 f=/proc/self/environ
 if [ -e $f ]; then
-   if [ "$(VAR=a cat $f)" = "$(VAR=b cat $f)" ]; then
+   if [ "$(VAR=a md5sum $f)" = "$(VAR=b md5sum $f)" ]; then
eerror "You have cruft in /proc that should be deleted"
else
einfo "/proc is already mounted"



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

2016-09-20 Thread William Hubbs
commit: d6c30ab12a3b335ac57cd1f0ac00231bb34fc0c4
Author: William Hubbs  gmail  com>
AuthorDate: Tue Sep 20 16:23:46 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Sep 20 16:33:56 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d6c30ab1

Revert "Remove eval calls from supervisor start functions"

This reverts commit 0d1f1010c299a95332f224c3be9e8dfdd85eec54.
We need the eval in case someone uses something like:
command_args="this \"is a\" test"

This is related to #77.

 sh/start-stop-daemon.sh | 5 -
 sh/supervise-daemon.sh  | 5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 0449e5b..0793b19 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -38,7 +38,10 @@ ssd_start()
service_inactive && _inactive=true
mark_service_inactive
fi
-   start-stop-daemon --start \
+   #the eval call is necessary for cases like:
+   # command_args="this \"is a\" test"
+   # to work properly.
+   eval start-stop-daemon --start \
--exec $command \
${chroot:+--chroot} $chroot \
${procname:+--name} $procname \

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 389635f..bff68a4 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -19,7 +19,10 @@ supervise_start()
fi
 
ebegin "Starting ${name:-$RC_SVCNAME}"
-   supervise-daemon --start \
+   # The eval call is necessary for cases like:
+   # command_args="this \"is a\" test"
+   # to work properly.
+   eval supervise-daemon --start \
${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \



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

2016-09-19 Thread William Hubbs
commit: 0d1f1010c299a95332f224c3be9e8dfdd85eec54
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 19 23:03:57 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 19 23:03:57 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0d1f1010

Remove eval calls from supervisor start functions

This fixes #77.

 sh/start-stop-daemon.sh | 2 +-
 sh/supervise-daemon.sh  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 6f396b3..0449e5b 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -38,7 +38,7 @@ ssd_start()
service_inactive && _inactive=true
mark_service_inactive
fi
-   eval start-stop-daemon --start \
+   start-stop-daemon --start \
--exec $command \
${chroot:+--chroot} $chroot \
${procname:+--name} $procname \

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index e6ac117..389635f 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -19,7 +19,7 @@ supervise_start()
fi
 
ebegin "Starting ${name:-$RC_SVCNAME}"
-   eval supervise-daemon --start \
+   supervise-daemon --start \
${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \



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

2016-09-14 Thread William Hubbs
commit: c4d7e02abd7008b8e8ad16f62c2abbb60fab252b
Author: William Hubbs  gmail  com>
AuthorDate: Wed Sep 14 16:08:48 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Sep 14 17:34:42 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c4d7e02a

Fix permission checks for cgroups

This is needed because containers may give read access to cgroups but
not allow the settings to be changed.

 sh/rc-cgroup.sh.in | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 20b2c6e..5987f96 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -53,7 +53,7 @@ cgroup_set_values()
while [ -n "$1" -a "$controller" != "cpuacct" ]; do
case "$1" in
$controller.*)
-   if [ -n "$name" -a -f "$cgroup/$name" -a -n 
"$val" ]; then
+   if [ -n "$name" -a -w "$cgroup/$name" -a -n 
"$val" ]; then
veinfo "$RC_SVCNAME: Setting 
$cgroup/$name to $val"
printf "%s" "$val" > "$cgroup/$name"
fi
@@ -68,12 +68,12 @@ cgroup_set_values()
esac
shift
done
-   if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
+   if [ -n "$name" -a -w "$cgroup/$name" -a -n "$val" ]; then
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
printf "%s" "$val" > "$cgroup/$name"
fi
 
-   if [ -f "$cgroup/tasks" ]; then
+   if [ -w "$cgroup/tasks" ]; then
veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
printf "%d" 0 > "$cgroup/tasks"
fi
@@ -88,14 +88,14 @@ cgroup_add_service()
 # cgroups. But may lead to a problems where that inheriting
 # is needed.
for d in /sys/fs/cgroup/* ; do
-   [ -f "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
+   [ -w "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
done
 
openrc_cgroup=/sys/fs/cgroup/openrc
if [ -d "$openrc_cgroup" ]; then
cgroup="$openrc_cgroup/$RC_SVCNAME"
mkdir -p "$cgroup"
-   [ -f "$cgroup/tasks" ] && printf "%d" 0 > "$cgroup/tasks"
+   [ -w "$cgroup/tasks" ] && printf "%d" 0 > "$cgroup/tasks"
fi
 }
 



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

2016-09-13 Thread William Hubbs
commit: 8a8032478a755f6e2ceaebc5425e61c6817df936
Author: William Hubbs  gmail  com>
AuthorDate: Tue Sep 13 17:27:08 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Sep 13 17:52:10 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8a803247

Make use of name vs RC_SVCNAME consistent in supervisor scripts

This fixes #79.

 sh/runit.sh | 4 ++--
 sh/s6.sh| 4 ++--
 sh/start-stop-daemon.sh | 4 ++--
 sh/supervise-daemon.sh  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/sh/runit.sh b/sh/runit.sh
index e9c1d22..3cef0f3 100644
--- a/sh/runit.sh
+++ b/sh/runit.sh
@@ -21,7 +21,7 @@ runit_start()
ebegin "Starting ${name:-$RC_SVCNAME}"
ln -snf "${service_path}" "${service_link}"
sv start "${service_link}" > /dev/null 2>&1
-   eend $? "Failed to start $RC_SVCNAME"
+   eend $? "Failed to start ${name:-$RC_SVCNAME}"
 }
 
 runit_stop()
@@ -36,7 +36,7 @@ runit_stop()
ebegin "Stopping ${name:-$RC_SVCNAME}"
sv stop "${service_link}" > /dev/null 2>&1 &&
rm "${service_link}"
-   eend $? "Failed to stop $RC_SVCNAME"
+   eend $? "Failed to stop ${name:-$RC_SVCNAME}"
 }
 
 runit_status()

diff --git a/sh/s6.sh b/sh/s6.sh
index 447419c..d1b9c10 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -30,7 +30,7 @@ s6_start()
sleep 1.5
set -- $(s6-svstat "${s6_service_link}")
[ "$1" = "up" ]
-   eend $? "Failed to start $RC_SVCNAME"
+   eend $? "Failed to start ${name:-$RC_SVCNAME}"
 }
 
 s6_stop()
@@ -44,7 +44,7 @@ s6_stop()
s6-svc -wD -d -T ${s6_service_timeout_stop:-1} "${s6_service_link}"
set -- $(s6-svstat "${s6_service_link}")
[ "$1" = "down" ]
-   eend $? "Failed to stop $RC_SVCNAME"
+   eend $? "Failed to stop ${name:-$RC_SVCNAME}"
 }
 
 s6_status()

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 65ee660..6b679ac 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -46,7 +46,7 @@ ssd_start()
${command_user+--user} $command_user \
$_background $start_stop_daemon_args \
-- $command_args $command_args_background
-   if eend $? "Failed to start $RC_SVCNAME"; then
+   if eend $? "Failed to start ${name:-$RC_SVCNAME}"; then
service_set_value "command" "${command}"
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
@@ -80,7 +80,7 @@ ssd_stop()
${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
 
-   eend $? "Failed to stop $RC_SVCNAME"
+   eend $? "Failed to stop ${name:-$RC_SVCNAME}"
 }
 
 ssd_status()

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 2d889a6..e6ac117 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -31,7 +31,7 @@ supervise_start()
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
fi
-   eend $rc "failed to start $RC_SVCNAME"
+   eend $rc "failed to start ${name:-$RC_SVCNAME}"
 }
 
 supervise_stop()
@@ -46,7 +46,7 @@ supervise_stop()
${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
 
-   eend $? "Failed to stop $RC_SVCNAME"
+   eend $? "Failed to stop ${name:-$RC_SVCNAME}"
 }
 
 supervise_status()



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

2016-09-12 Thread William Hubbs
commit: ac53c9a658589456c678b6bfe674a66a3845e564
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep 12 16:20:26 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Sep 12 17:58:31 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ac53c9a6

sh/init.sh: fix the test for cache restoration

This fixes the test for cache restoration since we are no longer caching
the dependency tree.

 sh/init.sh.BSD.in  | 2 +-
 sh/init.sh.GNU-kFreeBSD.in | 2 +-
 sh/init.sh.GNU.in  | 2 +-
 sh/init.sh.Linux.in| 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/sh/init.sh.BSD.in b/sh/init.sh.BSD.in
index 6fe0bde..64282e9 100644
--- a/sh/init.sh.BSD.in
+++ b/sh/init.sh.BSD.in
@@ -57,7 +57,7 @@ case "$(openrc --sys)" in
 esac
 retval=$?
 
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
+if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
 fi
 

diff --git a/sh/init.sh.GNU-kFreeBSD.in b/sh/init.sh.GNU-kFreeBSD.in
index db3eec3..5eb8064 100644
--- a/sh/init.sh.GNU-kFreeBSD.in
+++ b/sh/init.sh.GNU-kFreeBSD.in
@@ -34,7 +34,7 @@ ebegin "Creating $RC_SVCDIR"
 mkdir -p $RC_SVCDIR
 eend $?
 
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
+if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
 cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
 fi
 

diff --git a/sh/init.sh.GNU.in b/sh/init.sh.GNU.in
index f08bac7..08a492a 100644
--- a/sh/init.sh.GNU.in
+++ b/sh/init.sh.GNU.in
@@ -36,7 +36,7 @@ ebegin "Creating $RC_SVCDIR"
 mkdir -p $RC_SVCDIR
 eend $?
 
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
+if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
 cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
 fi
 

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index 7d36e7a..344f627 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -85,7 +85,7 @@ if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
eend $?
 fi
 
-if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
+if [ -e "$RC_LIBEXECDIR"/cache/softlevel ]; then
cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
 fi
 



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

2016-09-08 Thread William Hubbs
commit: d4d559323819c8a5279bf197d8d3ff80f1e28cdc
Author: William Hubbs  gmail  com>
AuthorDate: Mon Sep  5 16:20:03 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Sep  6 18:34:25 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=d4d55932

sh/openrc-run.sh: read global configuration settings first

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

 NEWS.md |  6 ++
 sh/openrc-run.sh.in | 18 +-
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index d50741a..931d0ab 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -5,6 +5,12 @@ the information in this file is in reverse order.
 
 ## OpenRC-0.22
 
+In previous versions of OpenRC, configuration information was processed
+so that service-specific configuration stored in /etc/conf.d/* was
+overridden by global configuration stored in /etc/rc.conf. This release
+reverses that. Global configuration is now overridden by
+service-specific configuration.
+
 The swapfiles service, which was basically a copy of the swap service,
 has been removed. If you are only using swap partitions, this change
 will not affect you. If you are using swap files, please adjust the

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index ce5432f..4cbfb16 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -193,6 +193,15 @@ status()
 
 yesno $RC_DEBUG && set -x
 
+# Load configuration settings. First the global ones, then any
+# service-specific settings.
+sourcex -e "@SYSCONFDIR@/rc.conf"
+if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
+   for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
+   sourcex -e "$_f"
+   done
+fi
+
 _conf_d=${RC_SERVICE%/*}/../conf.d
 # If we're net.eth0 or openvpn.work then load net or openvpn config
 _c=${RC_SVCNAME%%.*}
@@ -209,15 +218,6 @@ if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
 fi
 unset _conf_d
 
-# Load any system overrides
-sourcex -e "@SYSCONFDIR@/rc.conf"
-if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
-   for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
-   sourcex -e "$_f"
-   done
-fi
-
-
 # load service supervisor functions
 sourcex "@LIBEXECDIR@/sh/runit.sh"
 sourcex "@LIBEXECDIR@/sh/s6.sh"



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

2016-07-26 Thread William Hubbs
commit: 0c229faf7e6a57bcff70f2143b83cb69a34c89f4
Author: Martin Väth  mvath  de>
AuthorDate: Wed May 25 09:03:12 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jul 26 15:53:54 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0c229faf

tmpfiles.sh: Support lines with q Q h H

btrfs support is not implemented yet (for q Q v), but at least tmpfiles.sh
no longer chokes about tmpfiles.d lines of recent systemd versions

This fixes #87.

 sh/tmpfiles.sh.in | 48 ++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index f7ee11b..87545ed 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -10,8 +10,10 @@
 # http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
 #
 # See the tmpfiles.d manpage as well:
+# https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
+# This script should match the old manpage
 # http://0pointer.de/public/systemd-man/tmpfiles.d.html
-# This script should match the manpage as of 2012/03/12
+# as of 2012/03/12 and also implements some more recent features
 #
 
 DRYRUN=0
@@ -44,6 +46,17 @@ dryrun_or_real() {
$dryrun "$@"
 }
 
+_chattr() {
+   local attr="$2"
+   case $attr in
+   [+-=]*) : ;;
+   '') return ;;
+   *) attr="+$attr" ;;
+   esac
+   local IFS=
+   dryrun_or_real chattr $1 "$attr" -- $3
+}
+
 relabel() {
local path
local paths=$1 mode=$2 uid=$3 gid=$4
@@ -163,6 +176,37 @@ _v() {
_d "$@"
 }
 
+_q() {
+   # Similar to _v. However, make sure that the subvolume will be assigned
+   # to the same higher-level quota groups as the subvolume it has
+   # been created in.
+   # TODO: Implement btrfs subvol creation.
+   _d "$@"
+}
+
+_Q() {
+   # Similar to q. However, instead of copying the higher-level quota
+   # group assignments from the parent as-is, the lowest quota group
+   # of the parent subvolume is determined that is not the
+   # leaf quota group.
+   # TODO: Implement btrfs subvol creation.
+   _d "$@"
+}
+
+_h() {
+   # Set file/directory attributes. Lines of this type accept
+   # shell-style globs in place of normal path names.
+   # The format of the argument field matches chattr
+   _chattr '' "$6" "$1"
+}
+
+_H() {
+   # Recursively set file/directory attributes. Lines of this type accept
+   # shell-syle globs in place of normal path names.
+   # Does not follow symlinks
+   _chattr -R "$6" "$1"
+}
+
 _L() {
# Create a symlink if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
@@ -371,7 +415,7 @@ for FILE in $tmpfiles_d ; do
 
# whine about invalid entries
case $cmd in
-   f|F|w|d|D|v|p|L|c|C|b|x|X|r|R|z|Z) ;;
+   f|F|w|d|D|v|p|L|c|C|b|x|X|r|R|z|Z|q|Q|h|H) ;;
*) warninvalid ; continue ;;
esac
 



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

2016-07-25 Thread William Hubbs
commit: 671911762d1bcd90c10d8ac0eb30fe10be4a65f6
Author: Mike Gilbert  gentoo  org>
AuthorDate: Sat Mar 12 18:13:56 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jul 25 20:37:02 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=67191176

tmpfiles: Process command line before gathering config files

This is part of #83.

 sh/tmpfiles.sh.in | 51 ++-
 1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index f711b1d..95b8b93 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -264,6 +264,32 @@ _Z() {
 BOOT=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
 EXCLUDE=
 PREFIX=
+
+while [ $# -gt 0 ]; do
+   case $1 in
+   --boot) BOOT=1 ;;
+   --create) CREATE=1 ;;
+   --remove) REMOVE=1 ;;
+   --clean) CLEAN=1 ;; # TODO: Not implemented
+   --verbose) VERBOSE=1 ;;
+   --dryrun|--dry-run) DRYRUN=1 ;;
+   --exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} 
" ;;
+   --prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
+   -*) invalid_option "$1" ;;
+   esac
+   shift
+done
+
+if [ $(( CLEAN )) -eq 1 ] ; then
+   printf '%s clean mode is not implemented\n' "${0##*/}"
+   exit 1
+fi
+
+if [ "$CREATE$REMOVE" = '00' ]; then
+   printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--boot] 
[--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
+   exit 1
+fi
+
 FILE=
 fragments=
 # XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
@@ -294,31 +320,6 @@ for b in $tmpfiles_basenames ; do
[ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
 done
 
-while [ $# -gt 0 ]; do
-   case $1 in
-   --boot) BOOT=1 ;;
-   --create) CREATE=1 ;;
-   --remove) REMOVE=1 ;;
-   --clean) CLEAN=1 ;; # TODO: Not implemented
-   --verbose) VERBOSE=1 ;;
-   --dryrun|--dry-run) DRYRUN=1 ;;
-   --exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} 
" ;;
-   --prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
-   -*) invalid_option "$1" ;;
-   esac
-   shift
-done
-
-if [ $(( CLEAN )) -eq 1 ] ; then
-   printf '%s clean mode is not implemented\n' "${0##*/}"
-   exit 1
-fi
-
-if [ "$CREATE$REMOVE" = '00' ]; then
-   printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--boot] 
[--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
-   exit 1
-fi
-
 error=0
 
 # loop through the gathered fragments, sorted globally by filename.



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

2016-07-25 Thread William Hubbs
commit: 3092e310acd376fc626cc051549e02bcd7697aed
Author: Mike Gilbert  gentoo  org>
AuthorDate: Sat Mar 12 19:10:42 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jul 25 20:37:18 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3092e310

tmpfiles: Accept filenames as command line arguments

This brings us closer to being able to use tmpfiles.sh as a full
replacement for systemd-tmpfiles.

This closes #83.

 sh/tmpfiles.sh.in | 61 ---
 1 file changed, 36 insertions(+), 25 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 95b8b93..f7ee11b 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -264,6 +264,7 @@ _Z() {
 BOOT=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
 EXCLUDE=
 PREFIX=
+FILES=
 
 while [ $# -gt 0 ]; do
case $1 in
@@ -276,6 +277,7 @@ while [ $# -gt 0 ]; do
--exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} 
" ;;
--prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
-*) invalid_option "$1" ;;
+   *) FILES="${FILES} $1"
esac
shift
 done
@@ -290,40 +292,49 @@ if [ "$CREATE$REMOVE" = '00' ]; then
exit 1
 fi
 
-FILE=
-fragments=
 # XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
-tmpfiles_dirs='/usr/lib/tmpfiles.d/ /run/tmpfiles.d/ /etc/tmpfiles.d/'
+tmpfiles_dirs='/usr/lib/tmpfiles.d /run/tmpfiles.d /etc/tmpfiles.d'
 tmpfiles_basenames=''
+
+if [ -z "${FILES}" ]; then
+   # Build a list of sorted unique basenames
+   # directories declared later in the tmpfiles_d array will override 
earlier
+   # directories, on a per file basename basis.
+   # `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
+   # `/run/tmpfiles/foo.conf' will always be read after 
`/etc/tmpfiles.d/bar.conf'
+   for d in ${tmpfiles_dirs} ; do
+   [ -d $d ] && for f in ${d}/*.conf ; do
+   case "${f##*/}" in
+   systemd.conf|systemd-*.conf) continue;;
+   esac
+   [ -f $f ] && 
tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
+   done # for f in ${d}
+   done # for d in ${tmpfiles_dirs}
+   FILES="$(printf "${tmpfiles_basenames}\n" | sort -u )"
+fi
+
 tmpfiles_d=''
-# Build a list of sorted unique basenames
-# directories declared later in the tmpfiles_d array will override earlier
-# directories, on a per file basename basis.
-# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
-# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
-for d in ${tmpfiles_dirs} ; do
-   [ -d $d ] && for f in ${d}/*.conf ; do
-   case "${f##*/}" in
-   systemd.conf|systemd-*.conf) continue;;
-   esac
-   [ -f $f ] && 
tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
-   done # for f in ${d}
-done # for d in ${tmpfiles_dirs}
-tmpfiles_basenames="$(printf "${tmpfiles_basenames}\n" | sort -u )"
-
-for b in $tmpfiles_basenames ; do
-   real_f=''
-   for d in $tmpfiles_dirs ; do
-   f=${d}/${b}
-   [ -f "${f}" ] && real_f=$f
-   done
-   [ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
+
+for b in ${FILES} ; do
+   if [ "${b##*/}" != "${b}" ]; then
+   # The user specified a path on the command line
+   # Just pass it through unaltered
+   tmpfiles_d="${tmpfiles_d} ${b}"
+   else
+   real_f=''
+   for d in $tmpfiles_dirs ; do
+   f=${d}/${b}
+   [ -f "${f}" ] && real_f=$f
+   done
+   [ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
+   fi
 done
 
 error=0
 
 # loop through the gathered fragments, sorted globally by filename.
 # `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
+FILE=
 for FILE in $tmpfiles_d ; do
LINENUM=0
 



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

2016-07-25 Thread William Hubbs
commit: 7d68839e9ea89b0a92aef69a9b4fd298554bb9b1
Author: Mike Gilbert  gentoo  org>
AuthorDate: Sat Mar 12 18:01:51 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jul 25 20:36:44 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7d68839e

tmpfiles: Make unrecognized options fatal

This is part of #83.

 sh/tmpfiles.sh.in | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 43442d7..f711b1d 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -33,6 +33,11 @@ warninvalid() {
error=$(( error+1 ))
 } >&2
 
+invalid_option() {
+   printf "tmpfiles: invalid option '%s'\n" "$1" >&2
+   exit 1
+}
+
 dryrun_or_real() {
local dryrun=
[ $DRYRUN -eq 1 ] && dryrun=echo
@@ -299,6 +304,7 @@ while [ $# -gt 0 ]; do
--dryrun|--dry-run) DRYRUN=1 ;;
--exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} 
" ;;
--prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
+   -*) invalid_option "$1" ;;
esac
shift
 done



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

2016-05-24 Thread William Hubbs
commit: a8214af2fe3aa91930e3270af99cf1d9b7ef5b0a
Author: William Hubbs  gmail  com>
AuthorDate: Thu May 19 22:58:14 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu May 19 22:58:14 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a8214af2

start-stop-daemon.sh: fix regression in chroot support

The support for the chroot variable was broken in 0.16, this fixes that
breakage.

 sh/start-stop-daemon.sh | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 3e42137..65ee660 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -40,6 +40,7 @@ ssd_start()
fi
eval start-stop-daemon --start \
--exec $command \
+   ${chroot:+--chroot} $chroot \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \
@@ -47,6 +48,7 @@ ssd_start()
-- $command_args $command_args_background
if eend $? "Failed to start $RC_SVCNAME"; then
service_set_value "command" "${command}"
+   [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
[ -n "${procname}" ] && service_set_value "procname" 
"${procname}"
return 0
@@ -62,9 +64,11 @@ ssd_start()
 ssd_stop()
 {
local startcommand="$(service_get_value "command")"
+   local startchroot="$(service_get_value "chroot")"
local startpidfile="$(service_get_value "pidfile")"
local startprocname="$(service_get_value "procname")"
command="${startcommand:-$command}"
+   chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}"
procname="${startprocname:-$procname}"
[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
@@ -73,7 +77,7 @@ ssd_stop()
${retry:+--retry} $retry \
${command:+--exec} $command \
${procname:+--name} $procname \
-   ${pidfile:+--pidfile} $pidfile \
+   ${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
 
eend $? "Failed to stop $RC_SVCNAME"



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

2016-05-24 Thread William Hubbs
commit: 3351c8b4c3027f09003f8ba33e43f46762f5c453
Author: William Hubbs  gmail  com>
AuthorDate: Thu May 19 22:59:40 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu May 19 22:59:40 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3351c8b4

supervise-daemon.sh: add support for chroot variable

 sh/supervise-daemon.sh | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh
index 34e3ef7..2d889a6 100644
--- a/sh/supervise-daemon.sh
+++ b/sh/supervise-daemon.sh
@@ -20,24 +20,30 @@ supervise_start()
 
ebegin "Starting ${name:-$RC_SVCNAME}"
eval supervise-daemon --start \
+   ${chroot:+--chroot} $chroot \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \
$supervise_daemon_args \
$command \
-- $command_args $command_args_foreground
rc=$?
-   [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
+   if [ $rc = 0 ]; then
+   [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
+   [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
+   fi
eend $rc "failed to start $RC_SVCNAME"
 }
 
 supervise_stop()
 {
+   local startchroot="$(service_get_value "chroot")"
local startpidfile="$(service_get_value "pidfile")"
+   chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}"
[ -n "$pidfile" ] || return 0
ebegin "Stopping ${name:-$RC_SVCNAME}"
supervise-daemon --stop \
-   ${pidfile:+--pidfile} $pidfile \
+   ${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
 
eend $? "Failed to stop $RC_SVCNAME"



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

2016-02-19 Thread William Hubbs
commit: beaa71df0ab2cfa61beba4be0303099aa6c75e6a
Author: Dustin C. Hatch  hatch  name>
AuthorDate: Fri Feb 19 01:18:13 2016 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Feb 19 21:25:53 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=beaa71df

binfmt.sh: use read in raw mode

The read builtin in most shells will interpret backslash characters
as escapes, and they are lost when reading binfmt files line-by-line.
This causes magic strings containing backslashes to be mangled and
become invalid, resulting in erroneous 'invalid entry' messages.

The -r option to read disables special handling of backslashes and
keeps all lines intact.

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

 sh/binfmt.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/binfmt.sh.in b/sh/binfmt.sh.in
index fd422f8..be0ed48 100644
--- a/sh/binfmt.sh.in
+++ b/sh/binfmt.sh.in
@@ -22,7 +22,7 @@ apply_file() {
 
### FILE FORMAT ###
# See https://www.kernel.org/doc/Documentation/binfmt_misc.txt
-   while read line; do
+   while read -r line; do
LINENUM=$(( LINENUM+1 ))
case $line in
\#*) continue ;;



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

2016-01-19 Thread William Hubbs
commit: 30c3561b6b648d60174a22a73555b680d2cc86fc
Author: Colin Booth  heliocat  net>
AuthorDate: Mon Sep 14 07:43:42 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Jan 19 22:52:58 2016 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=30c3561b

sh/s6.sh: update s6-svc syntax to be valid for 2.2.0.0+

The s6-svc syntax changed for wait-up, wait-ready, wait-down, and
wait-finished. This changes the s6 handling script to use the current
valid syntax.

This fixes #65.

 sh/s6.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/s6.sh b/sh/s6.sh
index 7f378d5..447419c 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -41,7 +41,7 @@ s6_stop()
  fi
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Stopping ${name:-$RC_SVCNAME}"
-   s6-svc -Dd -T ${s6_service_timeout_stop:-1} "${s6_service_link}"
+   s6-svc -wD -d -T ${s6_service_timeout_stop:-1} "${s6_service_link}"
set -- $(s6-svstat "${s6_service_link}")
[ "$1" = "down" ]
eend $? "Failed to stop $RC_SVCNAME"



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

2015-12-09 Thread William Hubbs
commit: cc9c23c8484ea7d07b1f8e54bcab46cc31ec727d
Author: William Hubbs  gmail  com>
AuthorDate: Wed Dec  9 18:38:10 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Dec  9 18:38:10 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=cc9c23c8

Complete support for rc.conf.d

- gendepends.sh needs to read this directory to allow dependencies to be
  overridden
  - init.sh for Linux and Bsd need to read it to allow config settings
they use to be overridden.

 sh/gendepends.sh.in | 5 +
 sh/init.sh.BSD.in   | 5 +
 sh/init.sh.Linux.in | 5 +
 3 files changed, 15 insertions(+)

diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
index 2ab798d..79a4bff 100644
--- a/sh/gendepends.sh.in
+++ b/sh/gendepends.sh.in
@@ -96,6 +96,11 @@ do
fi
 
[ -e @SYSCONFDIR@/rc.conf ] && . @SYSCONFDIR@/rc.conf
+   if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
+   for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
+   [ -e "$_f" ] && . "$_f"
+   done
+   fi
 
if . "$_dir/$RC_SVCNAME"; then
echo "$RC_SVCNAME" >&3

diff --git a/sh/init.sh.BSD.in b/sh/init.sh.BSD.in
index 2a53dcd..5912a95 100644
--- a/sh/init.sh.BSD.in
+++ b/sh/init.sh.BSD.in
@@ -23,6 +23,11 @@ mount_svcdir()
 
 . "$RC_LIBEXECDIR"/sh/functions.sh
 [ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf"
+if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
+   for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
+   [ -r "$_f" ] && . "$_f"
+   done
+fi
 
 # Disable devd until we need it
 if [ -z "$RC_SYS" -a "$RC_UNAME" = "FreeBSD" ]; then

diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index a8ee69e..7d36e7a 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -5,6 +5,11 @@
 
 . "$RC_LIBEXECDIR"/sh/functions.sh
 [ -r "@SYSCONFDIR@/rc.conf" ] && . "@SYSCONFDIR@/rc.conf"
+if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
+   for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
+   [ -e "$_f" ] && . "$_f"
+   done
+fi
 
 # By default VServer already has /proc mounted, but OpenVZ does not!
 # However, some of our users have an old proc image in /proc



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

2015-12-03 Thread William Hubbs
commit: 627e925463068e754ffd869f99a43634d6d9631e
Author: William Hubbs  gmail  com>
AuthorDate: Thu Dec  3 20:09:38 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Dec  3 22:52:15 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=627e9254

add support for -containers keyword

 man/openrc-run.8  |  3 +++
 sh/gendepends.sh.in   | 13 -
 sh/openrc-run.sh.in   | 13 -
 sh/rc-functions.sh.in | 21 +
 4 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 6aab067..5d18fe5 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -227,6 +227,9 @@ Same as -jail, but for Xen DOM0 systems.
 Same as -jail, but for Xen DOMU systems.
 .It Dv -docker
 Same as -jail, but for docker systems.
+.It Dv -containers
+Same as -jail, but for all relevant container types on the operating
+system.
 .El
 .El
 .Pp

diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in
index 36caeb7..2ab798d 100644
--- a/sh/gendepends.sh.in
+++ b/sh/gendepends.sh.in
@@ -29,7 +29,18 @@ provide() {
[ -n "$*" ] && echo "$RC_SVCNAME iprovide $*" >&3
 }
 keyword() {
-   [ -n "$*" ] && echo "$RC_SVCNAME keyword $*" >&3
+   local c x
+   set -- $*
+   while [ -n "$*" ]; do
+   case "$1" in
+   -containers) x="$(_get_containers)" ;;
+   !-containers) x="$(_get_containers_remove)" ;;
+   *) x=$1 ;;
+   esac
+   c="${c}${x} "
+   shift
+   done
+   [ -n "$c" ] && echo "$RC_SVCNAME keyword $c" >&3
 }
 depend() {
:

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index c169204..5018cee 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -79,7 +79,18 @@ provide() {
[ -n "$*" ] && echo "provide $*"
 }
 keyword() {
-   [ -n "$*" ] && echo "keyword $*"
+   local c x
+   set -- $*
+   while [ -n "$*" ]; do
+   case "$1" in
+   -containers) x="$(_get_containers)" ;;
+   !-containers) x="$(_get_containers_remove)" ;;
+   *) x=$1 ;;
+   esac
+   c="${c}${x} "
+   shift
+   done
+   [ -n "$c" ] && echo "keyword $c"
 }
 
 # Describe the init script to the user

diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in
index c854876..12eb4e2 100644
--- a/sh/rc-functions.sh.in
+++ b/sh/rc-functions.sh.in
@@ -86,6 +86,27 @@ get_bootparam()
 }
 
 # Called from openrc-run.sh or gendepends.sh
+_get_containers() {
+   local c
+   case "${RC_UNAME}" in
+   FreeBSD)
+   c="-jail"
+   ;;
+   Linux)
+   c="-docker -lxc -openvz -rkt -systemd-nspawn -uml -vserver"
+   ;;
+   esac
+   echo $c
+}
+
+_get_containers_remove() {
+   local c
+   for x in $(_get_containers); do
+   c="${c}!${x} "
+   done
+   echo $c
+}
+
 _depend() {
depend
local _rc_svcname=$(shell_var "$RC_SVCNAME") _deptype= _depends=



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

2015-12-01 Thread William Hubbs
commit: bd9456ff3172cc88f32d67bd4e789e2beee43595
Author: William Hubbs  gmail  com>
AuthorDate: Tue Dec  1 18:31:28 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Dec  1 18:31:28 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=bd9456ff

rc-functions.sh: add support for user-defined want dependencies

 sh/rc-functions.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/rc-functions.sh.in b/sh/rc-functions.sh.in
index 911d65a..c854876 100644
--- a/sh/rc-functions.sh.in
+++ b/sh/rc-functions.sh.in
@@ -91,7 +91,7 @@ _depend() {
local _rc_svcname=$(shell_var "$RC_SVCNAME") _deptype= _depends=
 
# Add any user defined depends
-   for _deptype in config:CONFIG need:NEED use:USE \
+   for _deptype in config:CONFIG need:NEED use:USE want:WANT \
after:AFTER before:BEFORE \
provide:PROVIDE keyword:KEYWORD; do
IFS=:



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

2015-11-05 Thread William Hubbs
commit: c09eeca49145b034df6527c500099ba22f28e824
Author: William Hubbs  gmail  com>
AuthorDate: Fri Oct 30 17:32:32 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Nov  5 16:40:24 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c09eeca4

Add rc.conf.d support

This makes it possible to override settings in rc.conf by adding a
directory @SYSCONFDIR  /rc.conf.d and putting files in this directory.
The files will be processed in lexical order, and the last setting in
these files will be used.

 sh/openrc-run.sh.in|   6 +++
 src/librc/librc-misc.c | 103 +
 src/librc/rc.h.in  |   1 +
 3 files changed, 110 insertions(+)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 8aba4e0..749af2c 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -184,6 +184,12 @@ unset _conf_d
 
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
+if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
+   for _f in "@SYSCONFDIR@"/rc.conf.d/*.conf; do
+   sourcex -e "$_f"
+   done
+fi
+
 
 # load service supervisor functions
 sourcex "@LIBEXECDIR@/sh/s6.sh"

diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 2e9de80..1eedc96 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -28,6 +28,8 @@
  * SUCH DAMAGE.
  */
 
+#include 
+
 #include "queue.h"
 #include "librc.h"
 
@@ -214,6 +216,69 @@ rc_config_list(const char *file)
 }
 librc_hidden_def(rc_config_list)
 
+static void rc_config_set_value(RC_STRINGLIST *config, char *value)
+{
+   RC_STRING *cline;
+   char *entry;
+   size_t i = 0;
+   char *newline;
+   char *p = value;
+   bool replaced;
+   char *token;
+
+   if (! p)
+   return;
+   if (strncmp(p, "export ", 7) == 0)
+   p += 7;
+   if (! (token = strsep(&p, "=")))
+   return;
+
+   entry = xstrdup(token);
+   /* Preserve shell coloring */
+   if (*p == '$')
+   token = value;
+   else
+   do {
+   /* Bash variables are usually quoted */
+   token = strsep(&p, "\"\'");
+   } while (token && *token == '\0');
+
+   /* Drop a newline if that's all we have */
+   if (token) {
+   i = strlen(token) - 1;
+   if (token[i] == '\n')
+   token[i] = 0;
+
+   i = strlen(entry) + strlen(token) + 2;
+   newline = xmalloc(sizeof(char) * i);
+   snprintf(newline, i, "%s=%s", entry, token);
+   } else {
+   i = strlen(entry) + 2;
+   newline = xmalloc(sizeof(char) * i);
+   snprintf(newline, i, "%s=", entry);
+   }
+
+   replaced = false;
+   /* In shells the last item takes precedence, so we need to remove
+  any prior values we may already have */
+   TAILQ_FOREACH(cline, config, entries) {
+   i = strlen(entry);
+   if (strncmp(entry, cline->value, i) == 0 && cline->value[i] == 
'=') {
+   /* We have a match now - to save time we directly 
replace it */
+   free(cline->value);
+   cline->value = newline;
+   replaced = true;
+   break;
+   }
+   }
+
+   if (!replaced) {
+   rc_stringlist_add(config, newline);
+   free(newline);
+   }
+   free(entry);
+}
+
 /*
  * Override some specific rc.conf options on the kernel command line
  */
@@ -272,6 +337,42 @@ static RC_STRINGLIST *rc_config_override(RC_STRINGLIST 
*config)
 }
 #endif
 
+static RC_STRINGLIST * rc_config_directory(RC_STRINGLIST *config)
+{
+   DIR *dp;
+   struct dirent *d;
+   RC_STRINGLIST *rc_conf_d_files = rc_stringlist_new();
+   RC_STRING *fname;
+   RC_STRINGLIST *rc_conf_d_list;
+   char path[PATH_MAX];
+   RC_STRING *line;
+
+   if ((dp = opendir(RC_CONF_D)) != NULL) {
+   while ((d = readdir(dp)) != NULL) {
+   if (fnmatch("*.conf", d->d_name, FNM_PATHNAME) == 0) {
+   rc_stringlist_addu(rc_conf_d_files, d->d_name);
+   }
+   }
+   closedir(dp);
+
+   if (rc_conf_d_files) {
+   rc_stringlist_sort(&rc_conf_d_files);
+   TAILQ_FOREACH(fname, rc_conf_d_files, entries) {
+   if (! fname->value)
+   continue;
+   sprintf(path, "%s/%s", RC_CONF_D, fname->value);
+   rc_conf_d_list = rc_config_list(path);
+   TAILQ_FOREACH(line, rc_conf_d_list, entries)
+   if (line->value)
+   rc_config_set_value(config, 
li

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

2015-10-13 Thread William Hubbs
commit: fc777aeaf3e6e2d47f4599acfe6c8d1bf5bc760a
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct 13 20:50:59 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct 13 20:51:15 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=fc777aea

typo fix

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

 sh/openrc-run.sh.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index e9369e4..37ed96f 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -222,7 +222,7 @@ done
 sourcex "$RC_SERVICE"
 
 eval "printf '%s\n' $required_dirs" | while read _d; do
-   if [ ! -d "$_d" ]; then
+   if [ -n "$_d" ] && [ ! -d "$_d" ]; then
eerror "$RC_SVCNAME: \`$_d' is not a directory"
exit 1
fi
@@ -230,7 +230,7 @@ done
 unset _d
 
 eval "printf '%s\n' $required_files" | while read _f; do
-   if [ ! -r "$_f" ]; then
+   if [ -n "$_f" ] && [ ! -r "$_f" ]; then
eerror "$RC_SVCNAME: \`$_f' is not readable"
exit 1
fi



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

2015-10-13 Thread William Hubbs
commit: 7da72ce487a8d92d992e7fd3db881c198ae02609
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct 13 22:42:46 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct 13 22:45:05 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=7da72ce4

openrc-run.sh: fix new required_* tests to exit properly

 sh/openrc-run.sh.in | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 37ed96f..8aba4e0 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -227,6 +227,7 @@ eval "printf '%s\n' $required_dirs" | while read _d; do
exit 1
fi
 done
+[ $? -ne 0 ] && exit 1
 unset _d
 
 eval "printf '%s\n' $required_files" | while read _f; do
@@ -235,6 +236,7 @@ eval "printf '%s\n' $required_files" | while read _f; do
exit 1
fi
 done
+[ $? -ne 0 ] && exit 1
 unset _f
 
 if [ -n "$opts" ]; then



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

2015-10-13 Thread William Hubbs
commit: 29f7e335927d4c1fb151124de8cdf01fb87723fa
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct 13 12:59:50 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct 13 12:59:50 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=29f7e335

openrc-run.sh: allow spaces in required_{files,dirs}

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

 sh/openrc-run.sh.in | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 33dc59c..e9369e4 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -221,16 +221,16 @@ done
 # Load our script
 sourcex "$RC_SERVICE"
 
-for _d in $required_dirs; do
-   if [ ! -d $_d ]; then
+eval "printf '%s\n' $required_dirs" | while read _d; do
+   if [ ! -d "$_d" ]; then
eerror "$RC_SVCNAME: \`$_d' is not a directory"
exit 1
fi
 done
 unset _d
 
-for _f in $required_files; do
-   if [ ! -r $_f ]; then
+eval "printf '%s\n' $required_files" | while read _f; do
+   if [ ! -r "$_f" ]; then
eerror "$RC_SVCNAME: \`$_f' is not readable"
exit 1
fi



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

2015-10-06 Thread William Hubbs
commit: 80d3928b0d13f09a9c1e82bd27c9fff943d84d43
Author: Austin S. Hemmelgarn  gmail  com>
AuthorDate: Tue Oct  6 20:02:28 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct  6 20:05:35 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=80d3928b

cgroups: Add the hugetlb, net_cls and pids controllers

Note from WilliamH: I slightly rearranged the code and added the
settings in rc.conf.

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

 etc/rc.conf.Linux  | 9 +
 sh/rc-cgroup.sh.in | 9 +
 2 files changed, 18 insertions(+)

diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index a8ad58b..f04f96e 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -62,12 +62,21 @@ rc_tty_number=12
 # Set the devices controller settings for this service.
 #rc_cgroup_devices=""
 
+# Set the hugetlb controller settings for this service.
+#rc_cgroup_hugetlb=""
+
 # Set the memory controller settings for this service.
 #rc_cgroup_memory=""
 
+# Set the net_cls controller settings for this service.
+#rc_cgroup_net_cls=""
+
 # Set the net_prio controller settings for this service.
 #rc_cgroup_net_prio=""
 
+# Set the pids controller settings for this service.
+#rc_cgroup_pids=""
+
 # Set this to YES if yu want all of the processes in a service's cgroup
 # killed when the service is stopped or restarted.
 # This should not be set globally because it kills all of the service's

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 3f34d17..b49c711 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -109,12 +109,21 @@ cgroup_set_limits()
local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
[ -n "$devices" ] && cgroup_set_values devices "$devices"
 
+   local hugetlb="${rc_cgroup_hugetlb:-$RC_CGROUP_HUGETLB}"
+   [ -n "$hugetlb" ] && cgroup_set_values hugetlb "$hugetlb"
+
local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
[ -n "$memory" ] && cgroup_set_values memory "$memory"
 
+   local net_cls="${rc_cgroup_net_cls:-$RC_CGROUP_NET_CLS}"
+   [ -n "$net_cls" ] && cgroup_set_values net_cls "$net_cls"
+
local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
[ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
 
+   local pids="${rc_cgroup_pids:-$RC_CGROUP_PIDS}"
+   [ -n "$pids" ] && cgroup_set_values pids "$pids"
+
return 0
 }
 



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

2015-10-06 Thread William Hubbs
commit: b20a1951adf9a705a903fb3047b7ef26c013103c
Author: William Hubbs  gmail  com>
AuthorDate: Tue Oct  6 16:59:55 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Oct  6 17:11:29 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b20a1951

rc-cgroup.sh: Do not add leading spaces to cgroup values

We were starting the value we write to the cgroup setting file with
leading spaces and this was causing issues. This change makes sure that
we aren't adding leading spaces to the value.

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

 sh/rc-cgroup.sh.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index c7cac2a..3f34d17 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -54,7 +54,9 @@ cgroup_set_values()
val=
;;
*)
-   val="$val $1"
+   [ -n "$val" ] &&
+   val="$val $1" ||
+   val="$1"
;;
esac
shift



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

2015-10-04 Thread William Hubbs
commit: a59365a582c3a8c9a8b863b572fddcb65fccadfd
Author: William Hubbs  gmail  com>
AuthorDate: Fri Oct  2 21:34:15 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Oct  2 21:34:15 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a59365a5

start-stop-daemon.sh: complain in start if command is undefined

The default start-stop-daemon start function expects the command
variable to be defined to point to the daemon we want to start.

If the variable is undefined, this means that there will be nothing to
start, and in this case we should complain because it is possible that
the script writer made a typo in the variable name.

 sh/start-stop-daemon.sh | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
index 6a3e205..ea99269 100644
--- a/sh/start-stop-daemon.sh
+++ b/sh/start-stop-daemon.sh
@@ -4,7 +4,13 @@
 
 ssd_start()
 {
-   [ -n "$command" ] || return 0
+   if [ -z "$command" ]; then
+   ewarn "The command variable is undefined."
+   ewarn "There is nothing for ${name:-$RC_SVCNAME} to start."
+   ewarn "If this is what you intend, please write a start 
function."
+   ewarn "This will become a failure in a future release."
+   return 0
+   fi
 
local _background=
ebegin "Starting ${name:-$RC_SVCNAME}"



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

2015-08-04 Thread William Hubbs
commit: 6a422982579786cb8308af04ccca6622afa06e50
Author: Jason Zaman  perfinion  com>
AuthorDate: Fri Jul 10 20:45:11 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Aug  3 19:51:16 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6a422982

tmpfiles: run restorecon on the entire path

The tmpfiles "d" entry will create a full path and only the last dir in
the path will have its SELinux label set correctly. This patch will
restorecon the parents as well so that the selinux labels are correct.

eg, "d /run/libvirt/lxc", then "lxc" would have the correct SELinux
label but "libvirt" would not.

Signed-off-by: Jason Zaman  perfinion.com>

 sh/tmpfiles.sh.in | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 89bd03e..43442d7 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -53,10 +53,18 @@ relabel() {
done
 }
 
+splitpath() {
+local path=$1
+while [ -n "$path" ]; do
+echo $path
+path=${path%/*}
+done
+}
+
 _restorecon() {
 local path=$1
 if [ -x /sbin/restorecon ]; then
-dryrun_or_real restorecon -F "$path"
+dryrun_or_real restorecon -F $(splitpath "$path")
 fi
 }
 
@@ -122,6 +130,7 @@ _d() {
 
if [ ! -d "$path" ]; then
dryrun_or_real mkdir -p "$path" 2>/dev/null
+   _restorecon "$path"
dryrun_or_real $CHECKPATH -dq -m "$mode" -o "$uid:$gid" "$path"
fi
 }
@@ -137,6 +146,7 @@ _D() {
 
if [ $CREATE -gt 0 ]; then
dryrun_or_real mkdir -p "$path" 2>/dev/null
+   _restorecon "$path"
dryrun_or_real $CHECKPATH -Dq -m "$mode" -o "$uid:$gid" "$path"
fi
 }



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

2015-07-10 Thread William Hubbs
commit: a36a635b016a7427dd1739a26c951fedf22f0dec
Author: Mike Gilbert  gentoo  org>
AuthorDate: Sun Jun 14 01:25:33 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jun 25 05:40:35 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a36a635b

tmpfiles: Recognize type 'v' (create btrfs subvol)

This change does NOT implement btrfs subvol creation.  Instead, it
treats 'v' the same as 'd', which is an acceptable fallback
according to the manual.

Fixes #58

 sh/tmpfiles.sh.in | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 046bf9f..89bd03e 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -141,6 +141,13 @@ _D() {
fi
 }
 
+_v() {
+   # Create a subvolume if the path does not exist yet and the file system
+   # supports this (btrfs). Otherwise create a normal directory.
+   # TODO: Implement btrfs subvol creation.
+   _d "$@"
+}
+
 _L() {
# Create a symlink if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
@@ -336,7 +343,7 @@ for FILE in $tmpfiles_d ; do
 
# whine about invalid entries
case $cmd in
-   f|F|w|d|D|p|L|c|C|b|x|X|r|R|z|Z) ;;
+   f|F|w|d|D|v|p|L|c|C|b|x|X|r|R|z|Z) ;;
*) warninvalid ; continue ;;
esac
 
@@ -344,7 +351,7 @@ for FILE in $tmpfiles_d ; do
if [ "$mode" = '-' -o "$mode" = '' ]; then
case "$cmd" in
p|f|F) mode=0644 ;;
-   d|D) mode=0755 ;;
+   d|D|v) mode=0755 ;;
C|z|Z|x|r|R|L) ;;
esac
fi



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

2015-07-10 Thread William Hubbs
commit: 9310ccc06bcadd8897aed51cd51c94fccb7d9c07
Author: Mike Gilbert  gentoo  org>
AuthorDate: Sun Jun 14 01:11:18 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jun 25 05:40:02 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=9310ccc0

Remove execute bit from tmpfiles.sh.in

 sh/tmpfiles.sh.in | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
old mode 100755
new mode 100644



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

2015-05-14 Thread William Hubbs
commit: a7fcc1e264b035177b4e524a40b27145baa86969
Author: William Hubbs  gmail  com>
AuthorDate: Thu May 14 19:26:52 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu May 14 19:26:52 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a7fcc1e2

S6: kick the scanner and sleep 1.5 seconds to avoid a race condition

 sh/s6.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sh/s6.sh b/sh/s6.sh
index 99aba3f..a45456a 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -13,6 +13,8 @@ s6_start()
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Starting ${name:-$RC_SVCNAME}"
ln -sf "${s6_service_path}" "${s6_service_link}"
+   s6-svscanctl -na "${RC_SVCDIR}"/s6-scan
+   sleep 1.5
s6-svc -u "${s6_service_link}"
if [ -n "$s6_svwait_options_start" ]; then
s6-svwait ${s6_svwait_options_start} "${s6_service_link}"



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

2015-05-14 Thread William Hubbs
commit: b79d058f162d8b49ccc968744e7cb1b7a7ba729c
Author: William Hubbs  gmail  com>
AuthorDate: Thu May 14 16:40:29 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu May 14 16:40:29 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=b79d058f

s6: Use s6-svc -Dd to stop services

This allows us to get rid of the sleep call in the stop function. Also,
we set a configurable timeout value for stopping daemons.

 man/openrc-run.8 |  5 +++--
 s6-guide.md  | 20 ++--
 sh/s6.sh |  6 +-
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 0a9f5bc..f08ad79 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -117,8 +117,9 @@ The path to the s6 service directory if you are monitoring 
this service
 with S6. The default is /var/svc.d/${RC_SVCNAME}.
 .It Ar s6_svwait_options_start
 The options to pass to s6-svwait when starting the service via s6.
-.It Ar s6_svwait_options_stop
-The options to pass to s6-svwait when stopping the service via s6.
+.It Ar s6_service_timeout_stop
+The amount of time, in milliseconds, s6-svc should wait for the service
+to go down when stopping the service. The default is 1.
 .It Ar start_stop_daemon_args
 List of arguments passed to start-stop-daemon when starting the daemon.
 .It Ar command

diff --git a/s6-guide.md b/s6-guide.md
index 9a09e32..63c63de 100644
--- a/s6-guide.md
+++ b/s6-guide.md
@@ -33,22 +33,14 @@ supervisor=s6
 Several other variables affect s6 services. They are documented on the
 openrc-run man page, but I will list them here for convenience:
 
-s6_service_path - the path to the s6 service directory
-s6_svwait_options_start - the options to pass to s6-svwait when starting
-s6_svwait_options_stop - the options to pass to s6-svwait when stopping.
-
-The s6_service_path variable defaults to /var/svc.d/${RC_SVCNAME} if it
-is not set in the service script. For example, if you want a service
-script called /etc/init.d/foobar to use s6 to monitor its daemon, the s6
-service should be the directory /var/svc.d/foobar.
+s6_service_path - the path to the s6 service directory. The default is
+/var/svc.d/$RC_SVCNAME.
 
-See the documentation for s6 for more information about s6 service
-directories.
+s6_svwait_options_start - the options to pass to s6-svwait when starting
+the service. If this is not set, s6-svwait will not be called.
 
-The s6_svwait_options_* variables set command line options to pass to
-s6-svwait when starting or stopping the s6 service. These can be very
-useful for waiting for s6 services to signal when they are up, timing out
-when an s6 service doesn't come up, etc.
+s6_service_timeout_stop - the amount of time, in milliseconds, s6-svc
+should wait for a service to go down when stopping.
 
 This is very early support, so feel free to file bugs if you have
 issues.

diff --git a/sh/s6.sh b/sh/s6.sh
index a99fd5b..99aba3f 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -31,11 +31,7 @@ s6_stop()
  fi
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Stopping ${name:-$RC_SVCNAME}"
-   s6-svc -d "${s6_service_link}"
-   if [ -n "$s6_svwait_options_stop" ]; then
-   s6-svwait ${s6_svwait_options_stop} "${s6_service_link}"
-   fi
-   sleep 1.5
+   s6-svc -Dd -T ${s6_service_timeout_stop:-1} "${s6_service_link}"
set -- $(s6-svstat "${s6_service_link}")
[ "$1" = "down" ]
eend $? "Failed to stop $RC_SVCNAME"



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

2015-05-13 Thread William Hubbs
commit: ddce529c71c2e9f01d8e5666e27050b6ed6c6761
Author: William Hubbs  gmail  com>
AuthorDate: Wed May 13 21:51:55 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May 13 21:51:55 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ddce529c

More s6 fixes

- When no service link is in the scan directory, show the default
  stopped message.
- Do not remove the service link when stopping the service.

 sh/s6.sh | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sh/s6.sh b/sh/s6.sh
index 01527b6..a99fd5b 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -37,12 +37,16 @@ s6_stop()
fi
sleep 1.5
set -- $(s6-svstat "${s6_service_link}")
-   [ "$1" = "down" ] && rm -fr "${s6_service_link}"
+   [ "$1" = "down" ]
eend $? "Failed to stop $RC_SVCNAME"
 }
 
 s6_status()
 {
s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
-   s6-svstat "${s6_service_link}"
+   if [ -L "${s6_service_link}" ]; then
+   s6-svstat "${s6_service_link}"
+   else
+   _status
+   fi
 }



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

2015-05-13 Thread William Hubbs
commit: e372f97bebd4866633ad56aa5d5b1ae59fa88118
Author: William Hubbs  gmail  com>
AuthorDate: Wed May 13 19:47:35 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed May 13 21:10:08 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=e372f97b

Fix the s6 handling

This changes the default s6 service directory to /var/svc.d, also
it changes the code to work with the individual services instead of
forcing a rescan when a service is started or stopped.

 man/openrc-run.8 |  2 +-
 s6-guide.md  |  4 ++--
 sh/s6.sh | 34 ++
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index 259d23f..0a9f5bc 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -114,7 +114,7 @@ in this release is S6 from Skarnet software. To use this, 
set
 supervisor=s6.
 .It Ar s6_service_path
 The path to the s6 service directory if you are monitoring this service
-with S6. The default is /etc/svc.d/${RC_SVCNAME}.
+with S6. The default is /var/svc.d/${RC_SVCNAME}.
 .It Ar s6_svwait_options_start
 The options to pass to s6-svwait when starting the service via s6.
 .It Ar s6_svwait_options_stop

diff --git a/s6-guide.md b/s6-guide.md
index 4a37a9c..9a09e32 100644
--- a/s6-guide.md
+++ b/s6-guide.md
@@ -37,10 +37,10 @@ s6_service_path - the path to the s6 service directory
 s6_svwait_options_start - the options to pass to s6-svwait when starting
 s6_svwait_options_stop - the options to pass to s6-svwait when stopping.
 
-The s6_service_path variable defaults to /etc/svc.d/${RC_SVCNAME} if it
+The s6_service_path variable defaults to /var/svc.d/${RC_SVCNAME} if it
 is not set in the service script. For example, if you want a service
 script called /etc/init.d/foobar to use s6 to monitor its daemon, the s6
-service should be the directory /etc/svc.d/foobar.
+service should be the directory /var/svc.d/foobar.
 
 See the documentation for s6 for more information about s6 service
 directories.

diff --git a/sh/s6.sh b/sh/s6.sh
index 780beab..01527b6 100644
--- a/sh/s6.sh
+++ b/sh/s6.sh
@@ -2,7 +2,7 @@
 # Copyright (c) 2015 William Hubbs 
 # Released under the 2-clause BSD license.
 
-[ -z "${s6_service_path}" ] && s6_service_path="/etc/svc.d/${RC_SVCNAME}"
+[ -z "${s6_service_path}" ] && s6_service_path="/var/svc.d/${RC_SVCNAME}"
 
 s6_start()
 {
@@ -10,16 +10,17 @@ s6_start()
eerror "${s6_service_path} does not exist."
return 1
  fi
-   local rc
+   s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Starting ${name:-$RC_SVCNAME}"
-   ln -sf "${s6_service_path}" "${RC_SVCDIR}"/s6-scan
-   s6-svscanctl -an "${RC_SVCDIR}"/s6-scan
-   rc=$?
+   ln -sf "${s6_service_path}" "${s6_service_link}"
+   s6-svc -u "${s6_service_link}"
if [ -n "$s6_svwait_options_start" ]; then
-   s6-svwait ${s6_svwait_options_start} "${s6_service_path}"
-   rc=$?
+   s6-svwait ${s6_svwait_options_start} "${s6_service_link}"
fi
-   eend $rc "Failed to start $RC_SVCNAME"
+   sleep 1.5
+   set -- $(s6-svstat "${s6_service_link}")
+   [ "$1" = "up" ]
+   eend $? "Failed to start $RC_SVCNAME"
 }
 
 s6_stop()
@@ -28,19 +29,20 @@ s6_stop()
eerror "${s6_service_path} does not exist."
return 1
  fi
-   local rc
+   s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
ebegin "Stopping ${name:-$RC_SVCNAME}"
-   rm -rf "${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
-   s6-svscanctl -an "${RC_SVCDIR}"/s6-scan
-   rc=$? 
+   s6-svc -d "${s6_service_link}"
if [ -n "$s6_svwait_options_stop" ]; then
-   s6-svwait ${s6_svwait_options_stop} "${s6_service_path}"
-   rc=$?
+   s6-svwait ${s6_svwait_options_stop} "${s6_service_link}"
fi
-   eend $rc "Failed to stop $RC_SVCNAME"
+   sleep 1.5
+   set -- $(s6-svstat "${s6_service_link}")
+   [ "$1" = "down" ] && rm -fr "${s6_service_link}"
+   eend $? "Failed to stop $RC_SVCNAME"
 }
 
 s6_status()
 {
-   s6-svstat "${s6_service_path}"
+   s6_service_link="${RC_SVCDIR}/s6-scan/${s6_service_path##*/}"
+   s6-svstat "${s6_service_link}"
 }



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

2015-05-08 Thread William Hubbs
commit: abef2fcb2dbcc277bb05f0d9c674d4b47826f17f
Author: William Hubbs  gmail  com>
AuthorDate: Fri May  8 16:29:49 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri May  8 16:39:39 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=abef2fcb

Make the default start, stop and status functions overridable

This will make it possible to add support for supervision suites such as
runit and s6.

 etc/rc.conf.in  |  6 
 sh/Makefile |  2 +-
 sh/openrc-run.sh.in | 75 ++---
 sh/start-stop-daemon.sh | 71 ++
 4 files changed, 87 insertions(+), 67 deletions(-)

diff --git a/etc/rc.conf.in b/etc/rc.conf.in
index 69a5cf2..b16aaff 100644
--- a/etc/rc.conf.in
+++ b/etc/rc.conf.in
@@ -77,6 +77,12 @@
 #rc_crashed_stop=NO
 #rc_crashed_start=YES
 
+# Set rc_supervisor to use a program to monitor your daemons and restart
+# them when they crash.
+# Leaving this undefined uses start-stop-daemon, which is OpenRC's
+# default.
+#rc_supervisor=""
+
 # Set rc_nocolor to yes if you do not want colors displayed in OpenRC
 # output.
 #rc_nocolor=NO

diff --git a/sh/Makefile b/sh/Makefile
index ee9d74d..3f8881e 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -1,7 +1,7 @@
 DIR=   ${LIBEXECDIR}/sh
 SRCS=  init.sh.in functions.sh.in gendepends.sh.in \
openrc-run.sh.in rc-functions.sh.in tmpfiles.sh.in ${SRCS-${OS}}
-INC=   rc-mount.sh functions.sh rc-functions.sh
+INC=   rc-mount.sh functions.sh rc-functions.sh start-stop-daemon.sh
 BIN=   gendepends.sh init.sh openrc-run.sh tmpfiles.sh ${BIN-${OS}}
 
 INSTALLAFTER=  _installafter

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index e279f11..4d286b2 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -125,72 +125,6 @@ _status()
fi
 }
 
-# Template start / stop / status functions
-start()
-{
-   [ -n "$command" ] || return 0
-   local _background=
-   ebegin "Starting ${name:-$RC_SVCNAME}"
-   if yesno "${command_background}"; then
-   if [ -z "${pidfile}" ]; then
-   eend 1 "command_background option used but no pidfile 
specified"
-   return 1
-   fi
-   _background="--background --make-pidfile"
-   fi
-   if yesno "$start_inactive"; then
-   local _inactive=false
-   service_inactive && _inactive=true
-   mark_service_inactive
-   fi
-   eval start-stop-daemon --start \
-   --exec $command \
-   ${chroot:+--chroot} $chroot \
-   ${procname:+--name} $procname \
-   ${pidfile:+--pidfile} $pidfile \
-   $_background $start_stop_daemon_args \
-   -- $command_args
-   if eend $? "Failed to start $RC_SVCNAME"; then
-   service_set_value "command" "${command}"
-   [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
-   [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
-   [ -n "${procname}" ] && service_set_value "procname" 
"${procname}"
-   return 0
-   fi
-   if yesno "$start_inactive"; then
-   if ! $_inactive; then
-   mark_service_stopped
-   fi
-   fi
-   return 1
-}
-
-stop()
-{
-   local startcommand="$(service_get_value "command")"
-   local startchroot="$(service_get_value "chroot")"
-   local startpidfile="$(service_get_value "pidfile")"
-   local startprocname="$(service_get_value "procname")"
-   command="${startcommand:-$command}"
-   chroot="${startchroot:-$chroot}"
-   pidfile="${startpidfile:-$pidfile}"
-   procname="${startprocname:-$procname}"
-   [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
-   ebegin "Stopping ${name:-$RC_SVCNAME}"
-   start-stop-daemon --stop \
-   ${retry:+--retry} $retry \
-   ${command:+--exec} $command \
-   ${procname:+--name} $procname \
-   ${pidfile:+--pidfile} $chroot$pidfile \
-   ${stopsig:+--signal} $stopsig
-   eend $? "Failed to stop $RC_SVCNAME"
-}
-
-status()
-{
-   _status
-}
-
 yesno $RC_DEBUG && set -x
 
 _conf_d=${RC_SERVICE%/*}/../conf.d
@@ -212,6 +146,15 @@ unset _conf_d
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
+# load a service supervisor
+sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
+if [ -n "$rc_supervisor" ]; then
+   if ! sourcex -e "@LIBEXECDIR@/sh/${rc_supervisor}.sh"; then
+   ewarn "$rc_supervisor is an invalid value for rc_supervisor"
+   ewarn "Using the default."
+   fi
+fi
+
 # Set verbose mode
 if yesno "${rc_verbose:-$RC_VERBOSE}"; then
EINFO_VERBOSE=yes

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
new file mode 100644
index 000..aae6792
--- /dev/nu

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

2015-04-21 Thread William Hubbs
commit: 15ab3f39c69ff8d69fd08a9cde7495a04b4dec9e
Author: William Hubbs  gmail  com>
AuthorDate: Mon Apr 13 16:15:58 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Tue Apr 21 16:30:24 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=15ab3f39

cgroups: use printf to write to cgroup files

This fixes #33.

 sh/rc-cgroup.sh.in | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 0426026..c7cac2a 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -1,6 +1,7 @@
 #!@SHELL@
 # Copyright (c) 2012 Alexander Vershilov 
 # Released under the 2-clause BSD license.
+
 extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
 description_cgroup_cleanup="Kill all processes in the cgroup"
 
@@ -47,7 +48,7 @@ cgroup_set_values()
$controller.*)
if [ -n "$name" -a -f "$cgroup/$name" -a -n 
"$val" ]; then
veinfo "$RC_SVCNAME: Setting 
$cgroup/$name to $val"
-   echo $val > "$cgroup/$name"
+   printf "%s" "$val" > "$cgroup/$name"
fi
name=$1
val=
@@ -60,12 +61,12 @@ cgroup_set_values()
done
if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
-   echo $val > "$cgroup/$name"
+   printf "%s" "$val" > "$cgroup/$name"
fi
 
if [ -f "$cgroup/tasks" ]; then
veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
-   echo 0 > "$cgroup/tasks"
+   printf "%d" 0 > "$cgroup/tasks"
fi
 
return 0
@@ -78,14 +79,14 @@ cgroup_add_service()
 # cgroups. But may lead to a problems where that inheriting
 # is needed.
for d in /sys/fs/cgroup/* ; do
-   [ -f "${d}"/tasks ] && echo 0 > "${d}"/tasks
+   [ -f "${d}"/tasks ] && printf "%d" 0 > "${d}"/tasks
done
 
openrc_cgroup=/sys/fs/cgroup/openrc
if [ -d "$openrc_cgroup" ]; then
cgroup="$openrc_cgroup/$RC_SVCNAME"
mkdir -p "$cgroup"
-   [ -f "$cgroup/tasks" ] && echo 0 > "$cgroup/tasks"
+   [ -f "$cgroup/tasks" ] && printf "%d" 0 > "$cgroup/tasks"
fi
 }
 



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

2015-04-21 Thread William Hubbs
commit: ee1768a419122d288256cce1723d4997bd965eab
Author: William Hubbs  gmail  com>
AuthorDate: Tue Mar 31 17:48:45 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Apr 20 22:10:07 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=ee1768a4

Add binfmt service to sysinit runlevel

This makes binfmt processing behave like tmpfiles processing which
follows the same specification as systemd.

This fixes #48.

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

 init.d/Makefile|  2 +-
 init.d/binfmt.in   | 20 +
 init.d/procfs.in   | 13 +
 runlevels/Makefile |  3 +-
 sh/.gitignore  |  1 +
 sh/Makefile|  6 ++--
 sh/binfmt.sh.in| 85 ++
 7 files changed, 113 insertions(+), 17 deletions(-)

diff --git a/init.d/Makefile b/init.d/Makefile
index 85925b1..0bd3651 100644
--- a/init.d/Makefile
+++ b/init.d/Makefile
@@ -21,7 +21,7 @@ SRCS-FreeBSD= hostid.in moused.in newsyslog.in pf.in rarpd.in 
rc-enabled.in \
 SRCS-FreeBSD+= adjkerntz.in devd.in dumpon.in encswap.in ipfw.in \
mixer.in nscd.in powerd.in syscons.in
 
-SRCS-Linux=devfs.in dmesg.in hwclock.in consolefont.in keymaps.in \
+SRCS-Linux=binfmt.in devfs.in dmesg.in hwclock.in consolefont.in 
keymaps.in \
killprocs.in modules.in mount-ro.in mtab.in numlock.in \
procfs.in sysfs.in termencoding.in tmpfiles.dev.in
 

diff --git a/init.d/binfmt.in b/init.d/binfmt.in
new file mode 100644
index 000..651b131
--- /dev/null
+++ b/init.d/binfmt.in
@@ -0,0 +1,20 @@
+#!@SBINDIR@/openrc-run
+# Copyright 2015 William Hubbs 
+# Released under the 2-clause BSD license.
+
+description="Register misc binary format handlers"
+
+depend()
+{
+   after procfs
+   use modules devfs
+   keyword -openvz -prefix -vserver -lxc
+}
+
+start()
+{
+   ebegin "Loading custom binary format handlers"
+   "$RC_LIBEXECDIR"/sh/binfmt.sh
+   eend $?
+return 0
+}

diff --git a/init.d/procfs.in b/init.d/procfs.in
index dfe58cb..167a1aa 100644
--- a/init.d/procfs.in
+++ b/init.d/procfs.in
@@ -15,24 +15,13 @@ start()
 {
# Setup Kernel Support for miscellaneous Binary Formats
if [ -d /proc/sys/fs/binfmt_misc -a ! -e 
/proc/sys/fs/binfmt_misc/register ]; then
+   modprobe -q binfmt-misc
if grep -qs binfmt_misc /proc/filesystems; then
ebegin "Mounting misc binary format filesystem"
mount -t binfmt_misc -o nodev,noexec,nosuid \
binfmt_misc /proc/sys/fs/binfmt_misc
-   if eend $? ; then
-   local fmts
-   ebegin "Loading custom binary format handlers"
-   fmts=$(grep -hsv -e '^[#;]' -e '^[[:space:]]*$' 
\
-   /run/binfmt.d/*.conf \
-   /etc/binfmt.d/*.conf \
-   ""/usr/lib/binfmt.d/*.conf)
-   if [ -n "${fmts}" ]; then
-   echo "${fmts}" > 
/proc/sys/fs/binfmt_misc/register
-   fi
eend $?
-   fi
fi
fi
-
return 0
 }

diff --git a/runlevels/Makefile b/runlevels/Makefile
index 25e3e1a..682d6e1 100644
--- a/runlevels/Makefile
+++ b/runlevels/Makefile
@@ -34,7 +34,8 @@ BOOT-FreeBSD+=hostid newsyslog savecore syslogd
 # FreeBSD specific stuff
 BOOT-FreeBSD+= adjkerntz dumpon syscons
 
-BOOT-Linux+=   hwclock keymaps modules mtab procfs termencoding tmpfiles.setup
+BOOT-Linux+=   binfmt hwclock keymaps modules mtab procfs termencoding \
+   tmpfiles.setup
 SHUTDOWN-Linux=killprocs mount-ro
 SYSINIT-Linux= devfs dmesg sysfs tmpfiles.dev
 

diff --git a/sh/.gitignore b/sh/.gitignore
index d5cb215..c83b730 100644
--- a/sh/.gitignore
+++ b/sh/.gitignore
@@ -8,3 +8,4 @@ init-early.sh
 rc-cgroup.sh
 tmpfiles.sh
 migrate-to-run.sh
+binfmt.sh

diff --git a/sh/Makefile b/sh/Makefile
index c1953f3..8f742dc 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -12,9 +12,9 @@ include ${MK}/os.mk
 SRCS-FreeBSD=
 BIN-FreeBSD=
 
-SRCS-Linux=cgroup-release-agent.sh.in init-early.sh.in 
migrate-to-run.sh.in \
-   rc-cgroup.sh.in
-BIN-Linux= cgroup-release-agent.sh init-early.sh migrate-to-run.sh \
+SRCS-Linux=binfmt.sh.in cgroup-release-agent.sh.in init-early.sh.in \
+   migrate-to-run.sh.in rc-cgroup.sh.in
+BIN-Linux= binfmt.sh cgroup-release-agent.sh init-early.sh 
migrate-to-run.sh \
rc-cgroup.sh
 
 SRCS-NetBSD=

diff --git a/sh/binfmt.sh.in b/sh/binfmt.sh.in
new file mode 100644
index 000..b636bac
--- /dev/null
+++ b/sh/binfmt.sh.in
@@ -0,0 +1,85 @@
+#!@SHELL@
+# This is a reimplementation of the systemd binfmt.d code to re

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

2015-04-08 Thread William Hubbs
commit: 1eab656ca1d3258ff00495710a68ad459ce50d3e
Author: William Hubbs  gmail  com>
AuthorDate: Wed Apr  1 15:55:09 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Apr  8 14:57:46 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=1eab656c

Fix tmpfiles processing

Tmpfiles.d processing had /run overriding /usr/lib and /etc, but this is
not correct. The correct order, from lowest to highest, for tmpfiles
processing is:

* /usr/lib/tmpfiles.d/*.conf
* /run/tmpfiles.d/*.conf
* /etc/tmpfiles.d

This means /run/tmpfiles.d/*.conf can override /etc/tmpfiles.d/*.conf,
but /etc/tmpfiles.d/*.conf can override both of them.

This fixes #49.

 sh/tmpfiles.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 6e7be42..046bf9f 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -245,7 +245,7 @@ PREFIX=
 FILE=
 fragments=
 # XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
-tmpfiles_dirs='/usr/lib/tmpfiles.d/ /etc/tmpfiles.d/ /run/tmpfiles.d/'
+tmpfiles_dirs='/usr/lib/tmpfiles.d/ /run/tmpfiles.d/ /etc/tmpfiles.d/'
 tmpfiles_basenames=''
 tmpfiles_d=''
 # Build a list of sorted unique basenames



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

2015-03-29 Thread William Hubbs
commit: c068762c4cf49e7ea9719dcab2e5f7d4c4e7e2e5
Author: William Hubbs  gmail  com>
AuthorDate: Sun Mar 29 20:20:52 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sun Mar 29 23:05:32 2015 +
URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=c068762c

Fix rc_verbose processing

We were processing the rc_verbose setting before we sourced the
configuration file where it was set; this fixes the issue.

Fixes #46

 sh/runscript.sh.in | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 06d51d0..4c47260 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -189,10 +189,6 @@ status()
 }
 
 yesno $RC_DEBUG && set -x
-if yesno "${rc_verbose:-$RC_VERBOSE}"; then
-   EINFO_VERBOSE=yes
-   export EINFO_VERBOSE
-fi
 
 _conf_d=${RC_SERVICE%/*}/../conf.d
 # If we're net.eth0 or openvpn.work then load net or openvpn config
@@ -213,6 +209,12 @@ unset _conf_d
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
+# Set verbose mode
+if yesno "${rc_verbose:-$RC_VERBOSE}"; then
+   EINFO_VERBOSE=yes
+   export EINFO_VERBOSE
+fi
+
 for _cmd; do
if [ "$_cmd" != status -a "$_cmd" != describe ]; then
# Apply any ulimit defined



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

2015-01-12 Thread William Hubbs
commit: 7e3a33c8f5ccae03e035cf4c9d1c3c01a0f57b1e
Author: William Hubbs  gmail  com>
AuthorDate: Mon Jan 12 20:37:10 2015 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Jan 12 20:45:06 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=7e3a33c8

Add description for cgroup_cleanup

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

---
 sh/rc-cgroup.sh.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index b635340..0426026 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -2,6 +2,7 @@
 # Copyright (c) 2012 Alexander Vershilov 
 # Released under the 2-clause BSD license.
 extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
+description_cgroup_cleanup="Kill all processes in the cgroup"
 
 cgroup_find_path()
 {



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

2014-10-22 Thread William Hubbs
commit: d8e1d9a6edf94ecac580e80e1113f4fdbdc5a23b
Author: Gabriele Giacone <1o5g4r8o  gmail  com>
AuthorDate: Tue Oct 21 07:24:12 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Oct 22 16:09:58 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=d8e1d9a6

Add missing files for GNU/kFreeBSD

---
 conf.d/network.GNU-kFreeBSD.in |  4 
 conf.d/staticroute.GNU-kFreeBSD.in |  5 +
 init.d/sysctl.GNU-kFreeBSD.in  | 31 +++
 mk/os-GNU-kFreeBSD.mk  |  4 +++-
 sh/init.sh.GNU-kFreeBSD.in | 35 +++
 5 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/conf.d/network.GNU-kFreeBSD.in b/conf.d/network.GNU-kFreeBSD.in
new file mode 100644
index 000..9f49b81
--- /dev/null
+++ b/conf.d/network.GNU-kFreeBSD.in
@@ -0,0 +1,4 @@
+
+# You can assign a default route
+#defaultroute="192.168.0.1"
+#defaultroute6="2001:a:b:c"

diff --git a/conf.d/staticroute.GNU-kFreeBSD.in 
b/conf.d/staticroute.GNU-kFreeBSD.in
new file mode 100644
index 000..9f54152
--- /dev/null
+++ b/conf.d/staticroute.GNU-kFreeBSD.in
@@ -0,0 +1,5 @@
+# Separate multiple routes using ; or new lines.
+
+# Example static routes. See route(8) for syntax.
+#staticroute="net 192.168.0.0 10.73.1.1 netmask 255.255.255.0
+#net 192.168.1.0 10.73.1.1 netmask 255.255.255.0"

diff --git a/init.d/sysctl.GNU-kFreeBSD.in b/init.d/sysctl.GNU-kFreeBSD.in
new file mode 100644
index 000..92d5868
--- /dev/null
+++ b/init.d/sysctl.GNU-kFreeBSD.in
@@ -0,0 +1,31 @@
+#!@SBINDIR@/openrc-run
+# Copyright (c) 2007-2009 Roy Marples 
+# Released under the 2-clause BSD license.
+
+depend()
+{
+   before bootmisc logger
+   keyword -prefix
+}
+
+start()
+{
+   [ -e /etc/sysctl.conf ] || return 0
+   local retval=0 var= comments= conf=
+   ebegin "Configuring kernel parameters"
+   eindent
+   for conf in @SYSCONFDIR@/sysctl.conf @SYSCONFDIR@/sysctl.d/*.conf; do
+   if [ -r "$conf" ]; then
+   vebegin "applying $conf"
+   while read var comments; do
+   case "$var" in
+   ""|"#"*) continue;;
+   esac
+   sysctl -w "$var" >/dev/null || retval=1
+   done < "$conf"
+   veend $retval
+   fi
+   done
+   eoutdent
+   eend $retval "Some errors were encountered"
+}

diff --git a/mk/os-GNU-kFreeBSD.mk b/mk/os-GNU-kFreeBSD.mk
index 72fea3e..c217372 100644
--- a/mk/os-GNU-kFreeBSD.mk
+++ b/mk/os-GNU-kFreeBSD.mk
@@ -3,7 +3,9 @@
 
 # Generic definitions
 
+SFX=   .GNU-kFreeBSD.in
+PKG_PREFIX?=   /usr
+
 CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=700
 LIBDL= -Wl,-Bdynamic -ldl
 LIBKVM?=
-include ${MK}/os-BSD.mk

diff --git a/sh/init.sh.GNU-kFreeBSD.in b/sh/init.sh.GNU-kFreeBSD.in
new file mode 100644
index 000..d1a04e1
--- /dev/null
+++ b/sh/init.sh.GNU-kFreeBSD.in
@@ -0,0 +1,35 @@
+#!@SHELL@
+# Copyright (c) 2007-2009 Roy Marples 
+# Released under the 2-clause BSD license.
+
+if [ ! -d /run ]; then
+ebegin "Creating /run"
+mkdir -p /run
+eend $?
+fi
+
+if [ -L $RC_SVCDIR ]; then
+rm $RC_SVCDIR
+fi
+
+ebegin "Mounting /run"
+if ! fstabinfo --mount /run; then
+mount -t tmpfs -o mode=0755,noexec,nosuid,size=10% tmpfs /run
+if [ $? != 0 ]; then
+eerror "Unable to mount tmpfs on /run."
+eerror "Can't continue."
+exit 1
+fi
+fi
+eend
+
+ebegin "Creating $RC_SVCDIR"
+mkdir -p $RC_SVCDIR
+eend $?
+
+if [ -e "$RC_LIBEXECDIR"/cache/deptree ]; then
+cp -p "$RC_LIBEXECDIR"/cache/* "$RC_SVCDIR" 2>/dev/null
+fi
+
+echo sysinit >"$RC_SVCDIR"/softlevel
+exit 0



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

2014-10-20 Thread William Hubbs
commit: 8c7ea4e9e8da500877a514402bbe90aababda2d6
Author: William Hubbs  gmail  com>
AuthorDate: Mon Oct 20 00:36:57 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Mon Oct 20 20:44:19 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=8c7ea4e9

runscript.sh: add chroot support

This adds support for a chroot variable which will be passed to the
start-stop-daemon --chroot switch to runscript.sh when starting a
daemon. This also needs to be saved so it can be used in locating the
pid file when stopping the daemon.

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

---
 man/openrc-run.8   | 3 +++
 sh/runscript.sh.in | 6 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/man/openrc-run.8 b/man/openrc-run.8
index c8bf24d..3308f24 100644
--- a/man/openrc-run.8
+++ b/man/openrc-run.8
@@ -120,6 +120,9 @@ Set this to "true", "yes" or "1" (case-insensitive) to 
force the daemon into
 the background. This implies the "--make-pidfile" and "--pidfile" option of
 .Xr start-stop-daemon 8
 so the pidfile variable must be set.
+.It Ar chroot
+.Xr start-stop-daemon 8
+will chroot into this path before writing the pid file or starting the daemon.
 .It Ar pidfile
 Pidfile to use for the above defined command.
 .It Ar name

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index b89c460..06d51d0 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -142,12 +142,14 @@ start()
fi
eval start-stop-daemon --start \
--exec $command \
+   ${chroot:+--chroot} $chroot \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
$_background $start_stop_daemon_args \
-- $command_args
if eend $? "Failed to start $RC_SVCNAME"; then
service_set_value "command" "${command}"
+   [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
[ -n "${procname}" ] && service_set_value "procname" 
"${procname}"
return 0
@@ -163,9 +165,11 @@ start()
 stop()
 {
local startcommand="$(service_get_value "command")"
+   local startchroot="$(service_get_value "chroot")"
local startpidfile="$(service_get_value "pidfile")"
local startprocname="$(service_get_value "procname")"
command="${startcommand:-$command}"
+   chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}"
procname="${startprocname:-$procname}"
[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
@@ -174,7 +178,7 @@ stop()
${retry:+--retry} $retry \
${command:+--exec} $command \
${procname:+--name} $procname \
-   ${pidfile:+--pidfile} $pidfile \
+   ${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig
eend $? "Failed to stop $RC_SVCNAME"
 }



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

2014-09-11 Thread William Hubbs
commit: 50658449bd46f1a53b8eb11d34f6eefdd1ceba9c
Author: Roy Marples  marples  name>
AuthorDate: Thu Sep 11 18:26:58 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 11 18:26:58 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=50658449

Use exception-based approach for cgroup/ulimit setup

Note from William Hubbs:
I spoke with Roy about this, and he pointed out that user-defined
functions may need the limits applied, so it is better to go with a
method that uses exceptions to determine which functions apply the
limits.

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

---
 sh/runscript.sh.in | 34 ++
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index d4c7c60..b89c460 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -209,19 +209,29 @@ unset _conf_d
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
-# Apply any ulimit defined
-[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
-
-# Apply cgroups settings if defined
-if [ "$1" = "start" ] ; then
-   if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then
-   cgroup_add_service /sys/fs/cgroup/openrc
-   cgroup_add_service /sys/fs/cgroup/systemd/system
+for _cmd; do
+   if [ "$_cmd" != status -a "$_cmd" != describe ]; then
+   # Apply any ulimit defined
+   [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && \
+   ulimit ${rc_ulimit:-$RC_ULIMIT}
+   # Apply cgroups settings if defined
+   if [ "$(command -v cgroup_add_service)" = \
+   "cgroup_add_service" ]
+   then
+   if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
+   eerror "No permission to apply cgroup settings"
+   break
+   fi
+   cgroup_add_service /sys/fs/cgroup/openrc
+   cgroup_add_service /sys/fs/cgroup/systemd/system
+   fi
+   [ "$(command -v cgroup_set_limits)" = \
+   "cgroup_set_limits" ] && \
+   cgroup_set_limits
+   break
fi
-   [ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \
-   cgroup_set_limits
-fi
-
+done
+ 
 # Load our script
 sourcex "$RC_SERVICE"
 



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

2014-09-11 Thread William Hubbs
commit: de60ffeebe93ffdc09c1dda51e04f29485d96cdb
Author: William Hubbs  gmail  com>
AuthorDate: Thu Sep 11 17:02:51 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Sep 11 17:02:51 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=de60ffee

runscript: move verbose mode setting near debug setting

---
 sh/runscript.sh.in | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 9b2ae0e..d4c7c60 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -185,6 +185,10 @@ status()
 }
 
 yesno $RC_DEBUG && set -x
+if yesno "${rc_verbose:-$RC_VERBOSE}"; then
+   EINFO_VERBOSE=yes
+   export EINFO_VERBOSE
+fi
 
 _conf_d=${RC_SERVICE%/*}/../conf.d
 # If we're net.eth0 or openvpn.work then load net or openvpn config
@@ -208,12 +212,6 @@ sourcex -e "@SYSCONFDIR@/rc.conf"
 # Apply any ulimit defined
 [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
 
-# Set verbose mode
-if yesno "${rc_verbose:-$RC_VERBOSE}"; then
-   EINFO_VERBOSE=yes
-   export EINFO_VERBOSE
-fi
-
 # Apply cgroups settings if defined
 if [ "$1" = "start" ] ; then
if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then



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

2014-08-28 Thread William Hubbs
commit: 6f3f50d4530f583d0d2aedec8af20077a9d07f4f
Author: Andrew Gregory  gmail  com>
AuthorDate: Mon Aug 25 19:37:45 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Aug 27 22:48:34 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=6f3f50d4

tmpfiles.sh: add support for + modifier

systemd added support for b+, c+, p+, and L+ in 2e78fa79 and 1554afae to
remove the target path if it already exists.

---
 sh/tmpfiles.sh.in | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 42a3639..41f86cf 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -304,6 +304,7 @@ for FILE in $tmpfiles_d ; do
# But IS allowed when globs are expanded for the x/r/R/z/Z types.
while read cmd path mode uid gid age arg; do
LINENUM=$(( LINENUM+1 ))
+   FORCE=0
 
# Unless we have both command and path, skip this line.
if [ -z "$cmd" -o -z "$path" ]; then
@@ -311,13 +312,20 @@ for FILE in $tmpfiles_d ; do
fi
 
case $cmd in
-   *!) [ "$BOOT" -eq "1" ] || continue; cmd=${cmd%!} ;;
+   \#*) continue ;;
esac
 
+   while [ ${#cmd} -gt 1 ]; do
+   case $cmd in
+   *!) cmd=${cmd%!}; [ "$BOOT" -eq "1" ] || 
continue 2 ;;
+   *+) cmd=${cmd%+}; FORCE=1; ;;
+   *) warninvalid ; continue 2 ;;
+   esac
+   done
+
# whine about invalid entries
case $cmd in
f|F|w|d|D|p|L|c|b|x|X|r|R|z|Z) ;;
-   \#*) continue ;;
*) warninvalid ; continue ;;
esac
 
@@ -338,6 +346,13 @@ for FILE in $tmpfiles_d ; do
 
[ -n "$EXCLUDE" ] && checkprefix $path $EXCLUDE && continue
[ -n "$PREFIX" ] && ! checkprefix $path $PREFIX && continue
+
+   if [ $FORCE -gt 0 ]; then
+   case $cmd in
+   p|L|c|b) [ -f "$path" ] && dryrun_or_real rm -f 
"$path"
+   esac
+   fi
+
[ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
_$cmd "$@"
rc=$?



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

2014-08-28 Thread William Hubbs
commit: d4204a97a2410fcf37a64385204e6452c6958e8d
Author: Andrew Gregory  gmail  com>
AuthorDate: Mon Aug 25 19:46:28 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Aug 27 22:49:00 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=d4204a97

tmpfiles.sh: add support for C action

Recursively copies files or directories.  Added by systemd in 849958d1.

---
 sh/tmpfiles.sh.in | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 41f86cf..6e7be42 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -80,6 +80,17 @@ _c() {
fi
 }
 
+_C() {
+   # recursively copy a file or directory
+   local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
+   if [ ! -e "$path" ]; then
+   dryrun_or_real cp -r "$arg" "$path"
+   _restorecon "$path"
+   [ $uid != '-' ] && dryrun_or_real chown "$uid" "$path"
+   [ $gid != '-' ] && dryrun_or_real chgrp "$gid" "$path"
+   [ $mode != '-' ] && dryrun_or_real chmod "$mode" "$path"
+   fi
+}
 
 _f() {
# Create a file if it doesn't exist yet
@@ -325,7 +336,7 @@ for FILE in $tmpfiles_d ; do
 
# whine about invalid entries
case $cmd in
-   f|F|w|d|D|p|L|c|b|x|X|r|R|z|Z) ;;
+   f|F|w|d|D|p|L|c|C|b|x|X|r|R|z|Z) ;;
*) warninvalid ; continue ;;
esac
 
@@ -334,7 +345,7 @@ for FILE in $tmpfiles_d ; do
case "$cmd" in
p|f|F) mode=0644 ;;
d|D) mode=0755 ;;
-   z|Z|x|r|R|L) ;;
+   C|z|Z|x|r|R|L) ;;
esac
fi
 



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

2014-08-22 Thread William Hubbs
commit: 6f080e9c1a2a9b9c308cdc03f9cf782c4ce4d440
Author: Jason Zaman  perfinion  com>
AuthorDate: Wed Aug 13 06:50:34 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Aug 13 15:02:20 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=6f080e9c

tmpfiles: Move relabelling before any other calls for device nodes

Device nodes are normally never device_t so this type does not
have many permissions. After the mknod, the device should have
its label corrected before any other operations (like chmod).

---
 sh/tmpfiles.sh.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 63c5d14..8538545 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -65,8 +65,8 @@ _b() {
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
-   dryrun_or_real chown $uid:$gid $path
_restorecon "$path"
+   dryrun_or_real chown $uid:$gid $path
fi
 }
 
@@ -75,8 +75,8 @@ _c() {
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
-   dryrun_or_real chown $uid:$gid $path
_restorecon "$path"
+   dryrun_or_real chown $uid:$gid $path
fi
 }
 



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

2014-08-22 Thread William Hubbs
commit: 647e08eb9166d23d0c64f0c8767d93a06bd21a40
Author: Jason Zaman  perfinion  com>
AuthorDate: Tue Aug  5 22:12:35 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Aug  7 17:54:04 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=647e08eb

tmpfiles.sh: do not use install

install is in /usr which causes problems if /usr is not mounted.
Instead, checkpath and "mkdir -p" can do everything required and are
both available before /usr is mounted.
Since checkpath also handles selinux labels correctly,
_restorecon after is not required.

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

---
 sh/tmpfiles.sh.in | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index da64011..63c5d14 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -15,6 +15,7 @@
 #
 
 DRYRUN=0
+CHECKPATH="@LIBEXECDIR@/bin/checkpath"
 
 checkprefix() {
n=$1
@@ -87,9 +88,8 @@ _f() {
[ $CREATE -gt 0 ] || return 0
 
if [ ! -e "$path" ]; then
-   dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null 
"$path"
+   dryrun_or_real $CHECKPATH -fq -m "$mode" -o "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
-   _restorecon "$path"
fi
 }
 
@@ -99,9 +99,8 @@ _F() {
 
[ $CREATE -gt 0 ] || return 0
 
-   dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
+   dryrun_or_real $CHECKPATH -Fq -m "$mode" -o "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
-   _restorecon "$path"
 }
 
 _d() {
@@ -111,8 +110,8 @@ _d() {
[ $CREATE -gt 0 ] || return 0
 
if [ ! -d "$path" ]; then
-   dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
-   _restorecon "$path"
+   dryrun_or_real mkdir -p "$path" 2>/dev/null
+   dryrun_or_real $CHECKPATH -dq -m "$mode" -o "$uid:$gid" "$path"
fi
 }
 
@@ -126,8 +125,8 @@ _D() {
fi
 
if [ $CREATE -gt 0 ]; then
-   dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
-   _restorecon "$path"
+   dryrun_or_real mkdir -p "$path" 2>/dev/null
+   dryrun_or_real $CHECKPATH -Dq -m "$mode" -o "$uid:$gid" "$path"
fi
 }
 
@@ -145,9 +144,7 @@ _p() {
[ $CREATE -gt 0 ] || return 0
 
if [ ! -p "$path" ]; then
-   dryrun_or_real mkfifo -m$mode "$path"
-   dryrun_or_real chown "$uid:$gid" "$path"
-   _restorecon "$path"
+   dryrun_or_real $CHECKPATH -pq -m $mode -o "$uid:$gid" "$path"
fi
 }
 



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

2014-08-22 Thread William Hubbs
commit: c8018d04a7b238b57a3d74a68e2af02af395f510
Author: William Hubbs  gmail  com>
AuthorDate: Wed Aug 13 20:26:37 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Aug 13 20:26:37 2014 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=c8018d04

tmpfiles: fix relabel to run restorecon before chown and chmod

---
 sh/tmpfiles.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 8538545..42a3639 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -45,10 +45,10 @@ relabel() {
 
for path in ${paths}; do
if [ -e "$path" ]; then
+   [ -x /sbin/restorecon ] && dryrun_or_real restorecon 
$CHOPTS "$path"
[ $uid != '-' ] && dryrun_or_real chown $CHOPTS "$uid" 
"$path"
[ $gid != '-' ] && dryrun_or_real chgrp $CHOPTS "$gid" 
"$path"
[ $mode != '-' ] && dryrun_or_real chmod $CHOPTS 
"$mode" "$path"
-   [ -x /sbin/restorecon ] && dryrun_or_real restorecon 
$CHOPTS "$path"
fi
done
 }



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

2014-08-13 Thread William Hubbs
commit: c8018d04a7b238b57a3d74a68e2af02af395f510
Author: William Hubbs  gmail  com>
AuthorDate: Wed Aug 13 20:26:37 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Aug 13 20:26:37 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=c8018d04

tmpfiles: fix relabel to run restorecon before chown and chmod

---
 sh/tmpfiles.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 8538545..42a3639 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -45,10 +45,10 @@ relabel() {
 
for path in ${paths}; do
if [ -e "$path" ]; then
+   [ -x /sbin/restorecon ] && dryrun_or_real restorecon 
$CHOPTS "$path"
[ $uid != '-' ] && dryrun_or_real chown $CHOPTS "$uid" 
"$path"
[ $gid != '-' ] && dryrun_or_real chgrp $CHOPTS "$gid" 
"$path"
[ $mode != '-' ] && dryrun_or_real chmod $CHOPTS 
"$mode" "$path"
-   [ -x /sbin/restorecon ] && dryrun_or_real restorecon 
$CHOPTS "$path"
fi
done
 }



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

2014-08-13 Thread William Hubbs
commit: 6f080e9c1a2a9b9c308cdc03f9cf782c4ce4d440
Author: Jason Zaman  perfinion  com>
AuthorDate: Wed Aug 13 06:50:34 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Aug 13 15:02:20 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=6f080e9c

tmpfiles: Move relabelling before any other calls for device nodes

Device nodes are normally never device_t so this type does not
have many permissions. After the mknod, the device should have
its label corrected before any other operations (like chmod).

---
 sh/tmpfiles.sh.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 63c5d14..8538545 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -65,8 +65,8 @@ _b() {
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
-   dryrun_or_real chown $uid:$gid $path
_restorecon "$path"
+   dryrun_or_real chown $uid:$gid $path
fi
 }
 
@@ -75,8 +75,8 @@ _c() {
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
-   dryrun_or_real chown $uid:$gid $path
_restorecon "$path"
+   dryrun_or_real chown $uid:$gid $path
fi
 }
 



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

2014-08-07 Thread William Hubbs
commit: 647e08eb9166d23d0c64f0c8767d93a06bd21a40
Author: Jason Zaman  perfinion  com>
AuthorDate: Tue Aug  5 22:12:35 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Aug  7 17:54:04 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=647e08eb

tmpfiles.sh: do not use install

install is in /usr which causes problems if /usr is not mounted.
Instead, checkpath and "mkdir -p" can do everything required and are
both available before /usr is mounted.
Since checkpath also handles selinux labels correctly,
_restorecon after is not required.

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

---
 sh/tmpfiles.sh.in | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index da64011..63c5d14 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -15,6 +15,7 @@
 #
 
 DRYRUN=0
+CHECKPATH="@LIBEXECDIR@/bin/checkpath"
 
 checkprefix() {
n=$1
@@ -87,9 +88,8 @@ _f() {
[ $CREATE -gt 0 ] || return 0
 
if [ ! -e "$path" ]; then
-   dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null 
"$path"
+   dryrun_or_real $CHECKPATH -fq -m "$mode" -o "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
-   _restorecon "$path"
fi
 }
 
@@ -99,9 +99,8 @@ _F() {
 
[ $CREATE -gt 0 ] || return 0
 
-   dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
+   dryrun_or_real $CHECKPATH -Fq -m "$mode" -o "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
-   _restorecon "$path"
 }
 
 _d() {
@@ -111,8 +110,8 @@ _d() {
[ $CREATE -gt 0 ] || return 0
 
if [ ! -d "$path" ]; then
-   dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
-   _restorecon "$path"
+   dryrun_or_real mkdir -p "$path" 2>/dev/null
+   dryrun_or_real $CHECKPATH -dq -m "$mode" -o "$uid:$gid" "$path"
fi
 }
 
@@ -126,8 +125,8 @@ _D() {
fi
 
if [ $CREATE -gt 0 ]; then
-   dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
-   _restorecon "$path"
+   dryrun_or_real mkdir -p "$path" 2>/dev/null
+   dryrun_or_real $CHECKPATH -Dq -m "$mode" -o "$uid:$gid" "$path"
fi
 }
 
@@ -145,9 +144,7 @@ _p() {
[ $CREATE -gt 0 ] || return 0
 
if [ ! -p "$path" ]; then
-   dryrun_or_real mkfifo -m$mode "$path"
-   dryrun_or_real chown "$uid:$gid" "$path"
-   _restorecon "$path"
+   dryrun_or_real $CHECKPATH -pq -m $mode -o "$uid:$gid" "$path"
fi
 }
 



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

2014-07-16 Thread William Hubbs
commit: 4f784bd46923486773edcd7749246a21bd419e6b
Author: Jason Zaman  perfinion  com>
AuthorDate: Tue Jul 15 18:27:32 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Wed Jul 16 15:53:25 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=4f784bd4

tmpfiles: set the proper SELinux context

Restore the label on the created file / dir based on the policy
fcontexts.

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

---
 sh/tmpfiles.sh.in | 16 
 1 file changed, 16 insertions(+)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 66612fc..da64011 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -52,12 +52,20 @@ relabel() {
done
 }
 
+_restorecon() {
+local path=$1
+if [ -x /sbin/restorecon ]; then
+dryrun_or_real restorecon -F "$path"
+fi
+}
+
 _b() {
# Create a block device node if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
dryrun_or_real chown $uid:$gid $path
+   _restorecon "$path"
fi
 }
 
@@ -67,6 +75,7 @@ _c() {
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
dryrun_or_real chown $uid:$gid $path
+   _restorecon "$path"
fi
 }
 
@@ -80,6 +89,7 @@ _f() {
if [ ! -e "$path" ]; then
dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null 
"$path"
[ -z "$arg" ] || _w "$@"
+   _restorecon "$path"
fi
 }
 
@@ -91,6 +101,7 @@ _F() {
 
dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
[ -z "$arg" ] || _w "$@"
+   _restorecon "$path"
 }
 
 _d() {
@@ -101,6 +112,7 @@ _d() {
 
if [ ! -d "$path" ]; then
dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
+   _restorecon "$path"
fi
 }
 
@@ -110,10 +122,12 @@ _D() {
 
if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
dryrun_or_real find "$path" -mindepth 1 -maxdepth 1 -xdev -exec 
rm -rf {} +
+   _restorecon "$path"
fi
 
if [ $CREATE -gt 0 ]; then
dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
+   _restorecon "$path"
fi
 }
 
@@ -121,6 +135,7 @@ _L() {
# Create a symlink if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ ! -e "$path" ] && dryrun_or_real ln -s "$arg" "$path"
+   _restorecon "$path"
 }
 
 _p() {
@@ -132,6 +147,7 @@ _p() {
if [ ! -p "$path" ]; then
dryrun_or_real mkfifo -m$mode "$path"
dryrun_or_real chown "$uid:$gid" "$path"
+   _restorecon "$path"
fi
 }
 



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

2014-07-10 Thread William Hubbs
commit: 75e06d85584fc3ebfa26fbca97ea60b687247bb0
Author: William Hubbs  gmail  com>
AuthorDate: Thu Jul 10 10:18:00 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jul 10 15:57:56 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=75e06d85

Style Fixes

---
 sh/runscript.sh.in | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index c72a784..9b2ae0e 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -216,12 +216,12 @@ fi
 
 # Apply cgroups settings if defined
 if [ "$1" = "start" ] ; then
-if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then
-   cgroup_add_service /sys/fs/cgroup/openrc
-   cgroup_add_service /sys/fs/cgroup/systemd/system
-fi
-[ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \
-   cgroup_set_limits
+   if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then
+   cgroup_add_service /sys/fs/cgroup/openrc
+   cgroup_add_service /sys/fs/cgroup/systemd/system
+   fi
+   [ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \
+   cgroup_set_limits
 fi
 
 # Load our script



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

2014-07-10 Thread William Hubbs
commit: 1a44be0f16a7a1de8a176e7c656f8513494e0e64
Author: Alexander V Vershilov  gentoo  org>
AuthorDate: Sun Feb 16 00:27:52 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Jul 10 15:56:37 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=1a44be0f

cgroups: only run cgroup setup when starting a service

Status call should not set limits as it requires root permissions,
also this is not safe, as current process may reach limitation.

Solution is to set limits and move process to service cgroup only
on start.

X-GENTOO-BUG: 500364
X-GENTOO-BUG-URL: https://bugs.gentoo.org/show_bug.cgi?id=500364

---
 sh/runscript.sh.in | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index ceb9ab4..c72a784 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -215,12 +215,14 @@ if yesno "${rc_verbose:-$RC_VERBOSE}"; then
 fi
 
 # Apply cgroups settings if defined
+if [ "$1" = "start" ] ; then
 if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then
cgroup_add_service /sys/fs/cgroup/openrc
cgroup_add_service /sys/fs/cgroup/systemd/system
 fi
 [ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \
cgroup_set_limits
+fi
 
 # Load our script
 sourcex "$RC_SERVICE"



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

2014-06-20 Thread William Hubbs
commit: 094bc17cb0ad75da189ebf1a8242a378928a1eef
Author: William Hubbs  gmail  com>
AuthorDate: Sat Jun 21 00:39:07 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Sat Jun 21 00:39:07 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=094bc17c

tmpfiles.sh: fix comment processing

If you happened to format a comment with no white space after the '#',
it was not being processed.

Reported-by: consus  gmx.com
X-Gentoo-Bug: 511804
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=511804

---
 sh/tmpfiles.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 6d4c614..66612fc 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -304,7 +304,7 @@ for FILE in $tmpfiles_d ; do
# whine about invalid entries
case $cmd in
f|F|w|d|D|p|L|c|b|x|X|r|R|z|Z) ;;
-   \#) continue ;;
+   \#*) continue ;;
*) warninvalid ; continue ;;
esac
 



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

2014-06-20 Thread William Hubbs
commit: 19cccb2e9416311b85fcad3c15d4d988fed2f954
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon May 26 06:51:37 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Fri Jun 20 21:19:25 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=19cccb2e

sh/tmpfiles.sh: license under 2-clause BSD

As the author of our tmpfiles.sh script, I hereby license it under
2-clause BSD, like the rest of openrc.

Signed-off-by: Robin H. Johnson  gentoo.org>

---
 sh/tmpfiles.sh.in | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index a903163..6d4c614 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -3,10 +3,11 @@
 # Control creation, deletion, and cleaning of volatile and temporary files
 #
 # Copyright (c) 2012 Gentoo Foundation
+# Released under the 2-clause BSD license.
 #
-# This instance based on the Arch Linux version:
+# This instance is a pure-POSIX sh version, written by Robin H Johnson
+# , based on the Arch Linux version as of 2012/01/01:
 # http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
-# As of 2012/01/01
 #
 # See the tmpfiles.d manpage as well:
 # http://0pointer.de/public/systemd-man/tmpfiles.d.html



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

2014-05-25 Thread Robin H. Johnson
commit: a0596076dd97a35f0dfb6d601bc12e2297f66c7f
Author: Robin H. Johnson  gentoo  org>
AuthorDate: Mon May 26 06:51:37 2014 +
Commit: Robin H. Johnson  gentoo  org>
CommitDate: Mon May 26 06:51:44 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=a0596076

sh/tmpfiles.sh: license under 2-clause BSD

As the author of our tmpfiles.sh script, I hereby license it under
2-clause BSD, like the rest of openrc.

Signed-off-by: Robin H. Johnson  gentoo.org>

---
 sh/tmpfiles.sh.in | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index a903163..6d4c614 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -3,10 +3,11 @@
 # Control creation, deletion, and cleaning of volatile and temporary files
 #
 # Copyright (c) 2012 Gentoo Foundation
+# Released under the 2-clause BSD license.
 #
-# This instance based on the Arch Linux version:
+# This instance is a pure-POSIX sh version, written by Robin H Johnson
+# , based on the Arch Linux version as of 2012/01/01:
 # http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
-# As of 2012/01/01
 #
 # See the tmpfiles.d manpage as well:
 # http://0pointer.de/public/systemd-man/tmpfiles.d.html



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

2014-04-03 Thread William Hubbs
commit: c081633762dc66235fe385eedcc2cdf6bff83391
Author: Andrew Gregory  gmail  com>
AuthorDate: Thu Mar 27 15:02:47 2014 +
Commit: William Hubbs  gentoo  org>
CommitDate: Thu Mar 27 15:36:41 2014 +
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=c0816337

tmpfiles: ignore all files starting with systemd-

systemd recently moved creation of /run/nologin to systemd-nologin.conf

Signed-off-by: Andrew Gregory  gmail.com>

---
 sh/tmpfiles.sh.in | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 1a263f2..da588e2 100755
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -230,7 +230,9 @@ tmpfiles_d=''
 # `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
 for d in ${tmpfiles_dirs} ; do
[ -d $d ] && for f in ${d}/*.conf ; do
-   [ "$f" = "$d/systemd.conf" ] && continue
+   case "${f##*/}" in
+   systemd.conf|systemd-*.conf) continue;;
+   esac
[ -f $f ] && 
tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
done # for f in ${d}
 done # for d in ${tmpfiles_dirs}