Merge pull request #3392 from poettering/assorted-stuff

Assorted stuff
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2016-06-04 18:47:56 -04:00
19 changed files with 91 additions and 152 deletions
-4
View File
@@ -33,8 +33,6 @@ Janitorial Clean-ups:
Features:
* make sure bash completion uses journalctl --fields to get fields list
* use phyical_memory() to allow MemoryLimit= configuration based on available system memory
* ProtectKernelLogs= (drops CAP_SYSLOG, add seccomp for syslog() syscall, and DeviceAllow to /dev/kmsg) in service files
@@ -49,8 +47,6 @@ Features:
* RestrictNamespaces= or so in services (taking away the ability to create namespaces, with setns, unshare, clone)
* IAID field must move from [Link] to [DHCP] section in .network files
* make sure the ratelimit object can deal with USEC_INFINITY as way to turn off things
* journalctl: make sure -f ends when the container indicated by -M terminates
+3 -13
View File
@@ -30,17 +30,6 @@ __get_machines() {
{ while read a b; do echo " $a"; done; } | sort -u;
}
__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE
_{P,U,G}ID _COMM _EXE _CMDLINE
_CAP_EFFECTIVE _AUDIT_{SESSION,LOGINUID}
_SYSTEMD_{CGROUP,SESSION,{,USER_}UNIT,OWNER_UID,SLICE}
_SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
_{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
_KERNEL_{DEVICE,SUBSYSTEM}
_UDEV_{SYSNAME,DEVNODE,DEVLINK}
__CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
__syslog_priorities=(emerg alert crit err warning notice info debug)
_journalctl() {
@@ -79,7 +68,7 @@ _journalctl() {
comps='short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat'
;;
--field|-F)
comps=${__journal_fields[*]}
comps=$(journalctl --fields | sort 2>/dev/null)
;;
--machine|-M)
comps=$( __get_machines )
@@ -125,8 +114,9 @@ _journalctl() {
mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
else
mapfile -t field_vals < <(journalctl --fields 2>/dev/null)
compopt -o nospace
COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
COMPREPLY=( $(compgen -W '${field_vals[*]}' -S= -- "$cur") )
fi
}
+4 -4
View File
@@ -758,9 +758,9 @@ static int list_dependencies_print(const char *name, unsigned int level, unsigne
if (times) {
if (times->time)
printf("%s%s @%s +%s%s", ANSI_HIGHLIGHT_RED, name,
printf("%s%s @%s +%s%s", ansi_highlight_red(), name,
format_timespan(ts, sizeof(ts), times->activating - boot->userspace_time, USEC_PER_MSEC),
format_timespan(ts2, sizeof(ts2), times->time, USEC_PER_MSEC), ANSI_NORMAL);
format_timespan(ts2, sizeof(ts2), times->time, USEC_PER_MSEC), ansi_normal());
else if (times->activated > boot->userspace_time)
printf("%s @%s", name, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
else
@@ -926,8 +926,8 @@ static int list_dependencies(sd_bus *bus, const char *name) {
if (times) {
if (times->time)
printf("%s%s +%s%s\n", ANSI_HIGHLIGHT_RED, id,
format_timespan(ts, sizeof(ts), times->time, USEC_PER_MSEC), ANSI_NORMAL);
printf("%s%s +%s%s\n", ansi_highlight_red(), id,
format_timespan(ts, sizeof(ts), times->time, USEC_PER_MSEC), ansi_normal());
else if (times->activated > boot->userspace_time)
printf("%s @%s\n", id, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
else
+4
View File
@@ -66,6 +66,10 @@ static inline bool isempty(const char *p) {
return !p || !p[0];
}
static inline const char *empty_to_null(const char *p) {
return isempty(p) ? NULL : p;
}
static inline char *startswith(const char *s, const char *prefix) {
size_t l;
+18 -7
View File
@@ -155,14 +155,14 @@ int ask_char(char *ret, const char *replies, const char *text, ...) {
char c;
bool need_nl = true;
if (on_tty())
if (colors_enabled())
fputs(ANSI_HIGHLIGHT, stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
if (on_tty())
if (colors_enabled())
fputs(ANSI_NORMAL, stdout);
fflush(stdout);
@@ -199,14 +199,14 @@ int ask_string(char **ret, const char *text, ...) {
char line[LINE_MAX];
va_list ap;
if (on_tty())
if (colors_enabled())
fputs(ANSI_HIGHLIGHT, stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
if (on_tty())
if (colors_enabled())
fputs(ANSI_NORMAL, stdout);
fflush(stdout);
@@ -1193,6 +1193,19 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
return receive_one_fd(pair[0], 0);
}
bool terminal_is_dumb(void) {
const char *e;
if (!on_tty())
return true;
e = getenv("TERM");
if (!e)
return true;
return streq(e, "dumb");
}
bool colors_enabled(void) {
static int enabled = -1;
@@ -1202,10 +1215,8 @@ bool colors_enabled(void) {
colors = getenv("SYSTEMD_COLORS");
if (colors)
enabled = parse_boolean(colors) != 0;
else if (streq_ptr(getenv("TERM"), "dumb"))
enabled = false;
else
enabled = on_tty();
enabled = !terminal_is_dumb();
}
return enabled;
+1
View File
@@ -80,6 +80,7 @@ unsigned lines(void);
void columns_lines_cache_reset(int _unused_ signum);
bool on_tty(void);
bool terminal_is_dumb(void);
bool colors_enabled(void);
static inline const char *ansi_underline(void) {
+1 -1
View File
@@ -558,7 +558,7 @@ static void display(Hashmap *a) {
assert(a);
if (on_tty())
if (!terminal_is_dumb())
fputs(ANSI_HOME_CLEAR, stdout);
array = alloca(sizeof(Group*) * hashmap_size(a));
+6 -8
View File
@@ -479,8 +479,7 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
if (r < 0)
return r;
if (isempty(name))
name = NULL;
name = empty_to_null(name);
if (streq_ptr(name, c->data[PROP_STATIC_HOSTNAME]))
return sd_bus_reply_method_return(m, NULL);
@@ -499,9 +498,9 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (isempty(name)) {
if (isempty(name))
c->data[PROP_STATIC_HOSTNAME] = mfree(c->data[PROP_STATIC_HOSTNAME]);
} else {
else {
char *h;
if (!hostname_is_valid(name, false))
@@ -546,8 +545,7 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
if (r < 0)
return r;
if (isempty(name))
name = NULL;
name = empty_to_null(name);
if (streq_ptr(name, c->data[prop]))
return sd_bus_reply_method_return(m, NULL);
@@ -570,9 +568,9 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (isempty(name)) {
if (isempty(name))
c->data[prop] = mfree(c->data[prop]);
} else {
else {
char *h;
/* The icon name might ultimately be used as file
+7 -2
View File
@@ -54,7 +54,9 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
j = (n * (unsigned) p) / 65535ULL;
k = n - j;
fputs("\r\x1B[?25l" ANSI_HIGHLIGHT_GREEN, stdout);
fputs("\r", stdout);
if (colors_enabled())
fputs("\x1B[?25l" ANSI_HIGHLIGHT_GREEN, stdout);
for (i = 0; i < j; i++)
fputs("\xe2\x96\x88", stdout);
@@ -66,7 +68,10 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
printf(" %3"PRIu64"%%", 100U * p / 65535U);
fputs("\r\x1B[?25h", stdout);
fputs("\r", stdout);
if (colors_enabled())
fputs("\x1B[?25h", stdout);
fflush(stdout);
}
+9 -4
View File
@@ -1664,15 +1664,19 @@ static int setup_keys(void) {
if (on_tty()) {
fprintf(stderr,
"\n"
"The new key pair has been generated. The " ANSI_HIGHLIGHT "secret sealing key" ANSI_NORMAL " has been written to\n"
"The new key pair has been generated. The %ssecret sealing key%s has been written to\n"
"the following local file. This key file is automatically updated when the\n"
"sealing key is advanced. It should not be used on multiple hosts.\n"
"\n"
"\t%s\n"
"\n"
"Please write down the following " ANSI_HIGHLIGHT "secret verification key" ANSI_NORMAL ". It should be stored\n"
"Please write down the following %ssecret verification key%s. It should be stored\n"
"at a safe location and should not be saved locally on disk.\n"
"\n\t" ANSI_HIGHLIGHT_RED, p);
"\n\t%s",
ansi_highlight(), ansi_normal(),
ansi_highlight(), ansi_normal(),
ansi_highlight_red(),
p);
fflush(stderr);
}
for (i = 0; i < seed_size; i++) {
@@ -1687,8 +1691,9 @@ static int setup_keys(void) {
char tsb[FORMAT_TIMESPAN_MAX], *hn;
fprintf(stderr,
ANSI_NORMAL "\n"
"%s\n"
"The sealing key is automatically changed every %s.\n",
ansi_normal(),
format_timespan(tsb, sizeof(tsb), arg_interval, 0));
hn = gethostname_malloc();
+2 -1
View File
@@ -633,7 +633,8 @@ static int parse_request(uint8_t code, uint8_t len, const void *option, void *us
break;
case SD_DHCP_OPTION_MAXIMUM_MESSAGE_SIZE:
if (len == 2)
if (len == 2 && unaligned_read_be16(option) >= sizeof(DHCPPacket))
req->max_optlen = unaligned_read_be16(option) - sizeof(DHCPPacket);
break;
+7 -22
View File
@@ -97,10 +97,6 @@ typedef struct Context {
Hashmap *polkit_registry;
} Context;
static const char* nonempty(const char *s) {
return isempty(s) ? NULL : s;
}
static bool startswith_comma(const char *s, const char *prefix) {
const char *t;
@@ -171,8 +167,7 @@ static int locale_read_data(Context *c) {
for (p = 0; p < _LOCALE_MAX; p++) {
assert(names[p]);
r = free_and_strdup(&c->locale[p],
nonempty(getenv(names[p])));
r = free_and_strdup(&c->locale[p], empty_to_null(getenv(names[p])));
if (r < 0)
return r;
}
@@ -1041,11 +1036,8 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
if (r < 0)
return r;
if (isempty(keymap))
keymap = NULL;
if (isempty(keymap_toggle))
keymap_toggle = NULL;
keymap = empty_to_null(keymap);
keymap_toggle = empty_to_null(keymap_toggle);
if (!streq_ptr(keymap, c->vc_keymap) ||
!streq_ptr(keymap_toggle, c->vc_keymap_toggle)) {
@@ -1214,17 +1206,10 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
if (r < 0)
return r;
if (isempty(layout))
layout = NULL;
if (isempty(model))
model = NULL;
if (isempty(variant))
variant = NULL;
if (isempty(options))
options = NULL;
layout = empty_to_null(layout);
model = empty_to_null(model);
variant = empty_to_null(variant);
options = empty_to_null(options);
if (!streq_ptr(layout, c->x11_layout) ||
!streq_ptr(model, c->x11_model) ||
+1 -2
View File
@@ -655,8 +655,7 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
r = sd_bus_message_read(message, "ss", &user, &path);
if (r < 0)
return r;
if (isempty(user))
user = NULL;
user = empty_to_null(user);
if (isempty(path))
path = "/bin/sh";
if (!path_is_absolute(path))
+4 -8
View File
@@ -658,10 +658,8 @@ static int resolve_service(sd_bus *bus, const char *name, const char *type, cons
assert(bus);
assert(domain);
if (isempty(name))
name = NULL;
if (isempty(type))
type = NULL;
name = empty_to_null(name);
type = empty_to_null(type);
if (arg_ifindex > 0 && !if_indextoname(arg_ifindex, ifname))
return log_error_errno(errno, "Failed to resolve interface name for index %i: %m", arg_ifindex);
@@ -820,10 +818,8 @@ static int resolve_service(sd_bus *bus, const char *name, const char *type, cons
if (r < 0)
return bus_log_parse_error(r);
if (isempty(canonical_name))
canonical_name = NULL;
if (isempty(canonical_type))
canonical_type = NULL;
canonical_name = empty_to_null(canonical_name);
canonical_type = empty_to_null(canonical_type);
if (!streq_ptr(name, canonical_name) ||
!streq_ptr(type, canonical_type) ||
+4 -2
View File
@@ -253,10 +253,12 @@ int ask_password_tty(
goto finish;
}
loop_write(ttyfd, ANSI_HIGHLIGHT, strlen(ANSI_HIGHLIGHT), false);
if (colors_enabled())
loop_write(ttyfd, ANSI_HIGHLIGHT, strlen(ANSI_HIGHLIGHT), false);
loop_write(ttyfd, message, strlen(message), false);
loop_write(ttyfd, " ", 1, false);
loop_write(ttyfd, ANSI_NORMAL, strlen(ANSI_NORMAL), false);
if (colors_enabled())
loop_write(ttyfd, ANSI_NORMAL, strlen(ANSI_NORMAL), false);
new_termios = old_termios;
new_termios.c_lflag &= ~(ICANON|ECHO);
+1 -1
View File
@@ -63,7 +63,7 @@ int pager_open(bool no_pager, bool jump_to_end) {
if (pager_pid > 0)
return 1;
if (!on_tty())
if (terminal_is_dumb())
return 0;
pager = getenv("SYSTEMD_PAGER");
+1 -3
View File
@@ -5218,9 +5218,7 @@ static int switch_root(int argc, char *argv[], void *userdata) {
init = cmdline_init;
}
if (isempty(init))
init = NULL;
init = empty_to_null(init);
if (init) {
const char *root_systemd_path = NULL, *root_init_path = NULL;
+11 -63
View File
@@ -42,32 +42,19 @@
#include "unit-name.h"
#include "util.h"
typedef enum RunlevelType {
RUNLEVEL_UP,
RUNLEVEL_DOWN
} RunlevelType;
static const struct {
const char *path;
const char *target;
const RunlevelType type;
} rcnd_table[] = {
/* Standard SysV runlevels for start-up */
{ "rc1.d", SPECIAL_RESCUE_TARGET, RUNLEVEL_UP },
{ "rc2.d", SPECIAL_MULTI_USER_TARGET, RUNLEVEL_UP },
{ "rc3.d", SPECIAL_MULTI_USER_TARGET, RUNLEVEL_UP },
{ "rc4.d", SPECIAL_MULTI_USER_TARGET, RUNLEVEL_UP },
{ "rc5.d", SPECIAL_GRAPHICAL_TARGET, RUNLEVEL_UP },
{ "rc1.d", SPECIAL_RESCUE_TARGET },
{ "rc2.d", SPECIAL_MULTI_USER_TARGET },
{ "rc3.d", SPECIAL_MULTI_USER_TARGET },
{ "rc4.d", SPECIAL_MULTI_USER_TARGET },
{ "rc5.d", SPECIAL_GRAPHICAL_TARGET },
/* Standard SysV runlevels for shutdown */
{ "rc0.d", SPECIAL_POWEROFF_TARGET, RUNLEVEL_DOWN },
{ "rc6.d", SPECIAL_REBOOT_TARGET, RUNLEVEL_DOWN }
/* Note that the order here matters, as we read the
directories in this order, and we want to make sure that
sysv_start_priority is known when we first load the
unit. And that value we only know from S links. Hence
UP must be read before DOWN */
/* We ignore the SysV runlevels for shutdown here, as SysV services get default dependencies anyway, and that
* means they are shut down anyway at system power off if running. */
};
static const char *arg_dest = "/tmp";
@@ -82,7 +69,6 @@ typedef struct SysvStub {
char **after;
char **wants;
char **wanted_by;
char **conflicts;
bool has_lsb;
bool reload;
bool loaded;
@@ -100,7 +86,6 @@ static void free_sysvstub(SysvStub *s) {
strv_free(s->after);
strv_free(s->wants);
strv_free(s->wanted_by);
strv_free(s->conflicts);
free(s);
}
@@ -199,8 +184,6 @@ static int generate_unit_file(SysvStub *s) {
fprintf(f, "After=%s\n", *p);
STRV_FOREACH(p, s->wants)
fprintf(f, "Wants=%s\n", *p);
STRV_FOREACH(p, s->conflicts)
fprintf(f, "Conflicts=%s\n", *p);
fprintf(f,
"\n[Service]\n"
@@ -527,9 +510,7 @@ static int load_sysv(SysvStub *s) {
t[k-1] = 0;
}
j = strstrip(t+12);
if (isempty(j))
j = NULL;
j = empty_to_null(strstrip(t+12));
r = free_and_strdup(&chkconfig_description, j);
if (r < 0)
@@ -605,9 +586,7 @@ static int load_sysv(SysvStub *s) {
state = LSB_DESCRIPTION;
j = strstrip(t+12);
if (isempty(j))
j = NULL;
j = empty_to_null(strstrip(t+12));
r = free_and_strdup(&long_description, j);
if (r < 0)
@@ -618,9 +597,7 @@ static int load_sysv(SysvStub *s) {
state = LSB;
j = strstrip(t+18);
if (isempty(j))
j = NULL;
j = empty_to_null(strstrip(t+18));
r = free_and_strdup(&short_description, j);
if (r < 0)
@@ -841,7 +818,6 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_services) {
Set *runlevel_services[ELEMENTSOF(rcnd_table)] = {};
_cleanup_set_free_ Set *shutdown_services = NULL;
_cleanup_strv_free_ char **sysvrcnd_path = NULL;
SysvStub *service;
unsigned i;
@@ -912,8 +888,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
if (de->d_name[0] == 'S') {
if (rcnd_table[i].type == RUNLEVEL_UP)
service->sysv_start_priority = MAX(a*10 + b, service->sysv_start_priority);
service->sysv_start_priority = MAX(a*10 + b, service->sysv_start_priority);
r = set_ensure_allocated(&runlevel_services[i], NULL);
if (r < 0) {
@@ -927,20 +902,6 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
goto finish;
}
} else if (de->d_name[0] == 'K' &&
(rcnd_table[i].type == RUNLEVEL_DOWN)) {
r = set_ensure_allocated(&shutdown_services, NULL);
if (r < 0) {
log_oom();
goto finish;
}
r = set_put(shutdown_services, service);
if (r < 0) {
log_oom();
goto finish;
}
}
}
}
@@ -961,19 +922,6 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
}
}
SET_FOREACH(service, shutdown_services, j) {
r = strv_extend(&service->before, SPECIAL_SHUTDOWN_TARGET);
if (r < 0) {
log_oom();
goto finish;
}
r = strv_extend(&service->conflicts, SPECIAL_SHUTDOWN_TARGET);
if (r < 0) {
log_oom();
goto finish;
}
}
r = 0;
finish:
+7 -7
View File
@@ -144,13 +144,13 @@ static void print_status_info(const StatusInfo *i) {
yes_no(i->rtc_local));
if (i->rtc_local)
fputs("\n" ANSI_HIGHLIGHT
"Warning: The system is configured to read the RTC time in the local time zone.\n"
" This mode can not be fully supported. It will create various problems\n"
" with time zone changes and daylight saving time adjustments. The RTC\n"
" time is never updated, it relies on external facilities to maintain it.\n"
" If at all possible, use RTC in UTC by calling\n"
" 'timedatectl set-local-rtc 0'." ANSI_NORMAL "\n", stdout);
printf("\n%s"
"Warning: The system is configured to read the RTC time in the local time zone.\n"
" This mode can not be fully supported. It will create various problems\n"
" with time zone changes and daylight saving time adjustments. The RTC\n"
" time is never updated, it relies on external facilities to maintain it.\n"
" If at all possible, use RTC in UTC by calling\n"
" 'timedatectl set-local-rtc 0'.%s\n", ansi_highlight(), ansi_normal());
}
static int show_status(sd_bus *bus, char **args, unsigned n) {