1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

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),