summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-daemon/sd-daemon.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-04-27 13:26:49 +0200
committerMike Yuan <me@yhndnzj.com>2024-04-27 13:26:49 +0200
commit3e9fcc21638ac6c0c280f89b13742c3be9141955 (patch)
treeeeada887da45b1e591dee10cfc2921e3e5956bad /src/libsystemd/sd-daemon/sd-daemon.c
parentnetworkd: Correct documentation for LinkLocalAddressing (diff)
downloadsystemd-3e9fcc21638ac6c0c280f89b13742c3be9141955.tar.xz
systemd-3e9fcc21638ac6c0c280f89b13742c3be9141955.zip
sd-daemon: minor modernization, use assert_return
Diffstat (limited to '')
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index 58626463a8..16a8ac6cce 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -456,6 +456,7 @@ static int pid_notify_with_fds_internal(
const char *state,
const int *fds,
unsigned n_fds) {
+
SocketAddress address;
struct iovec iovec;
struct msghdr msghdr = {
@@ -464,19 +465,12 @@ static int pid_notify_with_fds_internal(
.msg_name = &address.sockaddr,
};
_cleanup_close_ int fd = -EBADF;
- struct cmsghdr *cmsg = NULL;
- const char *e;
- bool send_ucred;
- ssize_t n;
int type, r;
- if (!state)
- return -EINVAL;
+ assert_return(state, -EINVAL);
+ assert_return(fds || n_fds == 0, -EINVAL);
- if (n_fds > 0 && !fds)
- return -EINVAL;
-
- e = getenv("NOTIFY_SOCKET");
+ const char *e = getenv("NOTIFY_SOCKET");
if (!e)
return 0;
@@ -530,12 +524,14 @@ static int pid_notify_with_fds_internal(
iovec = IOVEC_MAKE_STRING(state);
- send_ucred =
+ bool send_ucred =
(pid != 0 && pid != getpid_cached()) ||
getuid() != geteuid() ||
getgid() != getegid();
if (n_fds > 0 || send_ucred) {
+ struct cmsghdr *cmsg;
+
/* CMSG_SPACE(0) may return value different than zero, which results in miscalculated controllen. */
msghdr.msg_controllen =
(n_fds > 0 ? CMSG_SPACE(sizeof(int) * n_fds) : 0) +
@@ -569,6 +565,8 @@ static int pid_notify_with_fds_internal(
}
}
+ ssize_t n;
+
do {
/* First try with fake ucred data, as requested */
n = sendmsg(fd, &msghdr, MSG_NOSIGNAL);