diff options
44 files changed, 54 insertions, 126 deletions
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 7ca8f06234..0bcdff53c2 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -308,9 +308,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/basic/log.c b/src/basic/log.c index f8ef751a93..f24431eef2 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -1337,3 +1337,13 @@ int log_dup_console(void) { console_fd = copy; return 0; } + +void log_setup_service(void) { + /* Sets up logging the way it is most appropriate for running a program as a service. Note that using this + * doesn't make the binary unsuitable for invocation on the command line, as log output will still go to the + * terminal if invoked interactively. */ + + log_set_target(LOG_TARGET_AUTO); + log_parse_environment(); + log_open(); +} diff --git a/src/basic/log.h b/src/basic/log.h index e1f5fd30cd..683f97b942 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -318,3 +318,5 @@ int log_syntax_invalid_utf8_internal( }) #define DEBUG_LOGGING _unlikely_(log_get_max_level() >= LOG_DEBUG) + +void log_setup_service(void); diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 9cead4a87c..09f1bb3968 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -185,9 +185,7 @@ int main(int argc, char *argv[]) { if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/cgroups-agent/cgroups-agent.c b/src/cgroups-agent/cgroups-agent.c index 27a28d1414..9721a32ed6 100644 --- a/src/cgroups-agent/cgroups-agent.c +++ b/src/cgroups-agent/cgroups-agent.c @@ -23,9 +23,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); if (fd < 0) { diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 46536b7c84..243a880542 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -883,9 +883,7 @@ static int process_socket(int fd) { assert(fd >= 0); - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); log_debug("Processing coredump received on stdin..."); diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 1ec40198b4..a18b4e40f2 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -609,9 +609,7 @@ int main(int argc, char *argv[]) { goto finish; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index d8b5893f76..314c8a3790 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -949,9 +949,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 821ad15c5f..b1ce210fcc 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -270,9 +270,7 @@ static int run(int argc, char *argv[]) { int r, exit_status; pid_t pid; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc > 2) { log_error("This program expects one or no arguments."); diff --git a/src/hibernate-resume/hibernate-resume.c b/src/hibernate-resume/hibernate-resume.c index abbf357291..17e7cd1a00 100644 --- a/src/hibernate-resume/hibernate-resume.c +++ b/src/hibernate-resume/hibernate-resume.c @@ -20,9 +20,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 4cbf2bde8b..219602c55a 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -707,9 +707,7 @@ int main(int argc, char *argv[]) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); mac_selinux_init(); diff --git a/src/import/importd.c b/src/import/importd.c index f17cdf10d4..5d2a051533 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -1118,9 +1118,7 @@ static int run(int argc, char *argv[]) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c index c93c02bf48..259908a885 100644 --- a/src/initctl/initctl.c +++ b/src/initctl/initctl.c @@ -352,9 +352,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index a4e25f2284..71553083d9 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -990,9 +990,7 @@ int main(int argc, char *argv[]) { struct MHD_Daemon *d = NULL; int r, n; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); r = parse_argv(argc, argv); if (r < 0) diff --git a/src/locale/localed.c b/src/locale/localed.c index 21d1ded65c..bb5b132ce7 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -720,9 +720,7 @@ int main(int argc, char *argv[]) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); mac_selinux_init(); diff --git a/src/login/logind.c b/src/login/logind.c index 5f2243a15d..f419186506 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1171,10 +1171,8 @@ static int run(int argc, char *argv[]) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; - log_set_target(LOG_TARGET_AUTO); log_set_facility(LOG_AUTH); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/machine/machined.c b/src/machine/machined.c index a2e7a30240..22eb030dee 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -350,10 +350,8 @@ static int run(int argc, char *argv[]) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; - log_set_target(LOG_TARGET_AUTO); log_set_facility(LOG_AUTH); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 68d91be296..0f7f4c384e 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -166,9 +166,7 @@ int main(int argc, char *argv[]) { if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/network/networkd.c b/src/network/networkd.c index d398be987f..4fa5533c60 100644 --- a/src/network/networkd.c +++ b/src/network/networkd.c @@ -17,9 +17,7 @@ int main(int argc, char *argv[]) { gid_t gid; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/network/wait-online/wait-online.c b/src/network/wait-online/wait-online.c index 2ba6329a7a..2d74593326 100644 --- a/src/network/wait-online/wait-online.c +++ b/src/network/wait-online/wait-online.c @@ -109,9 +109,7 @@ int main(int argc, char *argv[]) { _cleanup_(manager_freep) Manager *m = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/partition/growfs.c b/src/partition/growfs.c index 2712849414..673b651da6 100644 --- a/src/partition/growfs.c +++ b/src/partition/growfs.c @@ -231,9 +231,7 @@ int main(int argc, char *argv[]) { struct statfs sfs; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); r = parse_argv(argc, argv); if (r < 0) diff --git a/src/partition/makefs.c b/src/partition/makefs.c index b2702d20f7..22ff83dc77 100644 --- a/src/partition/makefs.c +++ b/src/partition/makefs.c @@ -49,9 +49,7 @@ static int run(int argc, char *argv[]) { struct stat st; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc != 3) { log_error("This program expects two arguments."); diff --git a/src/portable/portabled.c b/src/portable/portabled.c index 313211a792..cfaf2a59e3 100644 --- a/src/portable/portabled.c +++ b/src/portable/portabled.c @@ -127,9 +127,7 @@ static int run(int argc, char *argv[]) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index 7b11f29507..0fc0052f72 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -56,9 +56,7 @@ static void test_files(void) { static int run(int argc, char *argv[]) { int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc > 1) { log_error("This program takes no arguments."); diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index 6162f8d6bf..1d2b017cf7 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -30,9 +30,7 @@ static int run(int argc, char *argv[]) { FILE *f; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc != 2) { log_error("This program requires one argument."); diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index ece7f2955d..5eb1404670 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -29,9 +29,7 @@ static int run(int argc, char *argv[]) { struct mntent* me; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc > 1) { log_error("This program takes no arguments."); diff --git a/src/reply-password/reply-password.c b/src/reply-password/reply-password.c index bec754f7be..ee7a0ea130 100644 --- a/src/reply-password/reply-password.c +++ b/src/reply-password/reply-password.c @@ -39,9 +39,7 @@ int main(int argc, char *argv[]) { size_t length = 0; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc != 3) { log_error("Wrong number of arguments."); diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c index fbae0b28be..755477096d 100644 --- a/src/resolve/resolved.c +++ b/src/resolve/resolved.c @@ -19,9 +19,7 @@ int main(int argc, char *argv[]) { gid_t gid; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc != 1) { log_error("This program takes no arguments."); diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index 47181bfc16..ec8d91af79 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -363,9 +363,7 @@ int main(int argc, char *argv[]) { LIST_HEAD_INIT(write_queue); - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/shared/generator.c b/src/shared/generator.c index 53db27a93d..eba0ae8ae0 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -501,7 +501,5 @@ int generator_hook_up_growfs( void log_setup_generator(void) { log_set_prohibit_ipc(true); - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); } diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index f1f4da8886..f86d4c628f 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -358,9 +358,7 @@ static int run(int argc, char *argv[]) { usec_t delay = 0; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); r = parse_argv(argc, argv); if (r <= 0) diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c index a1ea2333de..82481972f0 100644 --- a/src/sulogin-shell/sulogin-shell.c +++ b/src/sulogin-shell/sulogin-shell.c @@ -98,9 +98,7 @@ int main(int argc, char *argv[]) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); print_mode(argc > 1 ? argv[1] : ""); diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 9419f7bd73..a9d30dea5f 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -269,9 +269,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index e23360d437..dfaff66389 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -1933,9 +1933,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (arg_cat_config) { r = cat_config(); diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 71f2f6f69b..d23feb94f1 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -964,9 +964,7 @@ int main(int argc, char *argv[]) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 9a43c6193b..4055295555 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -90,10 +90,8 @@ int main(int argc, char *argv[]) { gid_t gid; int r; - log_set_target(LOG_TARGET_AUTO); log_set_facility(LOG_CRON); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index a81cecd2f9..617bcc186a 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -3120,9 +3120,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (arg_user) { r = user_config_paths(&config_dirs); diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 609839c5a1..0c966af499 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -840,9 +840,7 @@ static int ask_on_consoles(int argc, char *argv[]) { static int run(int argc, char *argv[]) { int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/update-done/update-done.c b/src/update-done/update-done.c index 22faf19fa3..953e0fad21 100644 --- a/src/update-done/update-done.c +++ b/src/update-done/update-done.c @@ -37,9 +37,7 @@ int main(int argc, char *argv[]) { struct stat st; int r, q = 0; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (stat("/usr", &st) < 0) { log_error_errno(errno, "Failed to stat /usr: %m"); diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 70ed723a8e..7647aa5c74 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -222,9 +222,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/user-sessions/user-sessions.c b/src/user-sessions/user-sessions.c index 89c4b0005d..fa0829e384 100644 --- a/src/user-sessions/user-sessions.c +++ b/src/user-sessions/user-sessions.c @@ -19,9 +19,7 @@ int main(int argc, char*argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 41059bae04..7182be4624 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -403,9 +403,7 @@ int main(int argc, char **argv) { unsigned idx = 0; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/veritysetup/veritysetup.c b/src/veritysetup/veritysetup.c index 61dcfd7cc2..a10baf2bfd 100644 --- a/src/veritysetup/veritysetup.c +++ b/src/veritysetup/veritysetup.c @@ -50,9 +50,7 @@ int main(int argc, char *argv[]) { goto finish; } - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); umask(0022); diff --git a/src/volatile-root/volatile-root.c b/src/volatile-root/volatile-root.c index b08d42834f..70f5d957b2 100644 --- a/src/volatile-root/volatile-root.c +++ b/src/volatile-root/volatile-root.c @@ -82,9 +82,7 @@ static int run(int argc, char *argv[]) { const char *path; int r; - log_set_target(LOG_TARGET_AUTO); - log_parse_environment(); - log_open(); + log_setup_service(); if (argc > 3) { log_error("Too many arguments. Expected directory and mode."); |