X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=10213afbc244a2c1b892b3d685a06828a5edd28c;hp=9b083131df193b54c6ed3883ecc2683084637211;hb=95d383ee47db488f182048cfd6846f2e6b859f2b;hpb=d5d8429a12c4b1ef0dcd226c0904f00f4fa4898a diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 9b083131d..10213afbc 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -22,21 +22,16 @@ #include #include -#include #include #include #include #include #include #include -#include -#include #include #include #include -#include #include -#include #include "sd-daemon.h" #include "sd-shutdown.h" @@ -55,7 +50,6 @@ #include "cgroup-util.h" #include "list.h" #include "path-lookup.h" -#include "conf-parser.h" #include "exit-status.h" #include "build.h" #include "unit-name.h" @@ -2857,6 +2851,9 @@ static int check_inhibitors(sd_bus *bus, enum action a) { if (!sv) return log_oom(); + if ((pid_t) pid < 0) + return log_error_errno(ERANGE, "Bad PID %"PRIu32": %m", pid); + if (!strv_contains(sv, a == ACTION_HALT || a == ACTION_POWEROFF || @@ -2868,7 +2865,7 @@ static int check_inhibitors(sd_bus *bus, enum action a) { user = uid_to_name(uid); log_warning("Operation inhibited by \"%s\" (PID "PID_FMT" \"%s\", user %s), reason is \"%s\".", - who, pid, strna(comm), strna(user), why); + who, (pid_t) pid, strna(comm), strna(user), why); c++; } @@ -4517,6 +4514,23 @@ static int init_home_and_lookup_paths(char **user_home, char **user_runtime, Loo return 0; } +static int cat_file(const char *filename, bool newline) { + _cleanup_close_ int fd; + + fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOCTTY); + if (fd < 0) + return -errno; + + printf("%s%s# %s%s\n", + newline ? "\n" : "", + ansi_highlight_blue(), + filename, + ansi_highlight_off()); + fflush(stdout); + + return copy_bytes(fd, STDOUT_FILENO, (off_t) -1, false); +} + static int cat(sd_bus *bus, char **args) { _cleanup_free_ char *user_home = NULL; _cleanup_free_ char *user_runtime = NULL; @@ -4562,32 +4576,15 @@ static int cat(sd_bus *bus, char **args) { puts(""); if (fragment_path) { - printf("%s# %s%s\n", - ansi_highlight_blue(), - fragment_path, - ansi_highlight_off()); - fflush(stdout); - - r = copy_file_fd(fragment_path, STDOUT_FILENO, false); - if (r < 0) { - log_warning_errno(r, "Failed to cat %s: %m", fragment_path); - continue; - } + r = cat_file(fragment_path, false); + if (r < 0) + return log_warning_errno(r, "Failed to cat %s: %m", fragment_path); } STRV_FOREACH(path, dropin_paths) { - printf("%s%s# %s%s\n", - isempty(fragment_path) && path == dropin_paths ? "" : "\n", - ansi_highlight_blue(), - *path, - ansi_highlight_off()); - fflush(stdout); - - r = copy_file_fd(*path, STDOUT_FILENO, false); - if (r < 0) { - log_warning_errno(r, "Failed to cat %s: %m", *path); - continue; - } + r = cat_file(*path, path == dropin_paths); + if (r < 0) + return log_warning_errno(r, "Failed to cat %s: %m", *path); } } @@ -7102,6 +7099,11 @@ found: } } + /* Increase max number of open files to 16K if we can, we + * might needs this when browsing journal files, which might + * be split up into many files. */ + setrlimit_closest(RLIMIT_NOFILE, &RLIMIT_MAKE_CONST(16384)); + return verb->dispatch(bus, argv + optind); } @@ -7351,11 +7353,6 @@ int main(int argc, char*argv[]) { goto finish; } - /* Increase max number of open files to 16K if we can, we - * might needs this when browsing journal files, which might - * be split up into many files. */ - setrlimit_closest(RLIMIT_NOFILE, &RLIMIT_MAKE_CONST(16384)); - if (!avoid_bus()) r = bus_open_transport_systemd(arg_transport, arg_host, arg_scope != UNIT_FILE_SYSTEM, &bus);