summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/libsystemd.sym1
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c73
-rw-r--r--src/libsystemd/sd-id128/id128-util.c4
-rw-r--r--src/libsystemd/sd-journal/sd-journal.c10
4 files changed, 46 insertions, 42 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 35352dc832..936a3577f5 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -825,4 +825,5 @@ global:
sd_event_trim_memory;
sd_pid_notify_barrier;
sd_event_source_leave_ratelimit;
+ sd_journal_step_one;
} LIBSYSTEMD_253;
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index 8538b7ab82..c4472d204e 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -450,13 +450,11 @@ static int vsock_bind_privileged_port(int fd) {
return r;
}
-_public_ int sd_pid_notify_with_fds(
+static int pid_notify_with_fds_internal(
pid_t pid,
- int unset_environment,
const char *state,
const int *fds,
unsigned n_fds) {
-
SocketAddress address;
struct iovec iovec;
struct msghdr msghdr = {
@@ -470,15 +468,11 @@ _public_ int sd_pid_notify_with_fds(
bool send_ucred;
int r;
- if (!state) {
- r = -EINVAL;
- goto finish;
- }
+ if (!state)
+ return -EINVAL;
- if (n_fds > 0 && !fds) {
- r = -EINVAL;
- goto finish;
- }
+ if (n_fds > 0 && !fds)
+ return -EINVAL;
e = getenv("NOTIFY_SOCKET");
if (!e)
@@ -489,46 +483,38 @@ _public_ int sd_pid_notify_with_fds(
if (r == -EPROTO)
r = socket_address_parse_vsock(&address, e);
if (r < 0)
- goto finish;
+ return r;
msghdr.msg_namelen = address.size;
/* If we didn't get an address (which is a normal pattern when specifying VSOCK tuples) error out,
* we always require a specific CID. */
- if (address.sockaddr.vm.svm_family == AF_VSOCK && address.sockaddr.vm.svm_cid == VMADDR_CID_ANY) {
- r = -EINVAL;
- goto finish;
- }
+ if (address.sockaddr.vm.svm_family == AF_VSOCK && address.sockaddr.vm.svm_cid == VMADDR_CID_ANY)
+ return -EINVAL;
/* At the time of writing QEMU does not yet support AF_VSOCK + SOCK_DGRAM and returns
* ENODEV. Fallback to SOCK_SEQPACKET in that case. */
fd = socket(address.sockaddr.sa.sa_family, SOCK_DGRAM|SOCK_CLOEXEC, 0);
if (fd < 0) {
- if (!(ERRNO_IS_NOT_SUPPORTED(errno) || errno == ENODEV) || address.sockaddr.sa.sa_family != AF_VSOCK) {
- r = -errno;
- goto finish;
- }
+ if (!(ERRNO_IS_NOT_SUPPORTED(errno) || errno == ENODEV) || address.sockaddr.sa.sa_family != AF_VSOCK)
+ return log_debug_errno(errno, "Failed to open datagram notify socket to '%s': %m", e);
fd = socket(address.sockaddr.sa.sa_family, SOCK_SEQPACKET|SOCK_CLOEXEC, 0);
- if (fd < 0) {
- r = -errno;
- goto finish;
- }
+ if (fd < 0)
+ return log_debug_errno(errno, "Failed to open sequential packet socket to '%s': %m", e);
r = vsock_bind_privileged_port(fd);
if (r < 0 && !ERRNO_IS_PRIVILEGE(r))
- goto finish;
+ return log_debug_errno(r, "Failed to bind socket to privileged port: %m");
- if (connect(fd, &address.sockaddr.sa, address.size) < 0) {
- r = -errno;
- goto finish;
- }
+ if (connect(fd, &address.sockaddr.sa, address.size) < 0)
+ return log_debug_errno(errno, "Failed to connect socket to '%s': %m", e);
msghdr.msg_name = NULL;
msghdr.msg_namelen = 0;
} else if (address.sockaddr.sa.sa_family == AF_VSOCK) {
r = vsock_bind_privileged_port(fd);
if (r < 0 && !ERRNO_IS_PRIVILEGE(r))
- goto finish;
+ return log_debug_errno(r, "Failed to bind socket to privileged port: %m");
}
(void) fd_inc_sndbuf(fd, SNDBUF_SIZE);
@@ -575,10 +561,8 @@ _public_ int sd_pid_notify_with_fds(
}
/* First try with fake ucred data, as requested */
- if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) >= 0) {
- r = 1;
- goto finish;
- }
+ if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) >= 0)
+ return 1;
/* If that failed, try with our own ucred instead */
if (send_ucred) {
@@ -586,15 +570,24 @@ _public_ int sd_pid_notify_with_fds(
if (msghdr.msg_controllen == 0)
msghdr.msg_control = NULL;
- if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) >= 0) {
- r = 1;
- goto finish;
- }
+ if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) >= 0)
+ return 1;
}
- r = -errno;
+ return log_debug_errno(errno, "Failed to send notify message to '%s': %m", e);
+}
+
+_public_ int sd_pid_notify_with_fds(
+ pid_t pid,
+ int unset_environment,
+ const char *state,
+ const int *fds,
+ unsigned n_fds) {
+
+ int r;
+
+ r = pid_notify_with_fds_internal(pid, state, fds, n_fds);
-finish:
if (unset_environment)
assert_se(unsetenv("NOTIFY_SOCKET") == 0);
diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c
index 76c9d1c051..edadd86eaa 100644
--- a/src/libsystemd/sd-id128/id128-util.c
+++ b/src/libsystemd/sd-id128/id128-util.c
@@ -119,7 +119,7 @@ int id128_read_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t *ret) {
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
assert(path);
- fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY, 0);
+ fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY, /* xopen_flags = */ 0, /* mode = */ 0);
if (fd < 0)
return fd;
@@ -165,7 +165,7 @@ int id128_write_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t id) {
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
assert(path);
- fd = xopenat(dir_fd, path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, 0444);
+ fd = xopenat(dir_fd, path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, /* xopen_flags = */ 0, 0444);
if (fd < 0)
return fd;
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 47532e2cbc..957817bfab 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -979,6 +979,16 @@ _public_ int sd_journal_previous(sd_journal *j) {
return real_journal_next(j, DIRECTION_UP);
}
+_public_ int sd_journal_step_one(sd_journal *j, int advanced) {
+ assert_return(j, -EINVAL);
+
+ if (j->current_location.type == LOCATION_HEAD)
+ return sd_journal_next(j);
+ if (j->current_location.type == LOCATION_TAIL)
+ return sd_journal_previous(j);
+ return real_journal_next(j, advanced ? DIRECTION_DOWN : DIRECTION_UP);
+}
+
static int real_journal_next_skip(sd_journal *j, direction_t direction, uint64_t skip) {
int c = 0, r;