chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus: always explicitly close bus from main programs
[elogind.git]
/
src
/
systemctl
/
systemctl.c
diff --git
a/src/systemctl/systemctl.c
b/src/systemctl/systemctl.c
index fc325095ac833f16a89e95e33faa903f1eb72451..540b4a64c1f5077f7c5364fb2bb37f5419ec4d97 100644
(file)
--- a/
src/systemctl/systemctl.c
+++ b/
src/systemctl/systemctl.c
@@
-617,7
+617,7
@@
static int get_unit_list_recursive(
return r;
STRV_FOREACH(i, machines) {
return r;
STRV_FOREACH(i, machines) {
- _cleanup_bus_unref_ sd_bus *container = NULL;
+ _cleanup_bus_
close_
unref_ sd_bus *container = NULL;
int k;
r = sd_bus_open_system_container(&container, *i);
int k;
r = sd_bus_open_system_container(&container, *i);
@@
-1142,7
+1142,7
@@
static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) {
assert(nw);
assert(next);
assert(nw);
assert(next);
- if (next->monotonic !=
(usec_t) -1
&& next->monotonic > 0) {
+ if (next->monotonic !=
USEC_INFINITY
&& next->monotonic > 0) {
usec_t converted;
if (next->monotonic > nw->monotonic)
usec_t converted;
if (next->monotonic > nw->monotonic)
@@
-1150,7
+1150,7
@@
static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) {
else
converted = nw->realtime - (nw->monotonic - next->monotonic);
else
converted = nw->realtime - (nw->monotonic - next->monotonic);
- if (next->realtime !=
(usec_t) -1
&& next->realtime > 0)
+ if (next->realtime !=
USEC_INFINITY
&& next->realtime > 0)
next_elapse = MIN(converted, next->realtime);
else
next_elapse = converted;
next_elapse = MIN(converted, next->realtime);
else
next_elapse = converted;
@@
-1688,7
+1688,7
@@
static int compare_machine_info(const void *a, const void *b) {
}
static int get_machine_properties(sd_bus *bus, struct machine_info *mi) {
}
static int get_machine_properties(sd_bus *bus, struct machine_info *mi) {
- _cleanup_bus_unref_ sd_bus *container = NULL;
+ _cleanup_bus_
close_
unref_ sd_bus *container = NULL;
int r;
assert(mi);
int r;
assert(mi);
@@
-4998,15
+4998,9
@@
static int enable_sysv_units(const char *verb, char **args) {
STRV_FOREACH(k, paths.unit_path) {
_cleanup_free_ char *path = NULL;
STRV_FOREACH(k, paths.unit_path) {
_cleanup_free_ char *path = NULL;
- if (!isempty(arg_root))
- asprintf(&path, "%s/%s/%s", arg_root, *k, name);
- else
- asprintf(&path, "%s/%s", *k, name);
-
- if (!path) {
- r = log_oom();
- goto finish;
- }
+ path = path_join(arg_root, *k, name);
+ if (!path)
+ return log_oom();
found_native = access(path, F_OK) >= 0;
if (found_native)
found_native = access(path, F_OK) >= 0;
if (found_native)
@@
-5016,14
+5010,9
@@
static int enable_sysv_units(const char *verb, char **args) {
if (found_native)
continue;
if (found_native)
continue;
- if (!isempty(arg_root))
- asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name);
- else
- asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
- if (!p) {
- r = log_oom();
- goto finish;
- }
+ p = path_join(arg_root, SYSTEM_SYSVINIT_PATH, name);
+ if (!p)
+ return log_oom();
p[strlen(p) - strlen(".service")] = 0;
found_sysv = access(p, F_OK) >= 0;
p[strlen(p) - strlen(".service")] = 0;
found_sysv = access(p, F_OK) >= 0;
@@
-5045,18
+5034,15
@@
static int enable_sysv_units(const char *verb, char **args) {
argv[c] = NULL;
l = strv_join((char**)argv, " ");
argv[c] = NULL;
l = strv_join((char**)argv, " ");
- if (!l) {
- r = log_oom();
- goto finish;
- }
+ if (!l)
+ return log_oom();
log_info("Executing %s", l);
pid = fork();
if (pid < 0) {
log_error("Failed to fork: %m");
log_info("Executing %s", l);
pid = fork();
if (pid < 0) {
log_error("Failed to fork: %m");
- r = -errno;
- goto finish;
+ return -errno;
} else if (pid == 0) {
/* Child */
} else if (pid == 0) {
/* Child */
@@
-5067,8
+5053,7
@@
static int enable_sysv_units(const char *verb, char **args) {
j = wait_for_terminate(pid, &status);
if (j < 0) {
log_error("Failed to wait for child: %s", strerror(-r));
j = wait_for_terminate(pid, &status);
if (j < 0) {
log_error("Failed to wait for child: %s", strerror(-r));
- r = j;
- goto finish;
+ return j;
}
if (status.si_code == CLD_EXITED) {
}
if (status.si_code == CLD_EXITED) {
@@
-5082,17
+5067,12
@@
static int enable_sysv_units(const char *verb, char **args) {
puts("disabled");
}
puts("disabled");
}
- } else if (status.si_status != 0) {
- r = -EINVAL;
- goto finish;
- }
- } else {
- r = -EPROTO;
- goto finish;
- }
+ } else if (status.si_status != 0)
+ return -EINVAL;
+ } else
+ return -EPROTO;
}
}
-finish:
/* Drop all SysV units */
for (f = 0, t = 0; args[f]; f++) {
/* Drop all SysV units */
for (f = 0, t = 0; args[f]; f++) {
@@
-5452,7
+5432,7
@@
static int is_system_running(sd_bus *bus, char **args) {
return streq(state, "running") ? EXIT_SUCCESS : EXIT_FAILURE;
}
return streq(state, "running") ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static
int
systemctl_help(void) {
+static
void
systemctl_help(void) {
pager_open_if_enabled();
pager_open_if_enabled();
@@
-5577,12
+5557,9
@@
static int systemctl_help(void) {
" hibernate Hibernate the system\n"
" hybrid-sleep Hibernate and suspend the system\n",
program_invocation_short_name);
" hibernate Hibernate the system\n"
" hybrid-sleep Hibernate and suspend the system\n",
program_invocation_short_name);
-
- return 0;
}
}
-static int halt_help(void) {
-
+static void halt_help(void) {
printf("%s [OPTIONS...]%s\n\n"
"%s the system.\n\n"
" --help Show this help\n"
printf("%s [OPTIONS...]%s\n\n"
"%s the system.\n\n"
" --help Show this help\n"
@@
-5598,12
+5575,9
@@
static int halt_help(void) {
arg_action == ACTION_REBOOT ? "Reboot" :
arg_action == ACTION_POWEROFF ? "Power off" :
"Halt");
arg_action == ACTION_REBOOT ? "Reboot" :
arg_action == ACTION_POWEROFF ? "Power off" :
"Halt");
-
- return 0;
}
}
-static int shutdown_help(void) {
-
+static void shutdown_help(void) {
printf("%s [OPTIONS...] [TIME] [WALL...]\n\n"
"Shut down the system.\n\n"
" --help Show this help\n"
printf("%s [OPTIONS...] [TIME] [WALL...]\n\n"
"Shut down the system.\n\n"
" --help Show this help\n"
@@
-5615,12
+5589,9
@@
static int shutdown_help(void) {
" --no-wall Don't send wall message before halt/power-off/reboot\n"
" -c Cancel a pending shutdown\n",
program_invocation_short_name);
" --no-wall Don't send wall message before halt/power-off/reboot\n"
" -c Cancel a pending shutdown\n",
program_invocation_short_name);
-
- return 0;
}
}
-static int telinit_help(void) {
-
+static void telinit_help(void) {
printf("%s [OPTIONS...] {COMMAND}\n\n"
"Send control commands to the init daemon.\n\n"
" --help Show this help\n"
printf("%s [OPTIONS...] {COMMAND}\n\n"
"Send control commands to the init daemon.\n\n"
" --help Show this help\n"
@@
-5633,32
+5604,26
@@
static int telinit_help(void) {
" q, Q Reload init daemon configuration\n"
" u, U Reexecute init daemon\n",
program_invocation_short_name);
" q, Q Reload init daemon configuration\n"
" u, U Reexecute init daemon\n",
program_invocation_short_name);
-
- return 0;
}
}
-static int runlevel_help(void) {
-
+static void runlevel_help(void) {
printf("%s [OPTIONS...]\n\n"
"Prints the previous and current runlevel of the init system.\n\n"
" --help Show this help\n",
program_invocation_short_name);
printf("%s [OPTIONS...]\n\n"
"Prints the previous and current runlevel of the init system.\n\n"
" --help Show this help\n",
program_invocation_short_name);
-
- return 0;
}
}
-static
int
help_types(void) {
+static
void
help_types(void) {
int i;
const char *t;
int i;
const char *t;
- puts("Available unit types:");
+ if (!arg_no_legend)
+ puts("Available unit types:");
for (i = 0; i < _UNIT_TYPE_MAX; i++) {
t = unit_type_to_string(i);
if (t)
puts(t);
}
for (i = 0; i < _UNIT_TYPE_MAX; i++) {
t = unit_type_to_string(i);
if (t)
puts(t);
}
-
- return 0;
}
static int systemctl_parse_argv(int argc, char *argv[]) {
}
static int systemctl_parse_argv(int argc, char *argv[]) {
@@
-5740,12
+5705,13
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0)
{
+ while ((c = getopt_long(argc, argv, "ht:p:alqfs:H:M:n:o:ir", options, NULL)) >= 0)
switch (c) {
case 'h':
switch (c) {
case 'h':
- return systemctl_help();
+ systemctl_help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
case ARG_VERSION:
puts(PACKAGE_STRING);
@@
-5753,7
+5719,7
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
return 0;
case 't': {
return 0;
case 't': {
- char *word, *state;
+ c
onst c
har *word, *state;
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
@@
-5802,7
+5768,7
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
if (!arg_properties)
return log_oom();
} else {
if (!arg_properties)
return log_oom();
} else {
- char *word, *state;
+ c
onst c
har *word, *state;
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
@@
-5972,7
+5938,7
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case ARG_STATE: {
break;
case ARG_STATE: {
- char *word, *state;
+ c
onst c
har *word, *state;
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
size_t size;
FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
@@
-6013,7
+5979,6
@@
static int systemctl_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_transport != BUS_TRANSPORT_LOCAL && arg_scope != UNIT_FILE_SYSTEM) {
log_error("Cannot access user instance remotely.");
if (arg_transport != BUS_TRANSPORT_LOCAL && arg_scope != UNIT_FILE_SYSTEM) {
log_error("Cannot access user instance remotely.");
@@
-6053,11
+6018,12
@@
static int halt_parse_argv(int argc, char *argv[]) {
if (runlevel == '0' || runlevel == '6')
arg_force = 2;
if (runlevel == '0' || runlevel == '6')
arg_force = 2;
- while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0)
{
+ while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
switch (c) {
case ARG_HELP:
- return halt_help();
+ halt_help();
+ return 0;
case ARG_HALT:
arg_action = ACTION_HALT;
case ARG_HALT:
arg_action = ACTION_HALT;
@@
-6100,7
+6066,6
@@
static int halt_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) {
r = update_reboot_param_file(argc == optind + 1 ? argv[optind] : NULL);
if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) {
r = update_reboot_param_file(argc == optind + 1 ? argv[optind] : NULL);
@@
-6185,11
+6150,12
@@
static int shutdown_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "HPrhkt:afFc", options, NULL)) >= 0)
{
+ while ((c = getopt_long(argc, argv, "HPrhkt:afFc", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
switch (c) {
case ARG_HELP:
- return shutdown_help();
+ shutdown_help();
+ return 0;
case 'H':
arg_action = ACTION_HALT;
case 'H':
arg_action = ACTION_HALT;
@@
-6238,7
+6204,6
@@
static int shutdown_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
default:
assert_not_reached("Unhandled option");
}
- }
if (argc > optind && arg_action != ACTION_CANCEL_SHUTDOWN) {
r = parse_time_spec(argv[optind], &arg_when);
if (argc > optind && arg_action != ACTION_CANCEL_SHUTDOWN) {
r = parse_time_spec(argv[optind], &arg_when);
@@
-6299,11
+6264,12
@@
static int telinit_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
{
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
switch (c) {
case ARG_HELP:
- return telinit_help();
+ telinit_help();
+ return 0;
case ARG_NO_WALL:
arg_no_wall = true;
case ARG_NO_WALL:
arg_no_wall = true;
@@
-6315,10
+6281,10
@@
static int telinit_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
default:
assert_not_reached("Unhandled option");
}
- }
if (optind >= argc) {
if (optind >= argc) {
- telinit_help();
+ log_error("%s: required argument missing.",
+ program_invocation_short_name);
return -EINVAL;
}
return -EINVAL;
}
@@
-6364,11
+6330,12
@@
static int runlevel_parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
{
+ while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0)
switch (c) {
case ARG_HELP:
switch (c) {
case ARG_HELP:
- return runlevel_help();
+ runlevel_help();
+ return 0;
case '?':
return -EINVAL;
case '?':
return -EINVAL;
@@
-6376,7
+6343,6
@@
static int runlevel_parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
default:
assert_not_reached("Unhandled option");
}
- }
if (optind < argc) {
log_error("Too many arguments.");
if (optind < argc) {
log_error("Too many arguments.");
@@
-6862,7
+6828,7
@@
static int runlevel_main(void) {
}
int main(int argc, char*argv[]) {
}
int main(int argc, char*argv[]) {
- _cleanup_bus_unref_ sd_bus *bus = NULL;
+ _cleanup_bus_
close_
unref_ sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");
int r;
setlocale(LC_ALL, "");