On 11/22/18, Ian Jackson <ijack...@chiark.greenend.org.uk> wrote: > Mert Dirik writes ("Re: Bug#913247: Please provide a C implementation of > /lib/init/init-d-script"): >> On 11/22/18, Ian Jackson <ijack...@chiark.greenend.org.uk> wrote: >> > I don't know what `systemd redirection' is. Why does it not work ? >> > Can it be fixed ? >> >> To sum it up, when /lib/lsb/init-functions is sourced from a script in >> /etc/init.d, /lib/lsb/init-functions.d/40-systemd is also sourced and >> the script is executed using a corresponding "systemctl ...." command >> so that systemd can track the daemon. Relevant bug report is #826214. > > Thanks. > > This doesn't seem so difficult to fix. (CCing that bug.) > >> The problem here is, 40-systemd uses the value of "$0" to figure out >> whether the caller was a script inside /etc/init.d/ and using > > I just experimented: > > mariner:d> pwd > /u/iwj/junk/d > mariner:d> egrep . init-d-script daemon > init-d-script:#!/bin/sh > init-d-script:echo "in init-d-script \$0=$0 \$*=$*" > daemon:#!/usr/bin/env /u/iwj/junk/d/init-d-script > daemon:some thing or other > mariner:d> ./daemon start > in init-d-script $0=/u/iwj/junk/d/init-d-script $*=./daemon start > mariner:d> > > So I think this would be fixed if /lib/init/init-d-script detected > this situation and set $0 to the original script name (which it gets > in $1). That is probably desirable anyway.
The problem is there is no way of setting $0 inside a shell script as far as I know. So either init-d-script shouldn't be used in shebang or 40-systemd should handle a special case for it (this is up to the systemd maintainers as 40-systemd is in systemd package)