[systemd-commits] 4 commits - src/bus-driverd src/core src/libsystemd src/login src/machine src/shared src/shutdownd src/systemctl
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Tue Mar 4 07:08:42 PST 2014
src/bus-driverd/bus-driverd.c | 8 +--
src/core/dbus-execute.c | 8 +--
src/core/load-fragment.c | 13 +-----
src/core/locale-setup.c | 3 -
src/core/unit.c | 6 --
src/libsystemd/sd-bus/bus-control.c | 8 +--
src/login/logind-core.c | 78 +++++++++++-------------------------
src/login/logind-seat-dbus.c | 6 --
src/login/logind-seat.c | 6 --
src/login/logind-session-dbus.c | 6 --
src/login/logind-user-dbus.c | 6 --
src/machine/machine-dbus.c | 6 --
src/shared/acl-util.c | 3 -
src/shared/conf-parser.c | 11 ++---
src/shared/conf-parser.h | 6 ++
src/shared/fileio.c | 15 +++---
src/shared/strv.c | 17 +++++--
src/shared/strv.h | 1
src/shutdownd/shutdownd.c | 26 ++++--------
src/systemctl/systemctl.c | 16 ++-----
20 files changed, 97 insertions(+), 152 deletions(-)
New commits:
commit b5d742138f71e87312541a89aac5657015f50f48
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Mar 4 09:50:26 2014 -0500
Do not print invalid UTF-8 in error messages
Inexplicably, 550a40ec ('core: do not print invalid utf-8 in error
messages') only fixed two paths. Convert all of them now.
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index d77bf5c..5628d8c 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -536,9 +536,7 @@ int config_parse_exec(const char *unit,
}
if (!utf8_is_valid(path)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Path is not UTF-8 clean, ignoring assignment: %s",
- rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
r = 0;
goto fail;
}
@@ -553,9 +551,7 @@ int config_parse_exec(const char *unit,
}
if (!utf8_is_valid(c)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Path is not UTF-8 clean, ignoring assignment: %s",
- rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
r = 0;
goto fail;
}
@@ -1960,8 +1956,7 @@ int config_parse_unit_requires_mounts_for(
return log_oom();
if (!utf8_is_valid(n)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
continue;
}
@@ -2885,7 +2880,7 @@ int config_parse_namespace_path_strv(
return log_oom();
if (!utf8_is_valid(n)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
continue;
}
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 0a87a71..d27b1b7 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -585,7 +585,7 @@ int config_parse_string(
assert(data);
if (!utf8_is_valid(rvalue)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL, "String is not UTF-8 clean, ignoring assignment: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
return 0;
}
@@ -623,7 +623,7 @@ int config_parse_path(
assert(data);
if (!utf8_is_valid(rvalue)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
return 0;
}
@@ -688,8 +688,7 @@ int config_parse_strv(const char *unit,
return log_oom();
if (!utf8_is_valid(n)) {
- log_syntax(unit, LOG_ERR, filename, line, EINVAL,
- "String is not UTF-8 clean, ignoring: %s", rvalue);
+ log_invalid_utf8(unit, LOG_ERR, filename, line, EINVAL, rvalue);
continue;
}
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index e1c7ab4..ba0e58d 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -121,6 +121,12 @@ int log_syntax_internal(const char *unit, int level,
config_file, config_line, \
error, __VA_ARGS__)
+#define log_invalid_utf8(unit, level, config_file, config_line, error, rvalue) { \
+ _cleanup_free_ char *__p = utf8_escape_invalid(rvalue); \
+ log_syntax(unit, level, config_file, config_line, error, \
+ "String is not UTF-8 clean, ignoring assignment: %s", __p); \
+ }
+
#define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
int function(const char *unit, \
const char *filename, \
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index d591567..f101269 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -598,15 +598,18 @@ static int load_env_file_push(const char *filename, unsigned line,
int r;
if (!utf8_is_valid(key)) {
+ _cleanup_free_ char *t = utf8_escape_invalid(key);
+
log_error("%s:%u: invalid UTF-8 for key '%s', ignoring.",
- filename, line, key);
+ filename, line, t);
return -EINVAL;
}
if (value && !utf8_is_valid(value)) {
- /* FIXME: filter UTF-8 */
+ _cleanup_free_ char *t = utf8_escape_invalid(value);
+
log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.",
- filename, line, key, value);
+ filename, line, key, t);
return -EINVAL;
}
commit 6e18964d3a365567954fe10ddcfad74babdc427c
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Mar 4 09:20:51 2014 -0500
Introduce strv_consume which takes ownership
This mirrors set_consume and makes the common use a bit nicer.
diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index 5405960..3284d62 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -562,11 +562,9 @@ static int driver_list_queued_owners(sd_bus *bus, sd_bus_message *m, void *userd
if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
return -ENOMEM;
- r = strv_push(&owners, n);
- if (r < 0) {
- free(n);
- return -ENOMEM;
- }
+ r = strv_consume(&owners, n);
+ if (r < 0)
+ return r;
}
r = ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd.offset);
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 6d0bdce..3a05303 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -385,11 +385,9 @@ static int property_get_syscall_filter(
if (!name)
continue;
- r = strv_push(&l, name);
- if (r < 0) {
- free(name);
- return -ENOMEM;
- }
+ r = strv_consume(&l, name);
+ if (r < 0)
+ return r;
}
#endif
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index 276deb9..7a41035 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -133,8 +133,7 @@ int locale_setup(char ***environment) {
goto finish;
}
- if (strv_push(&add, s) < 0) {
- free(s);
+ if (strv_consume(&add, s) < 0) {
r = -ENOMEM;
goto finish;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index 1c0b0c7..d0e9159 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -3181,11 +3181,9 @@ int unit_require_mounts_for(Unit *u, const char *path) {
return 0;
}
- r = strv_push(&u->requires_mounts_for, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&u->requires_mounts_for, p);
+ if (r < 0)
return r;
- }
PATH_FOREACH_PREFIX_MORE(prefix, p) {
Set *x;
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 22b95d5..db0c11b 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -237,11 +237,9 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
return -ENOMEM;
- r = strv_push(x, n);
- if (r < 0) {
- free(n);
- return -ENOMEM;
- }
+ r = strv_consume(x, n);
+ if (r < 0)
+ return r;
previous_id = name->owner_id;
}
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 26cddfe..315e6ba 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -399,11 +399,9 @@ int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index f9305dd..fc728bb 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -558,11 +558,9 @@ int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index 18eea89..b5d27e7 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -315,11 +315,9 @@ int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index df96ccf..c9e3bb7 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -225,11 +225,9 @@ int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char
if (!p)
return -ENOMEM;
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(&l, p);
+ if (r < 0)
return r;
- }
}
*nodes = l;
diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c
index fb04e49..c93f58a 100644
--- a/src/shared/acl-util.c
+++ b/src/shared/acl-util.c
@@ -136,9 +136,8 @@ int search_acl_groups(char*** dst, const char* path, bool* belong) {
return log_oom();
}
- r = strv_push(dst, name);
+ r = strv_consume(dst, name);
if (r < 0) {
- free(name);
acl_free(acl);
return log_oom();
}
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 86435d3..0a87a71 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -681,7 +681,7 @@ int config_parse_strv(const char *unit,
}
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- _cleanup_free_ char *n;
+ char *n;
n = cunescape_length(w, l);
if (!n)
@@ -693,7 +693,7 @@ int config_parse_strv(const char *unit,
continue;
}
- r = strv_extend(sv, n);
+ r = strv_consume(sv, n);
if (r < 0)
return log_oom();
}
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index 0d3f2e9..d591567 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -614,11 +614,9 @@ static int load_env_file_push(const char *filename, unsigned line,
if (!p)
return -ENOMEM;
- r = strv_push(m, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(m, p);
+ if (r < 0)
return r;
- }
free(value);
return 0;
diff --git a/src/shared/strv.c b/src/shared/strv.c
index 13deba7..67706dc 100644
--- a/src/shared/strv.c
+++ b/src/shared/strv.c
@@ -378,9 +378,18 @@ int strv_push(char ***l, char *value) {
return 0;
}
+int strv_consume(char ***l, char *value) {
+ int r;
+
+ r = strv_push(l, value);
+ if (r < 0)
+ free(value);
+
+ return r;
+}
+
int strv_extend(char ***l, const char *value) {
char *v;
- int r;
if (!value)
return 0;
@@ -389,11 +398,7 @@ int strv_extend(char ***l, const char *value) {
if (!v)
return -ENOMEM;
- r = strv_push(l, v);
- if (r < 0)
- free(v);
-
- return r;
+ return strv_consume(l, v);
}
char **strv_uniq(char **l) {
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 715bc54..13a4bb6 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -40,6 +40,7 @@ int strv_extend_strv(char ***a, char **b);
int strv_extend_strv_concat(char ***a, char **b, const char *suffix);
int strv_extend(char ***l, const char *value);
int strv_push(char ***l, char *value);
+int strv_consume(char ***l, char *value);
char **strv_remove(char **l, const char *s);
char **strv_uniq(char **l);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 8692716..952d2f8 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2167,13 +2167,11 @@ static int expand_names(sd_bus *bus, char **names, const char* suffix, char ***r
return log_oom();
if (string_is_glob(t))
- r = strv_push(&globs, t);
+ r = strv_consume(&globs, t);
else
- r = strv_push(&mangled, t);
- if (r < 0) {
- free(t);
+ r = strv_consume(&mangled, t);
+ if (r < 0)
return log_oom();
- }
}
/* Query the manager only if any of the names are a glob, since
@@ -5346,10 +5344,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
if (!prop)
return log_oom();
- if (strv_push(&arg_properties, prop) < 0) {
- free(prop);
+ if (strv_consume(&arg_properties, prop) < 0)
return log_oom();
- }
}
}
@@ -5518,10 +5514,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
if (!s)
return log_oom();
- if (strv_push(&arg_states, s) < 0) {
- free(s);
+ if (strv_consume(&arg_states, s) < 0)
return log_oom();
- }
}
break;
}
commit e062dec5ae1a443d47885537af85d328c83c67db
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Feb 12 20:40:11 2014 -0500
shutdownd: modernizations
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 4a17198..8d034e6 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -61,9 +61,9 @@ static int read_packet(int fd, union shutdown_buffer *_b) {
} control = {};
struct msghdr msghdr = {
.msg_iov = &iovec,
- msghdr.msg_iovlen = 1,
- msghdr.msg_control = &control,
- msghdr.msg_controllen = sizeof(control),
+ .msg_iovlen = 1,
+ .msg_control = &control,
+ .msg_controllen = sizeof(control),
};
assert(fd >= 0);
@@ -120,7 +120,7 @@ static int read_packet(int fd, union shutdown_buffer *_b) {
static void warn_wall(usec_t n, struct sd_shutdown_command *c) {
char date[FORMAT_TIMESTAMP_MAX];
const char *prefix;
- char *l = NULL;
+ _cleanup_free_ char *l = NULL;
assert(c);
assert(c->warn_wall);
@@ -142,12 +142,10 @@ static void warn_wall(usec_t n, struct sd_shutdown_command *c) {
assert_not_reached("Unknown mode!");
if (asprintf(&l, "%s%s%s%s!", c->wall_message, c->wall_message[0] ? "\n" : "",
- prefix, format_timestamp(date, sizeof(date), c->usec)) < 0)
- log_error("Failed to allocate wall message");
- else {
+ prefix, format_timestamp(date, sizeof(date), c->usec)) >= 0)
utmp_wall(l, NULL);
- free(l);
- }
+ else
+ log_error("Failed to allocate wall message");
}
_const_ static usec_t when_wall(usec_t n, usec_t elapse) {
@@ -199,8 +197,8 @@ static const char *mode_to_string(enum sd_shutdown_mode m) {
static int update_schedule_file(struct sd_shutdown_command *c) {
int r;
- FILE *f;
- char *temp_path, *t;
+ _cleanup_fclose_ FILE *f = NULL;
+ _cleanup_free_ char *t = NULL, *temp_path = NULL;
assert(c);
@@ -217,7 +215,6 @@ static int update_schedule_file(struct sd_shutdown_command *c) {
r = fopen_temporary("/run/systemd/shutdown/scheduled", &f, &temp_path);
if (r < 0) {
log_error("Failed to save information about scheduled shutdowns: %s", strerror(-r));
- free(t);
return r;
}
@@ -237,8 +234,6 @@ static int update_schedule_file(struct sd_shutdown_command *c) {
if (!isempty(t))
fprintf(f, "WALL_MESSAGE=%s\n", t);
- free(t);
-
fflush(f);
if (ferror(f) || rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) {
@@ -249,9 +244,6 @@ static int update_schedule_file(struct sd_shutdown_command *c) {
unlink("/run/systemd/shutdown/scheduled");
}
- fclose(f);
- free(temp_path);
-
return r;
}
commit 61376f96a98291b5421bfd79a15ca4db50c2a3fe
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sun Feb 2 23:58:16 2014 -0500
logind: small simplifications
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index b8d03c3..ca34d37 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -42,20 +42,15 @@ int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_dev
assert(sysfs);
d = hashmap_get(m->devices, sysfs);
- if (d) {
- if (_device)
- *_device = d;
-
+ if (d)
/* we support adding master-flags, but not removing them */
d->master = d->master || master;
-
- return 0;
+ else {
+ d = device_new(m, sysfs, master);
+ if (!d)
+ return -ENOMEM;
}
- d = device_new(m, sysfs, master);
- if (!d)
- return -ENOMEM;
-
if (_device)
*_device = d;
@@ -69,17 +64,12 @@ int manager_add_seat(Manager *m, const char *id, Seat **_seat) {
assert(id);
s = hashmap_get(m->seats, id);
- if (s) {
- if (_seat)
- *_seat = s;
-
- return 0;
+ if (!s) {
+ s = seat_new(m, id);
+ if (!s)
+ return -ENOMEM;
}
- s = seat_new(m, id);
- if (!s)
- return -ENOMEM;
-
if (_seat)
*_seat = s;
@@ -93,17 +83,12 @@ int manager_add_session(Manager *m, const char *id, Session **_session) {
assert(id);
s = hashmap_get(m->sessions, id);
- if (s) {
- if (_session)
- *_session = s;
-
- return 0;
+ if (!s) {
+ s = session_new(m, id);
+ if (!s)
+ return -ENOMEM;
}
- s = session_new(m, id);
- if (!s)
- return -ENOMEM;
-
if (_session)
*_session = s;
@@ -117,17 +102,12 @@ int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **
assert(name);
u = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
- if (u) {
- if (_user)
- *_user = u;
-
- return 0;
+ if (!u) {
+ u = user_new(m, uid, gid, name);
+ if (!u)
+ return -ENOMEM;
}
- u = user_new(m, uid, gid, name);
- if (!u)
- return -ENOMEM;
-
if (_user)
*_user = u;
@@ -193,17 +173,12 @@ int manager_add_button(Manager *m, const char *name, Button **_button) {
assert(name);
b = hashmap_get(m->buttons, name);
- if (b) {
- if (_button)
- *_button = b;
-
- return 0;
+ if (!b) {
+ b = button_new(m, name);
+ if (!b)
+ return -ENOMEM;
}
- b = button_new(m, name);
- if (!b)
- return -ENOMEM;
-
if (_button)
*_button = b;
@@ -441,7 +416,8 @@ bool manager_shall_kill(Manager *m, const char *user) {
static int vt_is_busy(unsigned int vtnr) {
struct vt_stat vt_stat;
- int r = 0, fd;
+ int r = 0;
+ _cleanup_close_ int fd;
assert(vtnr >= 1);
@@ -460,14 +436,12 @@ static int vt_is_busy(unsigned int vtnr) {
else
r = !!(vt_stat.v_state & (1 << vtnr));
- close_nointr_nofail(fd);
-
return r;
}
int manager_spawn_autovt(Manager *m, unsigned int vtnr) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_free_ char *name = NULL;
+ char name[sizeof("autovt at tty.service") + DECIMAL_STR_MAX(unsigned int)];
int r;
assert(m);
@@ -489,9 +463,7 @@ int manager_spawn_autovt(Manager *m, unsigned int vtnr) {
return -EBUSY;
}
- if (asprintf(&name, "autovt at tty%u.service", vtnr) < 0)
- return log_oom();
-
+ snprintf(name, sizeof(name), "autovt at tty%u.service", vtnr);
r = sd_bus_call_method(
m->bus,
"org.freedesktop.systemd1",
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index 96cf08e..3f5efdc 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -168,14 +168,12 @@ int seat_load(Seat *s) {
}
static int vt_allocate(unsigned int vtnr) {
- _cleanup_free_ char *p = NULL;
+ char p[sizeof("/dev/tty") + DECIMAL_STR_MAX(unsigned int)];
_cleanup_close_ int fd = -1;
assert(vtnr >= 1);
- if (asprintf(&p, "/dev/tty%u", vtnr) < 0)
- return -ENOMEM;
-
+ snprintf(p, sizeof(p), "/dev/tty%u", vtnr);
fd = open_terminal(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
return -errno;
More information about the systemd-commits
mailing list