On Wed, 10 Jan 2018 22:49:17 +0300 Mert Dirik <[email protected]> wrote:
> On 01/10/18 21:20, Petter Reinholdtsen wrote:
> > [Mert Dirik]
> >> Please forgive my naivety, but simply moving the argument shift part before
> >> sourcing /lib/lsb/init-functions seems to successfully redirect to
> >> systemctl.
> > Interesting. This seem like a very good idea. :)
> I'm happy to hear that.
> >
> >> The only variable leaking to /lib/lsb/init-functions is "script", which can be
> >> easily renamed and namespaced in case of a possible problem.
> > Perhaps good to give it some init-d-script related prefix, to reduce the
> > chance of a future collision?
> Maybe "__init_d_script_path"?
> >
> >> Is there anything wrong with this approach?
> > Nothing I could think of from the top of my head. :)
> >
> Great :) I'll test it again in stretch or sid and I'll post the result
> here. (previous test was done in jessie)
>

I've tested the attached patch in a sid lxc container and the issue seems to be fixed there.
Here is a relevant output:

root@sid:~# cat /etc/init.d/sleep-daemon
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          sleep-daemon
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Sleep daemon
# Description:       Sleep daemon
### END INIT INFO

# Author: Foo Bar <[email protected]>

DESC="Sleep daemon"
DAEMON=/bin/sleep
DAEMON_ARGS=120
START_ARGS="--background --make-pidfile"

root@sid:~# /etc/init.d/sleep-daemon start
[ ok ] Starting sleep-daemon (via systemctl): sleep-daemon.service.
root@sid:~# systemctl status sleep-daemon | cat
● sleep-daemon.service - LSB: Sleep daemon
   Loaded: loaded (/etc/init.d/sleep-daemon; generated; vendor preset: enabled)
   Active: active (running) since Wed 2018-01-10 22:35:58 UTC; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1467 ExecStop=/etc/init.d/sleep-daemon stop (code=exited, status=0/SUCCESS)   Process: 1513 ExecStart=/etc/init.d/sleep-daemon start (code=exited, status=0/SUCCESS)
    Tasks: 1 (limit: 4915)
   CGroup: /lxc/sid/system.slice/sleep-daemon.service
           └─1529 /bin/sleep 120

Jan 10 22:35:58 sid systemd[1]: Starting LSB: Sleep daemon...
Jan 10 22:35:58 sid systemd[1]: Started LSB: Sleep daemon.
root@sid:~#


--- init-d-script.orig	2018-01-11 01:04:11.340881210 +0300
+++ init-d-script	2018-01-11 01:10:20.426711408 +0300
@@ -1,6 +1,11 @@
 #!/bin/sh
 # See init-d-script(5) for instructions on how to use this library.
 #=============================================================================
+
+# Shift arguments early to fix #826214
+__init_d_script_name="$1"
+shift
+
 # Define LSB log_* functions.
 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
 # and status_of_proc is working.
@@ -153,12 +158,10 @@
     set -x
 fi
 
-SCRIPTNAME=$1
-scriptbasename="$(basename $1)"
+SCRIPTNAME="$__init_d_script_name"
+scriptbasename="$(basename "$__init_d_script_name")"
 if [ "$scriptbasename" != "init-d-script" ] ; then
-    script="$1"
-    shift
-    . $script
+    . "$__init_d_script_name"
 else
     exit 0
 fi
_______________________________________________
Pkg-sysvinit-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-sysvinit-devel

Reply via email to