seatd already provides a systemd.service to start and run seatd. As seatd
needs to run as root while it may be preferable to run users of the seat as
non-root user, it is not possible to add a dependency from other
systemd.services to the seatd.service. Therefore, the seatd.service always
needs to run on such systems even if no other process actually needs it.
Socket activation allows to start the seatd service only when some other
process tries to connect to the socket.
Michael
Michael Tretter (2):
seatd: Initialize server before removing socket
seatd: Add support for systemd.socket activation
contrib/systemd/seatd.socket | 9 +++++++
meson.build | 9 ++++++-
seatd/seatd.c | 51 +++++++++++++++++++++++++++---------
3 files changed, 56 insertions(+), 13 deletions(-)
create mode 100644 contrib/systemd/seatd.socket
--
2.30.2
Removing an existing socket is a preparation for creating a new socket.
Initializing the service between removing a left-over socket and
creating a new socket makes error handling difficult.
This is a preparation for adding systemd socket activation.
---
seatd/seatd.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/seatd/seatd.c b/seatd/seatd.c
index f88e6c96aa71..bc200f0587dd 100644
--- a/seatd/seatd.c+++ b/seatd/seatd.c
@@ -152,33 +152,33 @@ int main(int argc, char *argv[]) {
log_init();
libseat_set_log_level(level);
+ struct server server = {0};+ if (server_init(&server) == -1) {+ log_errorf("server_init failed: %s", strerror(errno));+ return 1;+ }++ int ret = 1; struct stat st;
if (lstat(SEATD_DEFAULTPATH, &st) == 0) {
if (!S_ISSOCK(st.st_mode)) {
log_errorf("Non-socket file found at socket path %s, refusing to start",
SEATD_DEFAULTPATH);
- return 1;+ goto error_server; } else if (!unlink_existing_socket) {
log_errorf("Socket file found at socket path %s, refusing to start",
SEATD_DEFAULTPATH);
- return 1;+ goto error_server; } else {
// We only do this if the socket path is not user specified
log_infof("Removing leftover socket at %s", SEATD_DEFAULTPATH);
if (unlink(SEATD_DEFAULTPATH) == -1) {
log_errorf("Could not remove leftover socket: %s", strerror(errno));
- return 1;+ goto error_server; }
}
}
- struct server server = {0};- if (server_init(&server) == -1) {- log_errorf("server_init failed: %s", strerror(errno));- return 1;- }-- int ret = 1; int socket_fd = open_socket(SEATD_DEFAULTPATH, uid, gid);
if (socket_fd == -1) {
log_error("Could not create server socket");
--
2.30.2
[PATCH 2/2] seatd: Add support for systemd.socket activation
Export this patch