[systemd-devel] [PATCH] systemd-notify: Always pass a valid pid to sd_pid_notify

Lennart Poettering lennart at poettering.net
Mon Sep 21 09:14:24 PDT 2015


On Sat, 19.09.15 23:46, Benjamin Robin (dev at benjarobin.fr) wrote:

> If the option --pid was used, take the pid from this option, unless take
> the parend pid. Using 0 as pid (ucred of systemd-notify) will result 99% of the
> time in a failure with this error: "Cannot find unit for notify message of PID"
> 
> Shouldn't we use always the ppid, since the MAINPID is something
> else ?

Unless the user specifies --pid= we should not declare anything the
main PID, hence we should not implicilty add MAINPID=.

> 
> Signed-off-by: Benjamin Robin <dev at benjarobin.fr>

Merged via github:

https://github.com/systemd/systemd/pull/1315

BTW: we do not user S-o-b, that's a kernel thing. Merged anyway with
this, but please do not add this in future patches.

> ---
>  src/notify/notify.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/notify/notify.c b/src/notify/notify.c
> index c920b29..ff8fa03 100644
> --- a/src/notify/notify.c
> +++ b/src/notify/notify.c
> @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) {
>                  goto finish;
>          }
>  
> -        r = sd_pid_notify(arg_pid, false, n);
> +        r = sd_pid_notify(arg_pid ? arg_pid : getppid(), false, n);
>          if (r < 0) {
>                  log_error_errno(r, "Failed to notify init system: %m");
>                  goto finish;
> -- 
> 2.5.3
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list