summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-06-05 17:05:18 +0200
committerLennart Poettering <lennart@poettering.net>2014-06-05 17:05:18 +0200
commitbe8f4e9e8eb3b0c34a49c2e80a5c5b7dc6d175f0 (patch)
tree172fdccc7b7033063ecdb8bbd7e5d395e3a91095 /src/shared/util.c
parent03da8f9459b005d5515d2c34152d43bc63f64c79 (diff)
sd-daemon: introduce sd_pid_notify() and sd_pid_notifyf()
sd_pid_notify() operates like sd_notify(), however operates on a different PID (for example the parent PID of a process). Make use of this in systemd-notify, so that message are sent from the PID specified with --pid= rather than the usually shortlived PID of systemd-notify itself. This should increase the likelyhood that PID 1 can identify the cgroup that the notification message was sent from properly.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 4a3e35f356..7a4dacd213 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1377,17 +1377,21 @@ bool ignore_file(const char *filename) {
}
int fd_nonblock(int fd, bool nonblock) {
- int flags;
+ int flags, nflags;
assert(fd >= 0);
- if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
+ flags = fcntl(fd, F_GETFL, 0);
+ if (flags < 0)
return -errno;
if (nonblock)
- flags |= O_NONBLOCK;
+ nflags = flags | O_NONBLOCK;
else
- flags &= ~O_NONBLOCK;
+ nflags = flags & ~O_NONBLOCK;
+
+ if (nflags == flags)
+ return 0;
if (fcntl(fd, F_SETFL, flags) < 0)
return -errno;
@@ -1396,17 +1400,21 @@ int fd_nonblock(int fd, bool nonblock) {
}
int fd_cloexec(int fd, bool cloexec) {
- int flags;
+ int flags, nflags;
assert(fd >= 0);
- if ((flags = fcntl(fd, F_GETFD, 0)) < 0)
+ flags = fcntl(fd, F_GETFD, 0);
+ if (flags < 0)
return -errno;
if (cloexec)
- flags |= FD_CLOEXEC;
+ nflags = flags | FD_CLOEXEC;
else
- flags &= ~FD_CLOEXEC;
+ nflags = flags & ~FD_CLOEXEC;
+
+ if (nflags == flags)
+ return 0;
if (fcntl(fd, F_SETFD, flags) < 0)
return -errno;