[systemd-devel] [PATCH] Fix: Cannot call sd_pid_notify_with_fds with valid pid

Lennart Poettering lennart at poettering.net
Mon Sep 21 09:17:36 PDT 2015


On Sat, 19.09.15 18:54, Benjamin Robin (dev at benjarobin.fr) wrote:

> The tool called this way: "systemd-notify --pid=$$" is not working
> 
> When calling sd_pid_notify* functions with a valid pid (pid != 0),
> the sendmsg failed.
> The msg_controllen is invalid, because CMSG_SPACE(0) is not equal to
> 0.

This already has been fixed in git a few days ago:

a5bd3c32abb00ad945282568fd1a97c180b68047

>          if (n_fds > 0 || have_pid) {
> -                msghdr.msg_controllen = CMSG_SPACE(sizeof(int) * n_fds) +
> -                                        CMSG_SPACE(sizeof(struct ucred) * have_pid);
> +                if (n_fds > 0) {
> +                        msghdr.msg_controllen += CMSG_SPACE(sizeof(int) * n_fds);
> +                }
> +                if (have_pid) {
> +                        msghdr.msg_controllen += CMSG_SPACE(sizeof(struct ucred));
> +                }

Just for the sake of review: one-line if blocks without the brackets please, see CODING_STYLE.

Thanks,

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list