1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 10:25:37 +03:00

Merge pull request #7983 from poettering/tmpfiles-eexist

make "f" tmpfiles.d behaviour work like documentation suggests + coccinelle fixes
This commit is contained in:
Lennart Poettering 2018-01-25 11:34:15 +01:00 committed by GitHub
commit 7a466dc453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 44 additions and 29 deletions

12
NEWS
View File

@ -7,6 +7,18 @@ CHANGES WITH 237 in spe:
keycodes are not recognized by any major desktop. They now produce keycodes are not recognized by any major desktop. They now produce
Up/Down key events so that they can be used for scrolling. Up/Down key events so that they can be used for scrolling.
* INCOMPATIBILITY: systemd-tmpfiles' "f" lines changed behaviour
slightly: previously, if an argument was specified for lines of this
type (i.e. the right-most column was set) this string was appended to
existing files each time systemd-tmpfiles was run. This behaviour was
different from what the documentation said, and not particularly
useful, as repeated systemd-tmpfiles invocations would not be
idempotent and grow such files without bounds. With this release
behaviour has been altered slightly, to match what the documentation
says: lines of this type only have an effect if the indicated files
don't exist yet, and only then the argument string is written to the
file.
— Berlin, 2018-XX-XX — Berlin, 2018-XX-XX
CHANGES WITH 236: CHANGES WITH 236:

4
coccinelle/o-ndelay.occi Normal file
View File

@ -0,0 +1,4 @@
@@
@@
- O_NDELAY
+ O_NONBLOCK

View File

@ -147,9 +147,8 @@ L /tmp/foobar - - - - /dev/null</programlisting>
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><varname>f</varname></term> <term><varname>f</varname></term>
<listitem><para>Create a file if it does not exist yet. If <listitem><para>Create a file if it does not exist yet. If the argument parameter is given and the file did
the argument parameter is given, it will be written to the not exist yet, it will be written to the file. Does not follow symlinks.</para></listitem>
file. Does not follow symlinks.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -585,21 +584,14 @@ r! /tmp/.X[0-9]*-lock</programlisting>
<refsect2> <refsect2>
<title>Argument</title> <title>Argument</title>
<para>For <varname>L</varname> lines determines the destination <para>For <varname>L</varname> lines determines the destination path of the symlink. For <varname>c</varname> and
path of the symlink. For <varname>c</varname> and <varname>b</varname>, determines the major/minor of the device node, with major and minor formatted as integers,
<varname>b</varname>, determines the major/minor of the device separated by <literal>:</literal>, e.g. <literal>1:3</literal>. For <varname>f</varname>, <varname>F</varname>,
node, with major and minor formatted as integers, separated by and <varname>w</varname>, the argument may be used to specify a short string that is written to the file,
<literal>:</literal>, e.g. <literal>1:3</literal>. For suffixed by a newline. For <varname>C</varname>, specifies the source file or directory. For <varname>t</varname>
<varname>f</varname>, <varname>F</varname>, and and <varname>T</varname>, determines extended attributes to be set. For <varname>a</varname> and
<varname>w</varname>, the argument may be used to specify a short string that <varname>A</varname>, determines ACL attributes to be set. For <varname>h</varname> and <varname>H</varname>,
is written to the file, suffixed by a newline. For determines the file attributes to set. Ignored for all other lines.</para>
<varname>C</varname>, specifies the source file or
directory. For <varname>t</varname> and <varname>T</varname>,
determines extended attributes to be set. For
<varname>a</varname> and <varname>A</varname>, determines ACL
attributes to be set. For <varname>h</varname> and
<varname>H</varname>, determines the file attributes to
set. Ignored for all other lines.</para>
<para>This field can contain specifiers, see below.</para> <para>This field can contain specifiers, see below.</para>
</refsect2> </refsect2>

View File

@ -1497,7 +1497,8 @@ static int server_open_hostname(Server *s) {
assert(s); assert(s);
s->hostname_fd = open("/proc/sys/kernel/hostname", O_RDONLY|O_CLOEXEC|O_NDELAY|O_NOCTTY); s->hostname_fd = open("/proc/sys/kernel/hostname",
O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (s->hostname_fd < 0) if (s->hostname_fd < 0)
return log_error_errno(errno, "Failed to open /proc/sys/kernel/hostname: %m"); return log_error_errno(errno, "Failed to open /proc/sys/kernel/hostname: %m");

View File

@ -305,7 +305,7 @@ int inhibitor_create_fifo(Inhibitor *i) {
/* Open reading side */ /* Open reading side */
if (i->fifo_fd < 0) { if (i->fifo_fd < 0) {
i->fifo_fd = open(i->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY); i->fifo_fd = open(i->fifo_path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
if (i->fifo_fd < 0) if (i->fifo_fd < 0)
return -errno; return -errno;
} }
@ -321,7 +321,7 @@ int inhibitor_create_fifo(Inhibitor *i) {
} }
/* Open writing side */ /* Open writing side */
r = open(i->fifo_path, O_WRONLY|O_CLOEXEC|O_NDELAY); r = open(i->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK);
if (r < 0) if (r < 0)
return -errno; return -errno;

View File

@ -962,7 +962,7 @@ int session_create_fifo(Session *s) {
/* Open reading side */ /* Open reading side */
if (s->fifo_fd < 0) { if (s->fifo_fd < 0) {
s->fifo_fd = open(s->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY); s->fifo_fd = open(s->fifo_path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
if (s->fifo_fd < 0) if (s->fifo_fd < 0)
return -errno; return -errno;
@ -981,7 +981,7 @@ int session_create_fifo(Session *s) {
} }
/* Open writing side */ /* Open writing side */
r = open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NDELAY); r = open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NONBLOCK);
if (r < 0) if (r < 0)
return -errno; return -errno;

View File

@ -488,7 +488,8 @@ static int manager_watch_hostname(Manager *m) {
assert(m); assert(m);
m->hostname_fd = open("/proc/sys/kernel/hostname", O_RDONLY|O_CLOEXEC|O_NDELAY|O_NOCTTY); m->hostname_fd = open("/proc/sys/kernel/hostname",
O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (m->hostname_fd < 0) { if (m->hostname_fd < 0) {
log_warning_errno(errno, "Failed to watch hostname: %m"); log_warning_errno(errno, "Failed to watch hostname: %m");
return 0; return 0;

View File

@ -1382,7 +1382,7 @@ static int bus_append_socket_property(sd_bus_message *m, const char *field, cons
if (isempty(eq)) if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "Listen", "a(ss)", 0); r = sd_bus_message_append(m, "(sv)", "Listen", "a(ss)", 0);
else else
r = sd_bus_message_append(m, "(sv)", "Listen", "a(ss)", 1, field + strlen("Listen"), eq); r = sd_bus_message_append(m, "(sv)", "Listen", "a(ss)", 1, field + STRLEN("Listen"), eq);
if (r < 0) if (r < 0)
return bus_log_create_error(r); return bus_log_create_error(r);

View File

@ -330,7 +330,7 @@ static int write_to_terminal(const char *tty, const char *message) {
assert(tty); assert(tty);
assert(message); assert(message);
fd = open(tty, O_WRONLY|O_NDELAY|O_NOCTTY|O_CLOEXEC); fd = open(tty, O_WRONLY|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
if (fd < 0 || !isatty(fd)) if (fd < 0 || !isatty(fd))
return -errno; return -errno;

View File

@ -8352,7 +8352,7 @@ static int talk_initctl(void) {
request.runlevel = rl; request.runlevel = rl;
fd = open(INIT_FIFO, O_WRONLY|O_NDELAY|O_CLOEXEC|O_NOCTTY); fd = open(INIT_FIFO, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
if (fd < 0) { if (fd < 0) {
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;

View File

@ -1189,7 +1189,7 @@ static int write_one_file(Item *i, const char *path) {
assert(i); assert(i);
assert(path); assert(path);
flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND|O_NOFOLLOW : flags = i->type == CREATE_FILE ? O_CREAT|O_EXCL|O_NOFOLLOW :
i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC|O_NOFOLLOW : 0; i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC|O_NOFOLLOW : 0;
RUN_WITH_UMASK(0000) { RUN_WITH_UMASK(0000) {
@ -1200,9 +1200,13 @@ static int write_one_file(Item *i, const char *path) {
if (fd < 0) { if (fd < 0) {
if (i->type == WRITE_FILE && errno == ENOENT) { if (i->type == WRITE_FILE && errno == ENOENT) {
log_debug_errno(errno, "Not writing \"%s\": %m", path); log_debug_errno(errno, "Not writing missing file \"%s\": %m", path);
return 0; return 0;
} }
if (i->type == CREATE_FILE && errno == EEXIST) {
log_debug_errno(errno, "Not writing to pre-existing file \"%s\": %m", path);
goto done;
}
r = -errno; r = -errno;
if (!i->argument && errno == EROFS && stat(path, &st) == 0 && if (!i->argument && errno == EROFS && stat(path, &st) == 0 &&
@ -1223,6 +1227,7 @@ static int write_one_file(Item *i, const char *path) {
fd = safe_close(fd); fd = safe_close(fd);
done:
if (stat(path, &st) < 0) if (stat(path, &st) < 0)
return log_error_errno(errno, "stat(%s) failed: %m", path); return log_error_errno(errno, "stat(%s) failed: %m", path);