* in containers so that our children inherit that. */
#define DEFAULT_RLIMIT_MEMLOCK (1024ULL*1024ULL*8ULL)
-#define PLYMOUTH_SOCKET { \
- .un.sun_family = AF_UNIX, \
- .un.sun_path = "\0/org/freedesktop/plymouthd", \
- }
-
/* Path where PID1 listens for varlink subscriptions from systemd-oomd to notify of changes in ManagedOOM settings. */
#define VARLINK_ADDR_PATH_MANAGED_OOM_SYSTEM "/run/systemd/io.systemd.ManagedOOM"
/* Path where systemd-oomd listens for varlink connections from user managers to report changes in ManagedOOM settings. */
#include "battery-util.h"
#include "build.h"
-#include "constants.h"
#include "errno-util.h"
-#include "glyph-util.h"
#include "fd-util.h"
+#include "glyph-util.h"
#include "io-util.h"
#include "log.h"
#include "main-func.h"
#include "parse-util.h"
+#include "plymouth-util.h"
#include "pretty-print.h"
#include "proc-cmdline.h"
#include "socket-util.h"
return 0;
}
-static bool ERRNO_IS_NO_PLYMOUTH(int r) {
- return IN_SET(abs(r), EAGAIN, ENOENT) || ERRNO_IS_DISCONNECT(r);
-}
-
static int plymouth_send_message(const char *mode, const char *message) {
- static const union sockaddr_union sa = PLYMOUTH_SOCKET;
_cleanup_free_ char *plymouth_message = NULL;
- _cleanup_close_ int fd = -EBADF;
int c, r;
assert(mode);
if (c < 0)
return log_oom();
- /* We set SOCK_NONBLOCK here so that we rather drop the
- * message than wait for plymouth */
- fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
- if (fd < 0)
- return log_warning_errno(errno, "socket() failed: %m");
-
- if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
- return log_full_errno(ERRNO_IS_NO_PLYMOUTH(errno) ? LOG_DEBUG : LOG_WARNING, errno,
- "Failed to connect to plymouth: %m");
-
- r = loop_write(fd, plymouth_message, c);
+ /* We set SOCK_NONBLOCK here so that we rather drop the message than wait for plymouth */
+ r = plymouth_send_raw(plymouth_message, c, SOCK_NONBLOCK);
if (r < 0)
return log_full_errno(ERRNO_IS_NO_PLYMOUTH(r) ? LOG_DEBUG : LOG_WARNING, r,
- "Failed to write to plymouth: %m");
+ "Failed to communicate with plymouth: %m");
return 0;
}
#include "parse-util.h"
#include "path-lookup.h"
#include "path-util.h"
+#include "plymouth-util.h"
#include "process-util.h"
#include "psi-util.h"
#include "ratelimit.h"
}
void manager_send_unit_plymouth(Manager *m, Unit *u) {
- static const union sockaddr_union sa = PLYMOUTH_SOCKET;
_cleanup_free_ char *message = NULL;
- _cleanup_close_ int fd = -EBADF;
- int n = 0;
+ int c, r;
/* Don't generate plymouth events if the service was already
* started and we're just deserializing */
if (!UNIT_VTABLE(u)->notify_plymouth)
return;
- /* We set SOCK_NONBLOCK here so that we rather drop the
- * message then wait for plymouth */
- fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
- if (fd < 0) {
- log_error_errno(errno, "socket() failed: %m");
- return;
- }
-
- if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) {
- if (!IN_SET(errno, EAGAIN, ENOENT) && !ERRNO_IS_DISCONNECT(errno))
- log_error_errno(errno, "connect() failed: %m");
- return;
- }
-
- if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0)
+ c = asprintf(&message, "U\x02%c%s%c", (int) (strlen(u->id) + 1), u->id, '\x00');
+ if (c < 0)
return (void) log_oom();
- errno = 0;
- if (write(fd, message, n + 1) != n + 1)
- if (!IN_SET(errno, EAGAIN, ENOENT) && !ERRNO_IS_DISCONNECT(errno))
- log_error_errno(errno, "Failed to write Plymouth message: %m");
+ /* We set SOCK_NONBLOCK here so that we rather drop the message then wait for plymouth */
+ r = plymouth_send_raw(message, c, SOCK_NONBLOCK);
+ if (r < 0)
+ log_full_errno(ERRNO_IS_NO_PLYMOUTH(r) ? LOG_DEBUG : LOG_WARNING, r,
+ "Failed to communicate with plymouth: %m");
}
usec_t manager_get_watchdog(Manager *m, WatchdogType t) {
#include "alloc-util.h"
#include "ask-password-api.h"
-#include "constants.h"
#include "creds-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "missing_syscall.h"
#include "mkdir-label.h"
#include "nulstr-util.h"
+#include "plymouth-util.h"
#include "process-util.h"
#include "random-util.h"
#include "signal-util.h"
const char *flag_file,
char ***ret) {
- static const union sockaddr_union sa = PLYMOUTH_SOCKET;
_cleanup_close_ int fd = -EBADF, notify = -EBADF;
_cleanup_free_ char *packet = NULL;
ssize_t k;
return -errno;
}
- fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+ fd = plymouth_connect(SOCK_NONBLOCK);
if (fd < 0)
- return -errno;
-
- if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
- return -errno;
+ return fd;
if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED)) {
packet = strdup("c");
'pcrextend-util.c',
'pe-binary.c',
'pkcs11-util.c',
+ 'plymouth-util.c',
'pretty-print.c',
'ptyfwd.c',
'qrcode-util.c',
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "fd-util.h"
+#include "io-util.h"
+#include "plymouth-util.h"
+#include "socket-util.h"
+
+int plymouth_connect(int flags) {
+ static const union sockaddr_union sa = {
+ .un.sun_family = AF_UNIX,
+ .un.sun_path = "\0/org/freedesktop/plymouthd",
+ };
+ _cleanup_close_ int fd = -EBADF;
+
+ fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|flags, 0);
+ if (fd < 0)
+ return -errno;
+
+ if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
+ return -errno;
+
+ return TAKE_FD(fd);
+}
+
+int plymouth_send_raw(const void *raw, size_t size, int flags) {
+ _cleanup_close_ int fd = -EBADF;
+
+ fd = plymouth_connect(flags);
+ if (fd < 0)
+ return fd;
+
+ return loop_write(fd, raw, size);
+}
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <sys/types.h>
+
+#include "errno-util.h"
+
+int plymouth_connect(int flags);
+int plymouth_send_raw(const void *raw, size_t size, int flags);
+
+static inline bool ERRNO_IS_NO_PLYMOUTH(int r) {
+ return IN_SET(abs(r), EAGAIN, ENOENT) || ERRNO_IS_DISCONNECT(r);
+}