Message ID | 20190226095126.4296-1-Wojciech.Michna@assaabloy.com |
---|---|
State | Changes Requested |
Headers | show |
Series | Notify in behalf of PID parent or PID group. | expand |
Hi Marek, Wojciech, On 26/02/19 10:51, Wojciech Michna wrote: > > If there is Parent Pid or Group Pid those should be sent to the service manager. > This is a fix for the case when we are starting swupdate from shell script started from systemd. > In case we are starting from script not from systemd itself we need to annotate start to systemd as parent pid, > not our child pid. > > Signed-off-by: Szczypta Marek <Marek.Szczypta@assaabloy.com> > --- > core/swupdate.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/core/swupdate.c b/core/swupdate.c > index 4f3d9d6..a35ba78 100644 > --- a/core/swupdate.c > +++ b/core/swupdate.c > @@ -972,7 +972,15 @@ int main(int argc, char **argv) > > #ifdef CONFIG_SYSTEMD > if (sd_booted()) { > - sd_notify(0, "READY=1"); > + > + pid_t pidP = getpid(); > + pid_t pidPr = getppid(); > + pid_t pidGr = getpgrp(); > + > + /* > + * Notify in behalf of PID parent or PID group > + */ > + sd_pid_notify(((int)pidPr!=0 ? ((int)pidGr!=0 ? pidGr :pidPr ) : pidP ),0, "READY=1"); > } > #endif > I understand this fixes your personal use case, but this likes to me a hack and far away to be a generic solution. You want that SWUpdate sends back a notify in this case: -> start_swupdate.sh | |--> swupdate But then, what about -> start_swupdate_step1.sh | start_swupdate_step2.sh |--> swupdate or more deeper nesting ? The thing is : why SWUpdate should take care and try to imagine how it was started ? It is just a process / daemon and the calling process should take care of it. Which is the reason of the script ? Is it not possible to solve it rewriting the service unit of systemd, for example using ExecStartPre= if you need something before starting SWUpdate ? Best regards, Stefano Babic
diff --git a/core/swupdate.c b/core/swupdate.c index 4f3d9d6..a35ba78 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -972,7 +972,15 @@ int main(int argc, char **argv) #ifdef CONFIG_SYSTEMD if (sd_booted()) { - sd_notify(0, "READY=1"); + + pid_t pidP = getpid(); + pid_t pidPr = getppid(); + pid_t pidGr = getpgrp(); + + /* + * Notify in behalf of PID parent or PID group + */ + sd_pid_notify(((int)pidPr!=0 ? ((int)pidGr!=0 ? pidGr :pidPr ) : pidP ),0, "READY=1"); } #endif
If there is Parent Pid or Group Pid those should be sent to the service manager. This is a fix for the case when we are starting swupdate from shell script started from systemd. In case we are starting from script not from systemd itself we need to annotate start to systemd as parent pid, not our child pid. Signed-off-by: Szczypta Marek <Marek.Szczypta@assaabloy.com> --- core/swupdate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)