X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmanager.c;h=163f69c22f0ef2dec5f18fafeb19009e98085c21;hb=ad293f5a94d8124ece7d1cb860952a87b1c8d98f;hp=3291275d0a41d3c630d403569fdd4c60de694de8;hpb=7e2bb92dcae6ee785ff7462aadc8c369fd93715b;p=elogind.git diff --git a/src/manager.c b/src/manager.c index 3291275d0..163f69c22 100644 --- a/src/manager.c +++ b/src/manager.c @@ -76,7 +76,8 @@ static int manager_setup_notify(Manager *m) { struct sockaddr_un un; } sa; struct epoll_event ev; - int one = 1; + int one = 1, r; + mode_t u; assert(m); @@ -99,7 +100,11 @@ static int manager_setup_notify(Manager *m) { if (sa.un.sun_path[0] == '@') sa.un.sun_path[0] = 0; - if (bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) { + u = umask(0111); + r = bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)); + umask(u); + + if (r < 0) { log_error("bind() failed: %m"); return -errno; } @@ -186,6 +191,11 @@ static int manager_setup_signals(Manager *m) { SIGRTMIN+16, /* systemd: Immediate kexec */ SIGRTMIN+20, /* systemd: enable status messages */ SIGRTMIN+21, /* systemd: disable status messages */ + SIGRTMIN+22, /* systemd: set log level to LOG_DEBUG */ + SIGRTMIN+23, /* systemd: set log level to LOG_INFO */ + SIGRTMIN+27, /* systemd: set log target to console */ + SIGRTMIN+28, /* systemd: set log target to kmsg */ + SIGRTMIN+29, /* systemd: set log target to syslog-or-kmsg */ -1); assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0); @@ -258,7 +268,7 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) { if ((m->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0) goto fail; - if ((r = lookup_paths_init(&m->lookup_paths, m->running_as)) < 0) + if ((r = lookup_paths_init(&m->lookup_paths, m->running_as, true)) < 0) goto fail; if ((r = manager_setup_signals(m)) < 0) @@ -555,7 +565,8 @@ static void manager_build_unit_path_cache(Manager *m) { if (ignore_file(de->d_name)) continue; - if (asprintf(&p, "%s/%s", streq(*i, "/") ? "" : *i, de->d_name) < 0) { + p = join(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL); + if (!p) { r = -ENOMEM; goto fail; } @@ -2200,6 +2211,7 @@ static int manager_process_signal_fd(Manager *m) { break; default: { + /* Starting SIGRTMIN+0 */ static const char * const target_table[] = { [0] = SPECIAL_DEFAULT_TARGET, @@ -2244,6 +2256,31 @@ static int manager_process_signal_fd(Manager *m) { m->show_status = false; break; + case 22: + log_set_max_level(LOG_DEBUG); + log_notice("Setting log level to debug."); + break; + + case 23: + log_set_max_level(LOG_INFO); + log_notice("Setting log level to info."); + break; + + case 27: + log_set_target(LOG_TARGET_CONSOLE); + log_notice("Setting log target to console."); + break; + + case 28: + log_set_target(LOG_TARGET_KMSG); + log_notice("Setting log target to kmsg."); + break; + + case 29: + log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); + log_notice("Setting log target to syslog-or-kmsg."); + break; + default: log_warning("Got unhandled signal <%s>.", strna(signal_to_string(sfsi.ssi_signo))); } @@ -2822,7 +2859,7 @@ int manager_reload(Manager *m) { /* Find new unit paths */ lookup_paths_free(&m->lookup_paths); - if ((q = lookup_paths_init(&m->lookup_paths, m->running_as)) < 0) + if ((q = lookup_paths_init(&m->lookup_paths, m->running_as, true)) < 0) r = q; manager_run_generators(m); @@ -2953,6 +2990,7 @@ void manager_run_generators(Manager *m) { DIR *d = NULL; const char *generator_path; const char *argv[3]; + mode_t u; assert(m); @@ -2995,7 +3033,9 @@ void manager_run_generators(Manager *m) { argv[1] = m->generator_unit_path; argv[2] = NULL; + u = umask(0022); execute_directory(generator_path, d, (char**) argv); + umask(u); if (rmdir(m->generator_unit_path) >= 0) { /* Uh? we were able to remove this dir? I guess that @@ -3033,7 +3073,7 @@ void manager_undo_generators(Manager *m) { return; strv_remove(m->lookup_paths.unit_path, m->generator_unit_path); - rm_rf(m->generator_unit_path, false, true); + rm_rf(m->generator_unit_path, false, true, false); free(m->generator_unit_path); m->generator_unit_path = NULL;