chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
enable localization for common *ctl commands
[elogind.git]
/
src
/
systemctl
/
systemctl.c
diff --git
a/src/systemctl/systemctl.c
b/src/systemctl/systemctl.c
index b4b58c05b0a77192b569ee91d8fb16833eb0b167..b82c79435d29acf9cd2f8c5ac937c5de73ffe01f 100644
(file)
--- a/
src/systemctl/systemctl.c
+++ b/
src/systemctl/systemctl.c
@@
-22,6
+22,7
@@
#include <sys/reboot.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/reboot.h>
#include <stdio.h>
#include <getopt.h>
+#include <locale.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
@@
-99,6
+100,7
@@
static enum action {
ACTION_EXIT,
ACTION_SUSPEND,
ACTION_HIBERNATE,
ACTION_EXIT,
ACTION_SUSPEND,
ACTION_HIBERNATE,
+ ACTION_HYBRID_SLEEP,
ACTION_RUNLEVEL2,
ACTION_RUNLEVEL3,
ACTION_RUNLEVEL4,
ACTION_RUNLEVEL2,
ACTION_RUNLEVEL3,
ACTION_RUNLEVEL4,
@@
-320,6
+322,7
@@
static bool output_show_unit(const struct unit_info *u) {
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
unsigned id_len, max_id_len, active_len, sub_len, job_len, desc_len, n_shown = 0;
const struct unit_info *u;
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
unsigned id_len, max_id_len, active_len, sub_len, job_len, desc_len, n_shown = 0;
const struct unit_info *u;
+ int job_count = 0;
max_id_len = sizeof("UNIT")-1;
active_len = sizeof("ACTIVE")-1;
max_id_len = sizeof("UNIT")-1;
active_len = sizeof("ACTIVE")-1;
@@
-334,14
+337,18
@@
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
max_id_len = MAX(max_id_len, strlen(u->id));
active_len = MAX(active_len, strlen(u->active_state));
sub_len = MAX(sub_len, strlen(u->sub_state));
max_id_len = MAX(max_id_len, strlen(u->id));
active_len = MAX(active_len, strlen(u->active_state));
sub_len = MAX(sub_len, strlen(u->sub_state));
- if (u->job_id != 0)
+ if (u->job_id != 0)
{
job_len = MAX(job_len, strlen(u->job_type));
job_len = MAX(job_len, strlen(u->job_type));
+ job_count++;
+ }
}
if (!arg_full) {
unsigned basic_len;
id_len = MIN(max_id_len, 25);
}
if (!arg_full) {
unsigned basic_len;
id_len = MIN(max_id_len, 25);
- basic_len = 5 + id_len + 6 + active_len + sub_len + job_len;
+ basic_len = 5 + id_len + 5 + active_len + sub_len;
+ if (job_count)
+ basic_len += job_len + 1;
if (basic_len < (unsigned) columns()) {
unsigned extra_len, incr;
extra_len = columns() - basic_len;
if (basic_len < (unsigned) columns()) {
unsigned extra_len, incr;
extra_len = columns() - basic_len;
@@
-370,8
+377,10
@@
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
continue;
if (!n_shown && !arg_no_legend) {
continue;
if (!n_shown && !arg_no_legend) {
- printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD",
- active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
+ printf("%-*s %-6s %-*s %-*s ", id_len, "UNIT", "LOAD",
+ active_len, "ACTIVE", sub_len, "SUB");
+ if (job_count)
+ printf("%-*s ", job_len, "JOB");
if (!arg_full && arg_no_pager)
printf("%.*s\n", desc_len, "DESCRIPTION");
else
if (!arg_full && arg_no_pager)
printf("%.*s\n", desc_len, "DESCRIPTION");
else
@@
-394,12
+403,12
@@
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
e = arg_full ? NULL : ellipsize(u->id, id_len, 33);
e = arg_full ? NULL : ellipsize(u->id, id_len, 33);
- printf("%-*s %s%-6s%s %s%-*s %-*s%s %-*s
",
+ printf("%-*s %s%-6s%s %s%-*s %-*s%s %-*s",
id_len, e ? e : u->id,
on_loaded, u->load_state, off_loaded,
on_active, active_len, u->active_state,
sub_len, u->sub_state, off_active,
id_len, e ? e : u->id,
on_loaded, u->load_state, off_loaded,
on_active, active_len, u->active_state,
sub_len, u->sub_state, off_active,
- job_
len
, u->job_id ? u->job_type : "");
+ job_
count ? job_len + 1 : 0
, u->job_id ? u->job_type : "");
if (!arg_full && arg_no_pager)
printf("%.*s\n", desc_len, u->description);
else
if (!arg_full && arg_no_pager)
printf("%.*s\n", desc_len, u->description);
else
@@
-414,8
+423,9
@@
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
if (n_shown) {
printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
"ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
if (n_shown) {
printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
"ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
- "SUB = The low-level unit activation state, values depend on unit type.\n"
- "JOB = Pending job for the unit.\n\n");
+ "SUB = The low-level unit activation state, values depend on unit type.\n");
+ if (job_count)
+ printf("JOB = Pending job for the unit.\n");
on = ansi_highlight(true);
off = ansi_highlight(false);
} else {
on = ansi_highlight(true);
off = ansi_highlight(false);
} else {
@@
-424,11
+434,11
@@
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
}
if (arg_all)
}
if (arg_all)
- printf("%s%u loaded units listed.%s\n"
+ printf("
\n
%s%u loaded units listed.%s\n"
"To show all installed unit files use 'systemctl list-unit-files'.\n",
on, n_shown, off);
else
"To show all installed unit files use 'systemctl list-unit-files'.\n",
on, n_shown, off);
else
- printf("%s%u loaded units listed.%s Pass --all to see loaded but inactive units, too.\n"
+ printf("
\n
%s%u loaded units listed.%s Pass --all to see loaded but inactive units, too.\n"
"To show all installed unit files use 'systemctl list-unit-files'.\n",
on, n_shown, off);
}
"To show all installed unit files use 'systemctl list-unit-files'.\n",
on, n_shown, off);
}
@@
-1331,9
+1341,9
@@
static int wait_for_jobs(DBusConnection *bus, Set *s) {
else if (streq(d.result, "canceled"))
log_error("Job for %s canceled.", strna(d.name));
else if (streq(d.result, "dependency"))
else if (streq(d.result, "canceled"))
log_error("Job for %s canceled.", strna(d.name));
else if (streq(d.result, "dependency"))
- log_error("A dependency job for %s failed. See 'journalctl' for details.", strna(d.name));
+ log_error("A dependency job for %s failed. See 'journalctl
-n
' for details.", strna(d.name));
else if (!streq(d.result, "done") && !streq(d.result, "skipped"))
else if (!streq(d.result, "done") && !streq(d.result, "skipped"))
- log_error("Job for %s failed. See 'systemctl status %s' and 'journalctl' for details.", strna(d.name), strna(d.name));
+ log_error("Job for %s failed. See 'systemctl status %s' and 'journalctl
-n
' for details.", strna(d.name), strna(d.name));
}
if (streq_ptr(d.result, "timeout"))
}
if (streq_ptr(d.result, "timeout"))
@@
-1608,6
+1618,8
@@
static enum action verb_to_action(const char *verb) {
return ACTION_SUSPEND;
else if (streq(verb, "hibernate"))
return ACTION_HIBERNATE;
return ACTION_SUSPEND;
else if (streq(verb, "hibernate"))
return ACTION_HIBERNATE;
+ else if (streq(verb, "hybrid-sleep"))
+ return ACTION_HYBRID_SLEEP;
else
return ACTION_INVALID;
}
else
return ACTION_INVALID;
}
@@
-1628,7
+1640,8
@@
static int start_unit(DBusConnection *bus, char **args) {
[ACTION_DEFAULT] = SPECIAL_DEFAULT_TARGET,
[ACTION_EXIT] = SPECIAL_EXIT_TARGET,
[ACTION_SUSPEND] = SPECIAL_SUSPEND_TARGET,
[ACTION_DEFAULT] = SPECIAL_DEFAULT_TARGET,
[ACTION_EXIT] = SPECIAL_EXIT_TARGET,
[ACTION_SUSPEND] = SPECIAL_SUSPEND_TARGET,
- [ACTION_HIBERNATE] = SPECIAL_HIBERNATE_TARGET
+ [ACTION_HIBERNATE] = SPECIAL_HIBERNATE_TARGET,
+ [ACTION_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET
};
int r, ret = 0;
};
int r, ret = 0;
@@
-1764,6
+1777,10
@@
static int reboot_with_logind(DBusConnection *bus, enum action a) {
method = "Hibernate";
break;
method = "Hibernate";
break;
+ case ACTION_HYBRID_SLEEP:
+ method = "HybridSleep";
+ break;
+
default:
return -EINVAL;
}
default:
return -EINVAL;
}
@@
-1815,7
+1832,8
@@
static int start_special(DBusConnection *bus, char **args) {
(a == ACTION_POWEROFF ||
a == ACTION_REBOOT ||
a == ACTION_SUSPEND ||
(a == ACTION_POWEROFF ||
a == ACTION_REBOOT ||
a == ACTION_SUSPEND ||
- a == ACTION_HIBERNATE)) {
+ a == ACTION_HIBERNATE ||
+ a == ACTION_HYBRID_SLEEP)) {
r = reboot_with_logind(bus, a);
if (r >= 0)
return r;
r = reboot_with_logind(bus, a);
if (r >= 0)
return r;
@@
-3967,7
+3985,8
@@
static int systemctl_help(void) {
" exit Request user instance exit\n"
" switch-root [ROOT] [INIT] Change to a different root file system\n"
" suspend Suspend the system\n"
" exit Request user instance exit\n"
" switch-root [ROOT] [INIT] Change to a different root file system\n"
" suspend Suspend the system\n"
- " hibernate Hibernate the system\n",
+ " hibernate Hibernate the system\n"
+ " hybrid-sleep Hibernate and suspend the system\n",
program_invocation_short_name);
return 0;
program_invocation_short_name);
return 0;
@@
-4896,6
+4915,7
@@
static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
{ "kexec", EQUAL, 1, start_special },
{ "suspend", EQUAL, 1, start_special },
{ "hibernate", EQUAL, 1, start_special },
{ "kexec", EQUAL, 1, start_special },
{ "suspend", EQUAL, 1, start_special },
{ "hibernate", EQUAL, 1, start_special },
+ { "hybrid-sleep", EQUAL, 1, start_special },
{ "default", EQUAL, 1, start_special },
{ "rescue", EQUAL, 1, start_special },
{ "emergency", EQUAL, 1, start_special },
{ "default", EQUAL, 1, start_special },
{ "rescue", EQUAL, 1, start_special },
{ "emergency", EQUAL, 1, start_special },
@@
-5221,6
+5241,7
@@
int main(int argc, char*argv[]) {
dbus_error_init(&error);
dbus_error_init(&error);
+ setlocale(LC_ALL, "");
log_parse_environment();
log_open();
log_parse_environment();
log_open();