tree-wide: enable colorized logging for daemons when run in console

It may be useful when debugging daemons.
This commit is contained in:
Yu Watanabe 2021-01-17 15:12:28 +09:00
parent 74189020eb
commit d2acb93dc5
72 changed files with 72 additions and 85 deletions

View file

@ -2446,7 +2446,7 @@ static int run(int argc, char *argv[]) {
setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C"); /* we want to format/parse floats in C style */
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -380,7 +380,7 @@ static int run(int argc, char *argv[]) {
unsigned max_brightness, brightness;
int r;
log_setup_service();
log_setup();
if (strv_contains(strv_skip(argv, 1), "--help"))
return help();

View file

@ -1456,19 +1456,7 @@ int log_dup_console(void) {
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();
(void) log_open();
}
void log_setup_cli(void) {
/* Sets up logging the way it is most appropriate for running a program as a CLI utility. */
void log_setup(void) {
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
(void) log_open();

View file

@ -300,5 +300,4 @@ int log_syntax_invalid_utf8_internal(
#define DEBUG_LOGGING _unlikely_(log_get_max_level() >= LOG_DEBUG)
void log_setup_service(void);
void log_setup_cli(void);
void log_setup(void);

View file

@ -190,7 +190,7 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
log_setup_service();
log_setup();
umask(0022);

View file

@ -2565,7 +2565,7 @@ static int busctl_main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -163,7 +163,7 @@ static void show_cg_info(const char *controller, const char *path) {
static int run(int argc, char *argv[]) {
int r, output_flags;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -22,7 +22,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
log_setup_service();
log_setup();
fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
if (fd < 0) {

View file

@ -915,7 +915,7 @@ static int run(int argc, char *argv[]) {
CGroupMask mask;
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -861,7 +861,7 @@ static int process_socket(int fd) {
assert(fd >= 0);
log_setup_service();
log_setup();
log_debug("Processing coredump received on stdin...");

View file

@ -1108,7 +1108,7 @@ static int run(int argc, char *argv[]) {
int r, units_active;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
/* The journal merging logic potentially needs a lot of fds. */
(void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);

View file

@ -1395,7 +1395,7 @@ static int run(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program requires at least two arguments.");
log_setup_service();
log_setup();
cryptsetup_enable_logging(cd);

View file

@ -643,7 +643,7 @@ static int parse_argv(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r, k, n_found = 0;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -127,7 +127,7 @@ static int run(int argc, char *argv[]) {
* to detect whether we are being run in a virtualized
* environment or not */
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -158,7 +158,7 @@ static int run(int argc, char *argv[]) {
char **i;
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -1271,7 +1271,7 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -256,7 +256,7 @@ static int run(int argc, char *argv[]) {
int r, exit_status;
pid_t pid;
log_setup_service();
log_setup();
if (argc > 2)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),

View file

@ -20,7 +20,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
log_setup_service();
log_setup();
umask(0022);

View file

@ -3346,7 +3346,7 @@ static int run(int argc, char *argv[]) {
int r;
log_setup_cli();
log_setup();
r = redirect_bus_mgr();
if (r < 0)

View file

@ -17,7 +17,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
int r;
log_setup_service();
log_setup();
r = service_parse_argv("systemd-homed.service",
"A service to create, remove, change or inspect home areas.",

View file

@ -1633,7 +1633,7 @@ static int run(int argc, char *argv[]) {
start = now(CLOCK_MONOTONIC);
log_setup_service();
log_setup();
umask(0022);

View file

@ -443,7 +443,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -1064,7 +1064,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_setup_service();
log_setup();
r = service_parse_argv("systemd-hostnamed.service",
"Manage the system hostname and related metadata.",

View file

@ -249,7 +249,7 @@ static int id128_main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -1361,7 +1361,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(manager_unrefp) Manager *m = NULL;
int r;
log_setup_service();
log_setup();
r = service_parse_argv("systemd-importd.service",
"VM and container image import and export service.",

View file

@ -317,7 +317,7 @@ static int run(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program does not take arguments.");
log_setup_service();
log_setup();
umask(0022);

View file

@ -995,7 +995,7 @@ static int run(int argc, char *argv[]) {
MHD_USE_THREAD_PER_CONNECTION;
int r, n;
log_setup_service();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -129,7 +129,7 @@ static int run(int argc, char *argv[]) {
_cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1;
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -2145,7 +2145,7 @@ int main(int argc, char *argv[]) {
int n_shown = 0, r, poll_fd = -1;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
/* Increase max number of open files if we can, we might needs this when browsing journal files, which might be
* split up into many files. */

View file

@ -506,7 +506,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -830,7 +830,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_setup_service();
log_setup();
r = service_parse_argv("systemd-localed.service",
"Manage system locale settings and key mappings.",

View file

@ -1464,7 +1464,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
/* The journal merging logic potentially needs a lot of fds. */
(void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);

View file

@ -1160,7 +1160,7 @@ static int run(int argc, char *argv[]) {
int r;
log_set_facility(LOG_AUTH);
log_setup_service();
log_setup();
r = service_parse_argv("systemd-logind.service",
"Manager for user logins and devices and privileged operations.",

View file

@ -2876,7 +2876,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
/* The journal merging logic potentially needs a lot of fds. */
(void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);

View file

@ -324,7 +324,7 @@ static int run(int argc, char *argv[]) {
int r;
log_set_facility(LOG_AUTH);
log_setup_service();
log_setup();
r = service_parse_argv("systemd-machined.service",
"Manage registrations of local VMs and containers.",

View file

@ -165,7 +165,7 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -2822,7 +2822,7 @@ static void warn_networkd_missing(void) {
static int run(int argc, char* argv[]) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -22,7 +22,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(notify_on_cleanup) const char *notify_message = NULL;
int r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -184,7 +184,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(notify_on_cleanup) const char *notify_message = NULL;
int r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -122,7 +122,7 @@ static int run(int argc, char *argv[]) {
unsigned long long s = 0;
int r;
log_setup_service();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -201,7 +201,7 @@ static int run(int argc, char *argv[]) {
dev_t devno;
int r;
log_setup_service();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -24,7 +24,7 @@ static int run(int argc, char *argv[]) {
struct stat st;
int r;
log_setup_service();
log_setup();
if (argc != 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),

View file

@ -1113,7 +1113,7 @@ static int run(int argc, char *argv[]) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -135,7 +135,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(manager_unrefp) Manager *m = NULL;
int r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -367,7 +367,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(pstore_entries_reset) PStoreList list = {};
int r;
log_setup_service();
log_setup();
if (argc == 3) {
arg_sourcedir = argv[1];

View file

@ -58,7 +58,7 @@ static void test_files(void) {
static int run(int argc, char *argv[]) {
int r;
log_setup_service();
log_setup();
if (argc > 1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),

View file

@ -110,7 +110,7 @@ static int run(int argc, char *argv[]) {
ssize_t k;
int r;
log_setup_service();
log_setup();
if (argc != 2)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),

View file

@ -77,7 +77,7 @@ static int run(int argc, char *argv[]) {
struct mntent* me;
int r;
log_setup_service();
log_setup();
if (argc > 1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),

View file

@ -39,7 +39,7 @@ static int run(int argc, char *argv[]) {
size_t length = 0;
int r;
log_setup_service();
log_setup();
if (argc != 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Wrong number of arguments.");

View file

@ -3296,7 +3296,7 @@ static int run(int argc, char **argv) {
int r;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
if (streq(program_invocation_short_name, "resolvconf"))
r = resolvconf_parse_argv(argc, argv);

View file

@ -26,7 +26,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
int r;
log_setup_service();
log_setup();
r = service_parse_argv("systemd-resolved.service",
"Provide name resolution with caching using DNS, mDNS, LLMNR.",

View file

@ -276,7 +276,7 @@ static int run(int argc, char *argv[]) {
if (argc > 1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program requires no arguments.");
log_setup_service();
log_setup();
umask(0022);

View file

@ -368,7 +368,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(free_sleep_configp) SleepConfig *sleep_config = NULL;
int r;
log_setup_service();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -100,7 +100,7 @@ int main(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_setup_service();
log_setup();
print_mode(argc > 1 ? argv[1] : "");

View file

@ -386,7 +386,7 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -1027,7 +1027,7 @@ static int sysext_main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -1928,7 +1928,7 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
log_setup_service();
log_setup();
if (arg_cat_config)
return cat_config();

View file

@ -84,7 +84,7 @@ static int parse_argv(int argc, char *argv[]) {
static int run(int argc, char **argv) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -1051,7 +1051,7 @@ static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -1109,7 +1109,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
log_setup_service();
log_setup();
r = service_parse_argv("systemd-timedated.service",
"Manage the system clock and timezone and NTP enablement.",

View file

@ -97,7 +97,7 @@ static int run(int argc, char *argv[]) {
int r;
log_set_facility(LOG_CRON);
log_setup_service();
log_setup();
umask(0022);

View file

@ -3363,7 +3363,7 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
log_setup_service();
log_setup();
/* Descending down file system trees might take a lot of fds */
(void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE);

View file

@ -684,7 +684,7 @@ static int ask_on_consoles(char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -41,7 +41,7 @@ int main(int argc, char *argv[]) {
struct stat st;
int r, q = 0;
log_setup_service();
log_setup();
if (stat("/usr", &st) < 0) {
log_error_errno(errno, "Failed to stat /usr: %m");

View file

@ -224,7 +224,7 @@ static int run(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program requires one argument.");
log_setup_service();
log_setup();
umask(0022);

View file

@ -21,7 +21,7 @@ static int run(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program requires one argument.");
log_setup_service();
log_setup();
umask(0022);

View file

@ -763,7 +763,7 @@ static int run(int argc, char *argv[]) {
int r;
log_setup_cli();
log_setup();
r = parse_argv(argc, argv);
if (r <= 0)

View file

@ -24,7 +24,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
int r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -662,7 +662,7 @@ static int run(int argc, char *argv[]) {
unsigned n_iterations = 0;
int m, listen_fd, r;
log_setup_service();
log_setup();
m = sd_listen_fds(false);
if (m < 0)

View file

@ -430,7 +430,7 @@ int main(int argc, char **argv) {
unsigned idx = 0;
int r;
log_setup_service();
log_setup();
umask(0022);

View file

@ -136,7 +136,7 @@ static int run(int argc, char *argv[]) {
if (argc < 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program requires at least two arguments.");
log_setup_service();
log_setup();
umask(0022);

View file

@ -119,7 +119,7 @@ static int run(int argc, char *argv[]) {
dev_t devt;
int r;
log_setup_service();
log_setup();
if (argc > 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),