tmpfiles: port to unquote_many_words()

This commit is contained in:
daurnimator 2015-03-09 15:11:44 -04:00 committed by Lennart Poettering
parent cb81cd8073
commit 657cf7f4f8
3 changed files with 9 additions and 16 deletions

2
TODO
View File

@ -232,8 +232,6 @@ Features:
* exponential backoff in timesyncd and resolved when we cannot reach a server * exponential backoff in timesyncd and resolved when we cannot reach a server
* tmpfiles: port to unquote_many_words(), similar to sysusers
* unquote_many_words() should probably be used by a lot of code that * unquote_many_words() should probably be used by a lot of code that
currently uses FOREACH_WORD and friends. For example, most conf currently uses FOREACH_WORD and friends. For example, most conf
parsing callbacks should use it. parsing callbacks should use it.

View File

@ -118,6 +118,8 @@
d /run/user 0755 root root 10d - d /run/user 0755 root root 10d -
L /tmp/foobar - - - - /dev/null</programlisting> L /tmp/foobar - - - - /dev/null</programlisting>
<para>Fields may be enclosed within quotes and contain C-style escapes.</para>
<refsect2> <refsect2>
<title>Type</title> <title>Type</title>

View File

@ -1506,23 +1506,25 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
_cleanup_(item_free_contents) Item i = {}; _cleanup_(item_free_contents) Item i = {};
ItemArray *existing; ItemArray *existing;
Hashmap *h; Hashmap *h;
int r, c = -1, pos; int r, pos;
bool force = false, boot = false; bool force = false, boot = false;
assert(fname); assert(fname);
assert(line >= 1); assert(line >= 1);
assert(buffer); assert(buffer);
r = sscanf(buffer, r = unquote_many_words(&buffer,
"%ms %ms %ms %ms %ms %ms %n",
&action, &action,
&path, &path,
&mode, &mode,
&user, &user,
&group, &group,
&age, &age,
&c); &i.argument,
if (r < 2) { NULL);
if (r < 0)
return log_error_errno(r, "[%s:%u] Failed to parse line: %m", fname, line);
else if (r < 2) {
log_error("[%s:%u] Syntax error.", fname, line); log_error("[%s:%u] Syntax error.", fname, line);
return -EIO; return -EIO;
} }
@ -1559,15 +1561,6 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
return r; return r;
} }
if (c >= 0) {
c += strspn(buffer+c, WHITESPACE);
if (buffer[c] != 0 && (buffer[c] != '-' || buffer[c+1] != 0)) {
i.argument = unquote(buffer+c, "\"");
if (!i.argument)
return log_oom();
}
}
switch (i.type) { switch (i.type) {
case CREATE_FILE: case CREATE_FILE: