]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/userdb/userdbd.c
tree-wide: enable colorized logging for daemons when run in console
[thirdparty/systemd.git] / src / userdb / userdbd.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
d093b62c
LP
2
3#include <sys/stat.h>
4#include <sys/types.h>
5
6#include "daemon-util.h"
7#include "userdbd-manager.h"
8#include "log.h"
9#include "main-func.h"
10#include "signal-util.h"
11
12/* This service offers two Varlink services, both implementing io.systemd.UserDatabase:
13 *
4fcc9c49 14 * → io.systemd.NameServiceSwitch: this is a compatibility interface for glibc NSS: it responds to
d093b62c
LP
15 * name lookups by checking the classic NSS interfaces and responding that.
16 *
17 * → io.systemd.Multiplexer: this multiplexes lookup requests to all Varlink services that have a
18 * socket in /run/systemd/userdb/. It's supposed to simplify clients that don't want to implement
19 * the full iterative logic on their own.
20 */
21
22static int run(int argc, char *argv[]) {
d093b62c 23 _cleanup_(manager_freep) Manager *m = NULL;
272ac70a 24 _cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
d093b62c
LP
25 int r;
26
d2acb93d 27 log_setup();
d093b62c
LP
28
29 umask(0022);
30
31 if (argc != 1)
32 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes no arguments.");
33
34 if (setenv("SYSTEMD_BYPASS_USERDB", "io.systemd.NameServiceSwitch:io.systemd.Multiplexer", 1) < 0)
35 return log_error_errno(errno, "Failed to se $SYSTEMD_BYPASS_USERDB: %m");
36
37 assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, SIGTERM, SIGINT, SIGUSR2, -1) >= 0);
38
39 r = manager_new(&m);
40 if (r < 0)
41 return log_error_errno(r, "Could not create manager: %m");
42
43 r = manager_startup(m);
44 if (r < 0)
45 return log_error_errno(r, "Failed to start up daemon: %m");
46
47 notify_stop = notify_start(NOTIFY_READY, NOTIFY_STOPPING);
48
49 r = sd_event_loop(m->event);
50 if (r < 0)
51 return log_error_errno(r, "Event loop failed: %m");
52
53 return 0;
54}
55
56DEFINE_MAIN_FUNCTION(run);