chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
remove GTK pieces
[elogind.git]
/
src
/
load-fragment.c
diff --git
a/src/load-fragment.c
b/src/load-fragment.c
index 12079c640fdefbeebca6bceb9752ab0494ae8968..637c82b427d461fd0417831edb7aa3e4b16f0b37 100644
(file)
--- a/
src/load-fragment.c
+++ b/
src/load-fragment.c
@@
-43,6
+43,7
@@
#include "missing.h"
#include "unit-name.h"
#include "bus-errors.h"
#include "missing.h"
#include "unit-name.h"
#include "bus-errors.h"
+#include "utf8.h"
#ifndef HAVE_SYSV_COMPAT
int config_parse_warn_compat(
#ifndef HAVE_SYSV_COMPAT
int config_parse_warn_compat(
@@
-84,22
+85,18
@@
int config_parse_unit_deps(
char *t, *k;
int r;
char *t, *k;
int r;
- if (!(t = strndup(w, l)))
+ t = strndup(w, l);
+ if (!t)
return -ENOMEM;
k = unit_name_printf(u, t);
free(t);
return -ENOMEM;
k = unit_name_printf(u, t);
free(t);
-
if (!k)
return -ENOMEM;
r = unit_add_dependency_by_name(u, d, k, NULL, true);
if (!k)
return -ENOMEM;
r = unit_add_dependency_by_name(u, d, k, NULL, true);
-
- if (r < 0) {
- log_error("Failed to add dependency on %s, ignoring: %s", k, strerror(-r));
- free(k);
- return 0;
- }
+ if (r < 0)
+ log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
free(k);
}
free(k);
}
@@
-131,22
+128,18
@@
int config_parse_unit_names(
char *t, *k;
int r;
char *t, *k;
int r;
- if (!(t = strndup(w, l)))
+ t = strndup(w, l);
+ if (!t)
return -ENOMEM;
k = unit_name_printf(u, t);
free(t);
return -ENOMEM;
k = unit_name_printf(u, t);
free(t);
-
if (!k)
return -ENOMEM;
r = unit_merge_by_name(u, k);
if (!k)
return -ENOMEM;
r = unit_merge_by_name(u, k);
-
- if (r < 0) {
+ if (r < 0)
log_error("Failed to add name %s, ignoring: %s", k, strerror(-r));
log_error("Failed to add name %s, ignoring: %s", k, strerror(-r));
- free(k);
- return 0;
- }
free(k);
}
free(k);
}
@@
-165,27
+158,22
@@
int config_parse_unit_string_printf(
void *userdata) {
Unit *u = userdata;
void *userdata) {
Unit *u = userdata;
- char **s = data;
char *k;
char *k;
+ int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(filename);
assert(lvalue);
assert(rvalue);
- assert(s);
assert(u);
assert(u);
- if (!(k = unit_full_printf(u, rvalue)))
+ k = unit_full_printf(u, rvalue);
+ if (!k)
return -ENOMEM;
return -ENOMEM;
- free(*s);
- if (*k)
- *s = k;
- else {
- free(k);
- *s = NULL;
- }
+ r = config_parse_string(filename, line, section, lvalue, ltype, k, data, userdata);
+ free (k);
- return
0
;
+ return
r
;
}
int config_parse_unit_strv_printf(
}
int config_parse_unit_strv_printf(
@@
-228,30
+216,22
@@
int config_parse_unit_path_printf(
void *userdata) {
Unit *u = userdata;
void *userdata) {
Unit *u = userdata;
- char **s = data;
char *k;
char *k;
+ int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(filename);
assert(lvalue);
assert(rvalue);
- assert(s);
assert(u);
assert(u);
- if (!(k = unit_full_printf(u, rvalue)))
+ k = unit_full_printf(u, rvalue);
+ if (!k)
return -ENOMEM;
return -ENOMEM;
- if (!path_is_absolute(k)) {
- log_error("[%s:%u] Not an absolute path: %s", filename, line, k);
- free(k);
- return -EINVAL;
- }
-
- path_kill_slashes(k);
-
- free(*s);
- *s = k;
+ r = config_parse_path(filename, line, section, lvalue, ltype, k, data, userdata);
+ free(k);
- return
0
;
+ return
r
;
}
int config_parse_socket_listen(
}
int config_parse_socket_listen(
@@
-272,9
+252,10
@@
int config_parse_socket_listen(
assert(rvalue);
assert(data);
assert(rvalue);
assert(data);
- s =
(Socket*) data
;
+ s =
SOCKET(data)
;
- if (!(p = new0(SocketPort, 1)))
+ p = new0(SocketPort, 1);
+ if (!p)
return -ENOMEM;
if (streq(lvalue, "ListenFIFO")) {
return -ENOMEM;
if (streq(lvalue, "ListenFIFO")) {
@@
-383,7
+364,7
@@
int config_parse_socket_bind(
assert(rvalue);
assert(data);
assert(rvalue);
assert(data);
- s =
(Socket*) data
;
+ s =
SOCKET(data)
;
if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
int r;
if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
int r;
@@
-481,6
+462,7
@@
int config_parse_exec(
ExecCommand **e = data, *nce;
char *path, **n;
unsigned k;
ExecCommand **e = data, *nce;
char *path, **n;
unsigned k;
+ int r;
assert(filename);
assert(lvalue);
assert(filename);
assert(lvalue);
@@
-531,7
+513,8
@@
int config_parse_exec(
k++;
}
k++;
}
- if (!(n = new(char*, k + !honour_argv0)))
+ n = new(char*, k + !honour_argv0);
+ if (!n)
return -ENOMEM;
k = 0;
return -ENOMEM;
k = 0;
@@
-541,11
+524,33
@@
int config_parse_exec(
if (honour_argv0 && w == rvalue) {
assert(!path);
if (honour_argv0 && w == rvalue) {
assert(!path);
- if (!(path = cunescape_length(w, l)))
+
+ path = strndup(w, l);
+ if (!path) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ if (!utf8_is_valid(path)) {
+ log_error("[%s:%u] Path is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
+ r = 0;
goto fail;
goto fail;
+ }
+
} else {
} else {
- if (!(n[k++] = cunescape_length(w, l)))
+ char *c;
+
+ c = n[k++] = cunescape_length(w, l);
+ if (!c) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ if (!utf8_is_valid(c)) {
+ log_error("[%s:%u] Path is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
+ r = 0;
goto fail;
goto fail;
+ }
}
}
}
}
@@
-553,19
+558,25
@@
int config_parse_exec(
if (!n[0]) {
log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
if (!n[0]) {
log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
- strv_free(n);
- free(path);
- return 0;
+ r = 0;
+ goto fail;
}
}
- if (!path)
- if (!(path = strdup(n[0])))
+ if (!path) {
+ path = strdup(n[0]);
+ if (!path) {
+ r = -ENOMEM;
goto fail;
goto fail;
+ }
+ }
assert(path_is_absolute(path));
assert(path_is_absolute(path));
- if (!(nce = new0(ExecCommand, 1)))
+ nce = new0(ExecCommand, 1);
+ if (!nce) {
+ r = -ENOMEM;
goto fail;
goto fail;
+ }
nce->argv = n;
nce->path = path;
nce->argv = n;
nce->path = path;
@@
-586,7
+597,7
@@
fail:
free(path);
free(nce);
free(path);
free(nce);
- return
-ENOMEM
;
+ return
r
;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
@@
-1265,6
+1276,7
@@
int config_parse_timer_unit(
Timer *t = data;
int r;
DBusError error;
Timer *t = data;
int r;
DBusError error;
+ Unit *u;
assert(filename);
assert(lvalue);
assert(filename);
assert(lvalue);
@@
-1278,12
+1290,15
@@
int config_parse_timer_unit(
return 0;
}
return 0;
}
- if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
+ r = manager_load_unit(UNIT(t)->manager, rvalue, NULL, NULL, &u);
+ if (r < 0) {
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
dbus_error_free(&error);
return 0;
}
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
dbus_error_free(&error);
return 0;
}
+ unit_ref_set(&t->unit, u);
+
return 0;
}
return 0;
}
@@
-1347,6
+1362,7
@@
int config_parse_path_unit(
Path *t = data;
int r;
DBusError error;
Path *t = data;
int r;
DBusError error;
+ Unit *u;
assert(filename);
assert(lvalue);
assert(filename);
assert(lvalue);
@@
-1360,12
+1376,14
@@
int config_parse_path_unit(
return 0;
}
return 0;
}
- if ((r = manager_load_unit(
t->meta.manager, rvalue, NULL, &error, &t->unit
)) < 0) {
+ if ((r = manager_load_unit(
UNIT(t)->manager, rvalue, NULL, &error, &u
)) < 0) {
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
dbus_error_free(&error);
return 0;
}
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
dbus_error_free(&error);
return 0;
}
+ unit_ref_set(&t->unit, u);
+
return 0;
}
return 0;
}
@@
-1382,6
+1400,7
@@
int config_parse_socket_service(
Socket *s = data;
int r;
DBusError error;
Socket *s = data;
int r;
DBusError error;
+ Unit *x;
assert(filename);
assert(lvalue);
assert(filename);
assert(lvalue);
@@
-1395,12
+1414,15
@@
int config_parse_socket_service(
return 0;
}
return 0;
}
- if ((r = manager_load_unit(s->meta.manager, rvalue, NULL, &error, (Unit**) &s->service)) < 0) {
+ r = manager_load_unit(UNIT(s)->manager, rvalue, NULL, &error, &x);
+ if (r < 0) {
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
dbus_error_free(&error);
return 0;
}
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
dbus_error_free(&error);
return 0;
}
+ unit_ref_set(&s->service, x);
+
return 0;
}
return 0;
}
@@
-1416,7
+1438,6
@@
int config_parse_service_sockets(
Service *s = data;
int r;
Service *s = data;
int r;
- DBusError error;
char *state, *w;
size_t l;
char *state, *w;
size_t l;
@@
-1425,35
+1446,34
@@
int config_parse_service_sockets(
assert(rvalue);
assert(data);
assert(rvalue);
assert(data);
- dbus_error_init(&error);
-
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
- char *t;
- Unit *sock;
+ char *t, *k;
- if (!(t = strndup(w, l)))
+ t = strndup(w, l);
+ if (!t)
return -ENOMEM;
return -ENOMEM;
- if (!endswith(t, ".socket")) {
- log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
- free(t);
- continue;
- }
-
- r = manager_load_unit(s->meta.manager, t, NULL, &error, &sock);
+ k = unit_name_printf(UNIT(s), t);
free(t);
free(t);
- if (r < 0) {
- log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
- dbus_error_free(&error);
+ if (!k)
+ return -ENOMEM;
+
+ if (!endswith(k, ".socket")) {
+ log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
+ free(k);
continue;
}
continue;
}
- if ((r = set_ensure_allocated(&s->configured_sockets, trivial_hash_func, trivial_compare_func)) < 0)
- return r;
+ r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, NULL, true);
+ if (r < 0)
+ log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
- if ((r = set_put(s->configured_sockets, sock)) < 0)
+ r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, NULL, true);
+ if (r < 0)
return r;
return r;
+
+ free(k);
}
return 0;
}
return 0;
@@
-1563,7
+1583,7
@@
int config_parse_unit_condition_path(
if (!c)
return -ENOMEM;
if (!c)
return -ENOMEM;
- LIST_PREPEND(Condition, conditions, u->
meta.
conditions, c);
+ LIST_PREPEND(Condition, conditions, u->conditions, c);
return 0;
}
return 0;
}
@@
-1596,7
+1616,7
@@
int config_parse_unit_condition_string(
if (!(c = condition_new(cond, rvalue, trigger, negate)))
return -ENOMEM;
if (!(c = condition_new(cond, rvalue, trigger, negate)))
return -ENOMEM;
- LIST_PREPEND(Condition, conditions, u->
meta.
conditions, c);
+ LIST_PREPEND(Condition, conditions, u->conditions, c);
return 0;
}
return 0;
}
@@
-1637,11
+1657,12
@@
int config_parse_unit_condition_null(
if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
return -ENOMEM;
if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
return -ENOMEM;
- LIST_PREPEND(Condition, conditions, u->
meta.
conditions, c);
+ LIST_PREPEND(Condition, conditions, u->conditions, c);
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
+DEFINE_CONFIG_PARSE_ENUM(config_parse_start_limit_action, start_limit_action, StartLimitAction, "Failed to parse start limit action specifier");
int config_parse_unit_cgroup_attr(
const char *filename,
int config_parse_unit_cgroup_attr(
const char *filename,
@@
-2103,7
+2124,7
@@
static int merge_by_names(Unit **u, Set *names, const char *id) {
* ours? Then let's try it the other way
* round */
* ours? Then let's try it the other way
* round */
- other = manager_get_unit((*u)->m
eta.m
anager, k);
+ other = manager_get_unit((*u)->manager, k);
free(k);
if (other)
free(k);
if (other)
@@
-2157,7
+2178,7
@@
static int load_from_path(Unit *u, const char *path) {
} else {
char **p;
} else {
char **p;
- STRV_FOREACH(p, u->m
eta.m
anager->lookup_paths.unit_path) {
+ STRV_FOREACH(p, u->manager->lookup_paths.unit_path) {
/* Instead of opening the path right away, we manually
* follow all symlinks and add their name to our unit
/* Instead of opening the path right away, we manually
* follow all symlinks and add their name to our unit
@@
-2167,8
+2188,8
@@
static int load_from_path(Unit *u, const char *path) {
goto finish;
}
goto finish;
}
- if (u->m
eta.m
anager->unit_path_cache &&
- !set_get(u->m
eta.m
anager->unit_path_cache, filename))
+ if (u->manager->unit_path_cache &&
+ !set_get(u->manager->unit_path_cache, filename))
r = -ENOENT;
else
r = open_follow(&filename, &f, symlink_names, &id);
r = -ENOENT;
else
r = open_follow(&filename, &f, symlink_names, &id);
@@
-2204,7
+2225,7
@@
static int load_from_path(Unit *u, const char *path) {
goto finish;
if (merged != u) {
goto finish;
if (merged != u) {
- u->
meta.
load_state = UNIT_MERGED;
+ u->load_state = UNIT_MERGED;
r = 0;
goto finish;
}
r = 0;
goto finish;
}
@@
-2216,21
+2237,21
@@
static int load_from_path(Unit *u, const char *path) {
}
if (null_or_empty(&st))
}
if (null_or_empty(&st))
- u->
meta.
load_state = UNIT_MASKED;
+ u->load_state = UNIT_MASKED;
else {
/* Now, parse the file contents */
r = config_parse(filename, f, UNIT_VTABLE(u)->sections, config_item_perf_lookup, (void*) load_fragment_gperf_lookup, false, u);
if (r < 0)
goto finish;
else {
/* Now, parse the file contents */
r = config_parse(filename, f, UNIT_VTABLE(u)->sections, config_item_perf_lookup, (void*) load_fragment_gperf_lookup, false, u);
if (r < 0)
goto finish;
- u->
meta.
load_state = UNIT_LOADED;
+ u->load_state = UNIT_LOADED;
}
}
- free(u->
meta.
fragment_path);
- u->
meta.
fragment_path = filename;
+ free(u->fragment_path);
+ u->fragment_path = filename;
filename = NULL;
filename = NULL;
- u->
meta.
fragment_mtime = timespec_load(&st.st_mtim);
+ u->fragment_mtime = timespec_load(&st.st_mtim);
r = 0;
r = 0;
@@
-2250,49
+2271,49
@@
int unit_load_fragment(Unit *u) {
const char *t;
assert(u);
const char *t;
assert(u);
- assert(u->
meta.
load_state == UNIT_STUB);
- assert(u->
meta.
id);
+ assert(u->load_state == UNIT_STUB);
+ assert(u->id);
/* First, try to find the unit under its id. We always look
* for unit files in the default directories, to make it easy
* to override things by placing things in /etc/systemd/system */
/* First, try to find the unit under its id. We always look
* for unit files in the default directories, to make it easy
* to override things by placing things in /etc/systemd/system */
- if ((r = load_from_path(u, u->
meta.
id)) < 0)
+ if ((r = load_from_path(u, u->id)) < 0)
return r;
/* Try to find an alias we can load this with */
return r;
/* Try to find an alias we can load this with */
- if (u->
meta.
load_state == UNIT_STUB)
- SET_FOREACH(t, u->
meta.
names, i) {
+ if (u->load_state == UNIT_STUB)
+ SET_FOREACH(t, u->names, i) {
- if (t == u->
meta.
id)
+ if (t == u->id)
continue;
if ((r = load_from_path(u, t)) < 0)
return r;
continue;
if ((r = load_from_path(u, t)) < 0)
return r;
- if (u->
meta.
load_state != UNIT_STUB)
+ if (u->load_state != UNIT_STUB)
break;
}
/* And now, try looking for it under the suggested (originally linked) path */
break;
}
/* And now, try looking for it under the suggested (originally linked) path */
- if (u->
meta.load_state == UNIT_STUB && u->meta.
fragment_path) {
+ if (u->
load_state == UNIT_STUB && u->
fragment_path) {
- if ((r = load_from_path(u, u->
meta.
fragment_path)) < 0)
+ if ((r = load_from_path(u, u->fragment_path)) < 0)
return r;
return r;
- if (u->
meta.
load_state == UNIT_STUB) {
+ if (u->load_state == UNIT_STUB) {
/* Hmm, this didn't work? Then let's get rid
* of the fragment path stored for us, so that
* we don't point to an invalid location. */
/* Hmm, this didn't work? Then let's get rid
* of the fragment path stored for us, so that
* we don't point to an invalid location. */
- free(u->
meta.
fragment_path);
- u->
meta.
fragment_path = NULL;
+ free(u->fragment_path);
+ u->fragment_path = NULL;
}
}
/* Look for a template */
}
}
/* Look for a template */
- if (u->
meta.load_state == UNIT_STUB && u->meta.
instance) {
+ if (u->
load_state == UNIT_STUB && u->
instance) {
char *k;
char *k;
- if (!(k = unit_name_template(u->
meta.
id)))
+ if (!(k = unit_name_template(u->id)))
return -ENOMEM;
r = load_from_path(u, k);
return -ENOMEM;
r = load_from_path(u, k);
@@
-2301,10
+2322,10
@@
int unit_load_fragment(Unit *u) {
if (r < 0)
return r;
if (r < 0)
return r;
- if (u->
meta.
load_state == UNIT_STUB)
- SET_FOREACH(t, u->
meta.
names, i) {
+ if (u->load_state == UNIT_STUB)
+ SET_FOREACH(t, u->names, i) {
- if (t == u->
meta.
id)
+ if (t == u->id)
continue;
if (!(k = unit_name_template(t)))
continue;
if (!(k = unit_name_template(t)))
@@
-2316,7
+2337,7
@@
int unit_load_fragment(Unit *u) {
if (r < 0)
return r;
if (r < 0)
return r;
- if (u->
meta.
load_state != UNIT_STUB)
+ if (u->load_state != UNIT_STUB)
break;
}
}
break;
}
}
@@
-2331,7
+2352,7
@@
void unit_dump_config_items(FILE *f) {
} table[] = {
{ config_parse_int, "INTEGER" },
{ config_parse_unsigned, "UNSIGNED" },
} table[] = {
{ config_parse_int, "INTEGER" },
{ config_parse_unsigned, "UNSIGNED" },
- { config_parse_
size,
"SIZE" },
+ { config_parse_
bytes_size,
"SIZE" },
{ config_parse_bool, "BOOLEAN" },
{ config_parse_string, "STRING" },
{ config_parse_path, "PATH" },
{ config_parse_bool, "BOOLEAN" },
{ config_parse_string, "STRING" },
{ config_parse_path, "PATH" },