summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/calendarspec.c8
-rw-r--r--src/basic/fileio.c10
-rw-r--r--src/basic/unit-name.c9
-rw-r--r--src/boot/bootctl.c8
-rw-r--r--src/boot/efi/boot.c28
-rw-r--r--src/boot/efi/disk.c51
-rw-r--r--src/boot/efi/disk.h21
-rw-r--r--src/boot/efi/stub.c6
-rw-r--r--src/core/dbus-manager.c7
-rw-r--r--src/core/manager.c13
-rw-r--r--src/firstboot/firstboot.c26
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c39
-rw-r--r--src/journal-remote/journal-upload.c23
-rw-r--r--src/journal/catalog.c12
-rw-r--r--src/journal/journald-stream.c26
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c31
-rw-r--r--src/libsystemd-network/sd-lldp.c64
-rw-r--r--src/libsystemd/sd-bus/bus-dump.c7
-rw-r--r--src/libsystemd/sd-bus/bus-introspect.c10
-rw-r--r--src/libsystemd/sd-bus/bus-match.c5
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c7
-rw-r--r--src/libsystemd/sd-device/device-private.c8
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c18
-rw-r--r--src/libsystemd/sd-netlink/netlink-types.c38
-rw-r--r--src/libsystemd/sd-netlink/netlink-types.h1
-rw-r--r--src/locale/localed.c24
-rw-r--r--src/login/loginctl.c8
-rw-r--r--src/login/logind-dbus.c19
-rw-r--r--src/login/logind-inhibit.c25
-rw-r--r--src/login/logind-seat.c25
-rw-r--r--src/login/logind-session.c34
-rw-r--r--src/login/logind-user.c25
-rw-r--r--src/machine/machine.c32
-rw-r--r--src/network/networkd-link.c12
-rw-r--r--src/network/networkd-manager.c8
-rw-r--r--src/network/networkd-netdev-gperf.gperf1
-rw-r--r--src/network/networkd-netdev-tunnel.c12
-rw-r--r--src/network/networkd-netdev-tunnel.h5
-rw-r--r--src/network/networkd-netdev-vxlan.c8
-rw-r--r--src/network/networkd-netdev-vxlan.h1
-rw-r--r--src/network/networkd-wait-online-manager.c8
-rw-r--r--src/nspawn/nspawn.c5
-rw-r--r--src/run/run.c8
-rw-r--r--src/shared/ask-password-api.c8
-rw-r--r--src/systemd/sd-netlink.h1
-rw-r--r--src/sysusers/sysusers.c11
-rw-r--r--src/udev/udev-rules.c3
47 files changed, 432 insertions, 327 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c
index 2fde3e107e..2dcc9c5575 100644
--- a/src/basic/calendarspec.c
+++ b/src/basic/calendarspec.c
@@ -253,6 +253,7 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
char *buf = NULL;
size_t sz = 0;
FILE *f;
+ int r;
assert(c);
assert(p);
@@ -278,12 +279,11 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
fputc(':', f);
format_chain(f, 2, c->second);
- fflush(f);
-
- if (ferror(f)) {
+ r = fflush_and_check(f);
+ if (r < 0) {
free(buf);
fclose(f);
- return -ENOMEM;
+ return r;
}
fclose(f);
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 2216853777..4a9105f421 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -28,21 +28,15 @@
#include "fileio.h"
int write_string_stream(FILE *f, const char *line, bool enforce_newline) {
+
assert(f);
assert(line);
- errno = 0;
-
fputs(line, f);
if (enforce_newline && !endswith(line, "\n"))
fputc('\n', f);
- fflush(f);
-
- if (ferror(f))
- return errno ? -errno : -EIO;
-
- return 0;
+ return fflush_and_check(f);
}
static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline) {
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index bf52463d81..4b84542d0c 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -673,6 +673,7 @@ int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, c
int slice_build_parent_slice(const char *slice, char **ret) {
char *s, *dash;
+ int r;
assert(slice);
assert(ret);
@@ -693,11 +694,9 @@ int slice_build_parent_slice(const char *slice, char **ret) {
if (dash)
strcpy(dash, ".slice");
else {
- free(s);
-
- s = strdup("-.slice");
- if (!s)
- return -ENOMEM;
+ r = free_and_strdup(&s, "-.slice");
+ if (r < 0)
+ return r;
}
*ret = s;
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 091ea375d3..359fde9998 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -489,9 +489,9 @@ static int copy_file(const char *from, const char *to, bool force) {
}
} while (!feof(f));
- fflush(g);
- if (ferror(g)) {
- r = log_error_errno(EIO, "Failed to write \"%s\": %m", to);
+ r = fflush_and_check(g);
+ if (r < 0) {
+ log_error_errno(r, "Failed to write \"%s\": %m", to);
goto error;
}
@@ -519,7 +519,7 @@ static int copy_file(const char *from, const char *to, bool force) {
return 0;
error:
- unlink(p);
+ (void) unlink(p);
return r;
}
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index e8cd8abd26..dde0c41744 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -22,6 +22,7 @@
#include "console.h"
#include "graphics.h"
#include "pefile.h"
+#include "disk.h"
#include "linux.h"
#ifndef EFI_OS_INDICATIONS_BOOT_TO_FW_UI
@@ -1696,11 +1697,11 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
EFI_LOADED_IMAGE *loaded_image;
EFI_FILE *root_dir;
CHAR16 *loaded_image_path;
- EFI_DEVICE_PATH *device_path;
EFI_STATUS err;
Config config;
UINT64 init_usec;
BOOLEAN menu = FALSE;
+ CHAR16 uuid[37];
InitializeLib(image, sys_table);
init_usec = time_usec();
@@ -1722,29 +1723,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
}
/* export the device path this image is started from */
- device_path = DevicePathFromHandle(loaded_image->DeviceHandle);
- if (device_path) {
- EFI_DEVICE_PATH *path, *paths;
-
- paths = UnpackDevicePath(device_path);
- for (path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
- HARDDRIVE_DEVICE_PATH *drive;
- CHAR16 uuid[37];
-
- if (DevicePathType(path) != MEDIA_DEVICE_PATH)
- continue;
- if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
- continue;
- drive = (HARDDRIVE_DEVICE_PATH *)path;
- if (drive->SignatureType != SIGNATURE_TYPE_GUID)
- continue;
-
- GuidToString(uuid, (EFI_GUID *)&drive->Signature);
- efivar_set(L"LoaderDevicePartUUID", uuid, FALSE);
- break;
- }
- FreePool(paths);
- }
+ if (disk_get_part_uuid(loaded_image->DeviceHandle, uuid) == EFI_SUCCESS)
+ efivar_set(L"LoaderDevicePartUUID", uuid, FALSE);
root_dir = LibOpenRoot(loaded_image->DeviceHandle);
if (!root_dir) {
diff --git a/src/boot/efi/disk.c b/src/boot/efi/disk.c
new file mode 100644
index 0000000000..96063fbc28
--- /dev/null
+++ b/src/boot/efi/disk.c
@@ -0,0 +1,51 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2015 Kay Sievers <kay@vrfy.org>
+ */
+
+#include <efi.h>
+#include <efilib.h>
+
+#include "util.h"
+
+EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[37]) {
+ EFI_DEVICE_PATH *device_path;
+ EFI_STATUS r = EFI_NOT_FOUND;
+
+ /* export the device path this image is started from */
+ device_path = DevicePathFromHandle(handle);
+ if (device_path) {
+ EFI_DEVICE_PATH *path, *paths;
+
+ paths = UnpackDevicePath(device_path);
+ for (path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
+ HARDDRIVE_DEVICE_PATH *drive;
+
+ if (DevicePathType(path) != MEDIA_DEVICE_PATH)
+ continue;
+ if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
+ continue;
+ drive = (HARDDRIVE_DEVICE_PATH *)path;
+ if (drive->SignatureType != SIGNATURE_TYPE_GUID)
+ continue;
+
+ GuidToString(uuid, (EFI_GUID *)&drive->Signature);
+ r = EFI_SUCCESS;
+ break;
+ }
+ FreePool(paths);
+ }
+
+ return r;
+}
diff --git a/src/boot/efi/disk.h b/src/boot/efi/disk.h
new file mode 100644
index 0000000000..1b25343a00
--- /dev/null
+++ b/src/boot/efi/disk.h
@@ -0,0 +1,21 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2015 Kay Sievers <kay@vrfy.org>
+ */
+
+#ifndef __SDBOOT_DISK_H
+#define __SDBOOT_DISK_H
+
+EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[37]);
+#endif
diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c
index 0b1bc491ed..0c5ee4e9ff 100644
--- a/src/boot/efi/stub.c
+++ b/src/boot/efi/stub.c
@@ -18,6 +18,7 @@
#include "util.h"
#include "pefile.h"
+#include "disk.h"
#include "graphics.h"
#include "splash.h"
#include "linux.h"
@@ -46,6 +47,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
UINTN szs[ELEMENTSOF(sections)-1] = {};
CHAR8 *cmdline = NULL;
UINTN cmdline_len;
+ CHAR16 uuid[37];
EFI_STATUS err;
InitializeLib(image, sys_table);
@@ -99,6 +101,10 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
cmdline = line;
}
+ /* export the device path this image is started from */
+ if (disk_get_part_uuid(loaded_image->DeviceHandle, uuid) == EFI_SUCCESS)
+ efivar_set(L"LoaderDevicePartUUID", uuid, FALSE);
+
if (szs[3] > 0)
graphics_splash((UINT8 *)((UINTN)loaded_image->ImageBase + addrs[3]), szs[3], NULL);
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index d8b39bdf5f..5722e3c2bb 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1069,10 +1069,9 @@ static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *er
manager_dump_units(m, f, NULL);
manager_dump_jobs(m, f, NULL);
- fflush(f);
-
- if (ferror(f))
- return -ENOMEM;
+ r = fflush_and_check(f);
+ if (r < 0)
+ return r;
return sd_bus_reply_method_return(message, "s", dump);
}
diff --git a/src/core/manager.c b/src/core/manager.c
index a1f37bbbb3..ba107d4615 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1701,6 +1701,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
ssize_t n;
struct signalfd_siginfo sfsi;
bool sigchld = false;
+ int r;
assert(m);
assert(m->signal_fd == fd);
@@ -1809,20 +1810,16 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
f = open_memstream(&dump, &size);
if (!f) {
- log_warning("Failed to allocate memory stream.");
+ log_warning_errno(errno, "Failed to allocate memory stream: %m");
break;
}
manager_dump_units(m, f, "\t");
manager_dump_jobs(m, f, "\t");
- if (ferror(f)) {
- log_warning("Failed to write status stream");
- break;
- }
-
- if (fflush(f)) {
- log_warning("Failed to flush status stream");
+ r = fflush_and_check(f);
+ if (r < 0) {
+ log_warning_errno(r, "Failed to write status stream: %m");
break;
}
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 3805b29437..f06ab3da29 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -728,9 +728,8 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- free(arg_locale);
- arg_locale = strdup(optarg);
- if (!arg_locale)
+ r = free_and_strdup(&arg_locale, optarg);
+ if (r < 0)
return log_oom();
break;
@@ -741,9 +740,8 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- free(arg_locale_messages);
- arg_locale_messages = strdup(optarg);
- if (!arg_locale_messages)
+ r = free_and_strdup(&arg_locale_messages, optarg);
+ if (r < 0)
return log_oom();
break;
@@ -754,19 +752,16 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- free(arg_timezone);
- arg_timezone = strdup(optarg);
- if (!arg_timezone)
+ r = free_and_strdup(&arg_timezone, optarg);
+ if (r < 0)
return log_oom();
break;
case ARG_ROOT_PASSWORD:
- free(arg_root_password);
- arg_root_password = strdup(optarg);
- if (!arg_root_password)
+ r = free_and_strdup(&arg_root_password, optarg);
+ if (r < 0)
return log_oom();
-
break;
case ARG_ROOT_PASSWORD_FILE:
@@ -785,9 +780,8 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- free(arg_hostname);
- arg_hostname = strdup(optarg);
- if (!arg_hostname)
+ r = free_and_strdup(&arg_hostname, optarg);
+ if (r < 0)
return log_oom();
break;
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 22dfd5496d..50acb7595c 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -97,9 +97,9 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
id, what, rw ? "" : "read-only",
id);
- fflush(f);
- if (ferror(f))
- return log_error_errno(errno, "Failed to write file %s: %m", p);
+ r = fflush_and_check(f);
+ if (r < 0)
+ return log_error_errno(r, "Failed to write file %s: %m", p);
from = strjoina("../", n);
@@ -223,9 +223,9 @@ static int add_mount(
else
fprintf(f, "Options=%s\n", rw ? "rw" : "ro");
- fflush(f);
- if (ferror(f))
- return log_error_errno(errno, "Failed to write unit file %s: %m", p);
+ r = fflush_and_check(f);
+ if (r < 0)
+ return log_error_errno(r, "Failed to write unit file %s: %m", p);
if (post) {
lnk = strjoin(arg_dest, "/", post, ".requires/", unit, NULL);
@@ -301,9 +301,9 @@ static int add_automount(
where,
(unsigned long long)timeout / USEC_PER_SEC);
- fflush(f);
- if (ferror(f))
- return log_error_errno(errno, "Failed to write unit file %s: %m", p);
+ r = fflush_and_check(f);
+ if (r < 0)
+ return log_error_errno(r, "Failed to write unit file %s: %m", p);
lnk = strjoin(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/", unit, NULL);
if (!lnk)
@@ -426,9 +426,9 @@ static int add_swap(const char *path) {
"What=%s\n",
path);
- fflush(f);
- if (ferror(f))
- return log_error_errno(errno, "Failed to write unit file %s: %m", unit);
+ r = fflush_and_check(f);
+ if (r < 0)
+ return log_error_errno(r, "Failed to write unit file %s: %m", unit);
lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
if (!lnk)
@@ -727,9 +727,8 @@ static int enumerate_partitions(dev_t devnum) {
boot_nr = nr;
- free(boot);
- boot = strdup(subnode);
- if (!boot)
+ r = free_and_strdup(&boot, subnode);
+ if (r < 0)
return log_oom();
} else if (sd_id128_equal(type_id, GPT_HOME)) {
@@ -741,9 +740,8 @@ static int enumerate_partitions(dev_t devnum) {
home_nr = nr;
home_rw = !(flags & GPT_FLAG_READ_ONLY),
- free(home);
- home = strdup(subnode);
- if (!home)
+ r = free_and_strdup(&home, subnode);
+ if (r < 0)
return log_oom();
} else if (sd_id128_equal(type_id, GPT_SRV)) {
@@ -755,9 +753,8 @@ static int enumerate_partitions(dev_t devnum) {
srv_nr = nr;
srv_rw = !(flags & GPT_FLAG_READ_ONLY),
- free(srv);
- srv = strdup(subnode);
- if (!srv)
+ r = free_and_strdup(&srv, subnode);
+ if (r < 0)
return log_oom();
}
}
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index 5d23639ee8..172fd80a12 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -126,26 +126,31 @@ static int update_cursor_state(Uploader *u) {
r = fopen_temporary(u->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fprintf(f,
"# This is private data. Do not parse.\n"
"LAST_CURSOR=%s\n",
u->last_cursor);
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, u->state_file) < 0) {
+ if (rename(temp_path, u->state_file) < 0) {
r = -errno;
- unlink(u->state_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_errno(r, "Failed to save state %s: %m", u->state_file);
+ return 0;
- return r;
+fail:
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ (void) unlink(u->state_file);
+
+ return log_error_errno(r, "Failed to save state %s: %m", u->state_file);
}
static int load_cursor_state(Uploader *u) {
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index 0801e13599..33b0539315 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -371,25 +371,23 @@ static long write_catalog(const char *database, Hashmap *h, struct strbuf *sb,
goto error;
}
- fflush(w);
-
- if (ferror(w)) {
- log_error("%s: failed to write database.", p);
+ r = fflush_and_check(w);
+ if (r < 0) {
+ log_error_errno(r, "%s: failed to write database: %m", p);
goto error;
}
fchmod(fileno(w), 0644);
if (rename(p, database) < 0) {
- log_error_errno(errno, "rename (%s -> %s) failed: %m", p, database);
- r = -errno;
+ r = log_error_errno(errno, "rename (%s -> %s) failed: %m", p, database);
goto error;
}
return ftell(w);
error:
- unlink(p);
+ (void) unlink(p);
return r;
}
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index db2f581972..69e2d41863 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -142,7 +142,7 @@ static int stdout_stream_save(StdoutStream *s) {
r = fopen_temporary(s->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fprintf(f,
"# This is private data. Do not parse\n"
@@ -163,7 +163,7 @@ static int stdout_stream_save(StdoutStream *s) {
escaped = cescape(s->identifier);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "IDENTIFIER=%s\n", escaped);
@@ -175,7 +175,7 @@ static int stdout_stream_save(StdoutStream *s) {
escaped = cescape(s->unit_id);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "UNIT=%s\n", escaped);
@@ -183,16 +183,13 @@ static int stdout_stream_save(StdoutStream *s) {
r = fflush_and_check(f);
if (r < 0)
- goto finish;
+ goto fail;
if (rename(temp_path, s->state_file) < 0) {
r = -errno;
- goto finish;
+ goto fail;
}
- free(temp_path);
- temp_path = NULL;
-
/* Store the connection fd in PID 1, so that we get it passed
* in again on next start */
if (!s->fdstore) {
@@ -200,14 +197,15 @@ static int stdout_stream_save(StdoutStream *s) {
s->fdstore = true;
}
-finish:
- if (temp_path)
- unlink(temp_path);
+ return 0;
- if (r < 0)
- log_error_errno(r, "Failed to save stream data %s: %m", s->state_file);
+fail:
+ (void) unlink(s->state_file);
+
+ if (temp_path)
+ (void) unlink(temp_path);
- return r;
+ return log_error_errno(r, "Failed to save stream data %s: %m", s->state_file);
}
static int stdout_stream_log(StdoutStream *s, const char *p) {
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 54417b3af3..febf9f87f3 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -643,13 +643,13 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
r = fopen_temporary(lease_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fchmod(fileno(f), 0644);
r = sd_dhcp_lease_get_address(lease, &address);
if (r < 0)
- goto finish;
+ goto fail;
fprintf(f,
"# This is private data. Do not parse.\n"
@@ -657,7 +657,7 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
r = sd_dhcp_lease_get_netmask(lease, &address);
if (r < 0)
- goto finish;
+ goto fail;
fprintf(f, "NETMASK=%s\n", inet_ntoa(address));
@@ -713,7 +713,7 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
client_id_hex = hexmem(client_id, client_id_len);
if (!client_id_hex) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "CLIENTID=%s\n", client_id_hex);
}
@@ -725,26 +725,27 @@ int sd_dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
option_hex = hexmem(data, data_len);
if (!option_hex) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "VENDOR_SPECIFIC=%s\n", option_hex);
}
- r = 0;
-
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, lease_file) < 0) {
+ if (rename(temp_path, lease_file) < 0) {
r = -errno;
- unlink(lease_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_errno(r, "Failed to save lease data %s: %m", lease_file);
+ return 0;
+
+fail:
+ if (temp_path)
+ (void) unlink(temp_path);
- return r;
+ return log_error_errno(r, "Failed to save lease data %s: %m", lease_file);
}
int sd_dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c
index 6a2c05185d..034163eb9e 100644
--- a/src/libsystemd-network/sd-lldp.c
+++ b/src/libsystemd-network/sd-lldp.c
@@ -440,7 +440,7 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
r = fopen_temporary(lldp_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fchmod(fileno(f), 0644);
@@ -457,8 +457,10 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
s = strdup(buf);
- if (!s)
- return -ENOMEM;
+ if (!s) {
+ r = -ENOMEM;
+ goto fail;
+ }
r = lldp_read_port_id(p->packet, &type, &length, &port_id);
if (r < 0)
@@ -466,8 +468,10 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
if (type != LLDP_PORT_SUBTYPE_MAC_ADDRESS) {
k = strndup((char *) port_id, length -1);
- if (!k)
- return -ENOMEM;
+ if (!k) {
+ r = -ENOMEM;
+ goto fail;
+ }
sprintf(buf, "'_Port=%s' '_PType=%d' ", k , type);
free(k);
@@ -478,8 +482,10 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
}
k = strappend(s, buf);
- if (!k)
- return -ENOMEM;
+ if (!k) {
+ r = -ENOMEM;
+ goto fail;
+ }
free(s);
s = k;
@@ -493,8 +499,10 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
sprintf(buf, "'_TTL="USEC_FMT"' ", p->until);
k = strappend(s, buf);
- if (!k)
- return -ENOMEM;
+ if (!k) {
+ r = -ENOMEM;
+ goto fail;
+ }
free(s);
s = k;
@@ -504,15 +512,19 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
k = strappend(s, "'_NAME=N/A' ");
else {
t = strndup(k, length);
- if (!t)
- return -ENOMEM;
+ if (!t) {
+ r = -ENOMEM;
+ goto fail;
+ }
k = strjoin(s, "'_NAME=", t, "' ", NULL);
free(t);
}
- if (!k)
- return -ENOMEM;
+ if (!k) {
+ r = -ENOMEM;
+ goto fail;
+ }
free(s);
s = k;
@@ -522,8 +534,10 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
sprintf(buf, "'_CAP=%x'", data);
k = strappend(s, buf);
- if (!k)
- return -ENOMEM;
+ if (!k) {
+ r = -ENOMEM;
+ goto fail;
+ }
free(s);
s = k;
@@ -531,21 +545,23 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
fprintf(f, "%s\n", s);
}
}
- r = 0;
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, lldp_file) < 0) {
+ if (rename(temp_path, lldp_file) < 0) {
r = -errno;
- unlink(lldp_file);
- unlink(temp_path);
+ goto fail;
}
- finish:
- if (r < 0)
- log_error("Failed to save lldp data %s: %s", lldp_file, strerror(-r));
+ return 0;
+
+ fail:
+ if (temp_path)
+ (void) unlink(temp_path);
- return r;
+ return log_error_errno(r, "Failed to save lldp data %s: %m", lldp_file);
}
int sd_lldp_start(sd_lldp *lldp) {
diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c
index 9db86adb7f..a6b05eb88d 100644
--- a/src/libsystemd/sd-bus/bus-dump.c
+++ b/src/libsystemd/sd-bus/bus-dump.c
@@ -551,9 +551,8 @@ int bus_pcap_header(size_t snaplen, FILE *f) {
hdr.snaplen = (uint32_t) snaplen;
fwrite(&hdr, 1, sizeof(hdr), f);
- fflush(f);
- return 0;
+ return fflush_and_check(f);
}
int bus_message_pcap_frame(sd_bus_message *m, size_t snaplen, FILE *f) {
@@ -598,7 +597,5 @@ int bus_message_pcap_frame(sd_bus_message *m, size_t snaplen, FILE *f) {
snaplen -= w;
}
- fflush(f);
-
- return 0;
+ return fflush_and_check(f);
}
diff --git a/src/libsystemd/sd-bus/bus-introspect.c b/src/libsystemd/sd-bus/bus-introspect.c
index e2f4550c7e..c2233d0cf3 100644
--- a/src/libsystemd/sd-bus/bus-introspect.c
+++ b/src/libsystemd/sd-bus/bus-introspect.c
@@ -179,10 +179,10 @@ int introspect_finish(struct introspect *i, sd_bus *bus, sd_bus_message *m, sd_b
assert(reply);
fputs("</node>\n", i->f);
- fflush(i->f);
- if (ferror(i->f))
- return -ENOMEM;
+ r = fflush_and_check(i->f);
+ if (r < 0)
+ return r;
r = sd_bus_message_new_method_return(m, &q);
if (r < 0)
@@ -204,8 +204,6 @@ void introspect_free(struct introspect *i) {
if (i->f)
fclose(i->f);
- if (i->introspection)
- free(i->introspection);
-
+ free(i->introspection);
zero(*i);
}
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index 132b37526e..e4cbd793ed 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -914,6 +914,7 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com
char *buffer = NULL;
size_t size = 0;
unsigned i;
+ int r;
if (n_components <= 0)
return strdup("");
@@ -942,8 +943,8 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com
fputc('\'', f);
}
- fflush(f);
- if (ferror(f))
+ r = fflush_and_check(f);
+ if (r < 0)
return NULL;
return buffer;
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 0ca225c617..767df40e81 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -896,10 +896,9 @@ static int parse_container_kernel_address(sd_bus *b, const char **p, char **guid
} else
b->nspid = 0;
- free(b->kernel);
- b->kernel = strdup("/sys/fs/kdbus/0-system/bus");
- if (!b->kernel)
- return -ENOMEM;
+ r = free_and_strdup(&b->kernel, "/sys/fs/kdbus/0-system/bus");
+ if (r < 0)
+ return r;
return 0;
}
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 2e60433246..0ec9667744 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -1082,12 +1082,10 @@ int device_update_db(sd_device *device) {
return 0;
fail:
- log_error_errno(r, "failed to create %s file '%s' for '%s'", has_info ? "db" : "empty",
- path, device->devpath);
- unlink(path);
- unlink(path_tmp);
+ (void) unlink(path);
+ (void) unlink(path_tmp);
- return r;
+ return log_error_errno(r, "failed to create %s file '%s' for '%s'", has_info ? "db" : "empty", path, device->devpath);
}
int device_delete_db(sd_device *device) {
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index b0ed2f2882..3ba62a6be9 100644
--- a/src/libsystemd/sd-netlink/netlink-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -262,6 +262,24 @@ int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type,
return 0;
}
+int sd_netlink_message_append_flag(sd_netlink_message *m, unsigned short type) {
+ size_t size;
+ int r;
+
+ assert_return(m, -EINVAL);
+ assert_return(!m->sealed, -EPERM);
+
+ r = message_attribute_has_type(m, &size, type, NETLINK_TYPE_FLAG);
+ if (r < 0)
+ return r;
+
+ r = add_rtattr(m, type, NULL, 0);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
int sd_netlink_message_append_u8(sd_netlink_message *m, unsigned short type, uint8_t data) {
int r;
diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c
index 1e747abb24..2128329191 100644
--- a/src/libsystemd/sd-netlink/netlink-types.c
+++ b/src/libsystemd/sd-netlink/netlink-types.c
@@ -117,20 +117,30 @@ static const NLType rtnl_link_info_data_vlan_types[IFLA_VLAN_MAX + 1] = {
};
static const NLType rtnl_link_info_data_vxlan_types[IFLA_VXLAN_MAX+1] = {
- [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 },
- [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR },
- [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 },
- [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_U32},
- [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 },
- [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 },
- [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 },
- [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 },
- [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 },
- [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32},
- [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 },
- [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 },
- [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 },
- [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_ID] = { .type = NETLINK_TYPE_U32 },
+ [IFLA_VXLAN_GROUP] = { .type = NETLINK_TYPE_IN_ADDR },
+ [IFLA_VXLAN_LINK] = { .type = NETLINK_TYPE_U32 },
+ [IFLA_VXLAN_LOCAL] = { .type = NETLINK_TYPE_U32},
+ [IFLA_VXLAN_TTL] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_TOS] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_LEARNING] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_AGEING] = { .type = NETLINK_TYPE_U32 },
+ [IFLA_VXLAN_LIMIT] = { .type = NETLINK_TYPE_U32 },
+ [IFLA_VXLAN_PORT_RANGE] = { .type = NETLINK_TYPE_U32},
+ [IFLA_VXLAN_PROXY] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_RSC] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_L2MISS] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_L3MISS] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_PORT] = { .type = NETLINK_TYPE_U16 },
+ [IFLA_VXLAN_GROUP6] = { .type = NETLINK_TYPE_IN_ADDR },
+ [IFLA_VXLAN_LOCAL6] = { .type = NETLINK_TYPE_IN_ADDR },
+ [IFLA_VXLAN_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_REMCSUM_TX] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_REMCSUM_RX] = { .type = NETLINK_TYPE_U8 },
+ [IFLA_VXLAN_GBP] = { .type = NETLINK_TYPE_FLAG },
+ [IFLA_VXLAN_REMCSUM_NOPARTIAL] = { .type = NETLINK_TYPE_FLAG },
};
static const NLType rtnl_bond_arp_target_types[BOND_ARP_TARGETS_MAX + 1] = {
diff --git a/src/libsystemd/sd-netlink/netlink-types.h b/src/libsystemd/sd-netlink/netlink-types.h
index 758ffad1b7..bf7c641541 100644
--- a/src/libsystemd/sd-netlink/netlink-types.h
+++ b/src/libsystemd/sd-netlink/netlink-types.h
@@ -28,6 +28,7 @@ enum {
NETLINK_TYPE_U32, /* NLA_U32 */
NETLINK_TYPE_U64, /* NLA_U64 */
NETLINK_TYPE_STRING, /* NLA_STRING */
+ NETLINK_TYPE_FLAG, /* NLA_FLAG */
NETLINK_TYPE_IN_ADDR,
NETLINK_TYPE_ETHER_ADDR,
NETLINK_TYPE_CACHE_INFO,
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 88756542fd..e8a8f17d86 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -476,15 +476,25 @@ static int x11_write_data(Context *c) {
fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options);
fputs("EndSection\n", f);
- fflush(f);
- if (ferror(f) || rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
+
+ if (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
r = -errno;
- unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
- unlink(temp_path);
- return r;
- } else
- return 0;
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ (void) unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
+
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return r;
}
static int vconsole_reload(sd_bus *bus) {
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 9709eca9bd..5fa98e069f 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -372,11 +372,9 @@ static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_mess
if (r < 0)
return r;
- free(*p);
- *p = strdup(s);
-
- if (!*p)
- return -ENOMEM;
+ r = free_and_strdup(p, s);
+ if (r < 0)
+ return r;
} else {
r = sd_bus_message_read_basic(m, contents[0], userdata);
if (r < 0)
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index e6371ff04d..397952e7e5 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1816,17 +1816,22 @@ static int update_schedule_file(Manager *m) {
if (!isempty(m->wall_message))
fprintf(f, "WALL_MESSAGE=%s\n", t);
- (void) fflush_and_check(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) {
- log_error_errno(errno, "Failed to write information about scheduled shutdowns: %m");
+ if (rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) {
r = -errno;
-
- (void) unlink(temp_path);
- (void) unlink("/run/systemd/shutdown/scheduled");
+ goto fail;
}
- return r;
+ return 0;
+
+fail:
+ (void) unlink(temp_path);
+ (void) unlink("/run/systemd/shutdown/scheduled");
+
+ return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m");
}
static int manager_scheduled_shutdown_handler(
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index 855c85402c..a261e6a719 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -86,11 +86,11 @@ int inhibitor_save(Inhibitor *i) {
r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0);
if (r < 0)
- goto finish;
+ goto fail;
r = fopen_temporary(i->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fchmod(fileno(f), 0644);
@@ -128,19 +128,24 @@ int inhibitor_save(Inhibitor *i) {
if (i->fifo_path)
fprintf(f, "FIFO=%s\n", i->fifo_path);
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, i->state_file) < 0) {
+ if (rename(temp_path, i->state_file) < 0) {
r = -errno;
- unlink(i->state_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file);
+ return 0;
- return r;
+fail:
+ (void) unlink(i->state_file);
+
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file);
}
int inhibitor_start(Inhibitor *i) {
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index 495ec50be0..8d13a63688 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -93,11 +93,11 @@ int seat_save(Seat *s) {
r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0);
if (r < 0)
- goto finish;
+ goto fail;
r = fopen_temporary(s->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fchmod(fileno(f), 0644);
@@ -141,19 +141,24 @@ int seat_save(Seat *s) {
i->sessions_by_seat_next ? ' ' : '\n');
}
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, s->state_file) < 0) {
+ if (rename(temp_path, s->state_file) < 0) {
r = -errno;
- unlink(s->state_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_errno(r, "Failed to save seat data %s: %m", s->state_file);
+ return 0;
- return r;
+fail:
+ (void) unlink(s->state_file);
+
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save seat data %s: %m", s->state_file);
}
int seat_load(Seat *s) {
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 45f4c09d3d..2537d02845 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -165,11 +165,11 @@ int session_save(Session *s) {
r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0);
if (r < 0)
- goto finish;
+ goto fail;
r = fopen_temporary(s->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
assert(s->user);
@@ -217,7 +217,7 @@ int session_save(Session *s) {
escaped = cescape(s->remote_host);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "REMOTE_HOST=%s\n", escaped);
@@ -229,7 +229,7 @@ int session_save(Session *s) {
escaped = cescape(s->remote_user);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "REMOTE_USER=%s\n", escaped);
@@ -241,7 +241,7 @@ int session_save(Session *s) {
escaped = cescape(s->service);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "SERVICE=%s\n", escaped);
@@ -254,7 +254,7 @@ int session_save(Session *s) {
escaped = cescape(s->desktop);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "DESKTOP=%s\n", escaped);
@@ -282,21 +282,27 @@ int session_save(Session *s) {
if (s->controller)
fprintf(f, "CONTROLLER=%s\n", s->controller);
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, s->state_file) < 0) {
+ if (rename(temp_path, s->state_file) < 0) {
r = -errno;
- unlink(s->state_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_errno(r, "Failed to save session data %s: %m", s->state_file);
+ return 0;
- return r;
+fail:
+ (void) unlink(s->state_file);
+
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save session data %s: %m", s->state_file);
}
+
int session_load(Session *s) {
_cleanup_free_ char *remote = NULL,
*seat = NULL,
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 21d7268120..5d8a7571cd 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -116,11 +116,11 @@ static int user_save_internal(User *u) {
r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0);
if (r < 0)
- goto finish;
+ goto fail;
r = fopen_temporary(u->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
fchmod(fileno(f), 0644);
@@ -241,19 +241,24 @@ static int user_save_internal(User *u) {
fputc('\n', f);
}
- fflush(f);
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
- if (ferror(f) || rename(temp_path, u->state_file) < 0) {
+ if (rename(temp_path, u->state_file) < 0) {
r = -errno;
- unlink(u->state_file);
- unlink(temp_path);
+ goto fail;
}
-finish:
- if (r < 0)
- log_error_errno(r, "Failed to save user data %s: %m", u->state_file);
+ return 0;
- return r;
+fail:
+ (void) unlink(u->state_file);
+
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save user data %s: %m", u->state_file);
}
int user_save(User *u) {
diff --git a/src/machine/machine.c b/src/machine/machine.c
index 05fc4f849f..ab26803683 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -112,13 +112,13 @@ int machine_save(Machine *m) {
r = mkdir_safe_label("/run/systemd/machines", 0755, 0, 0);
if (r < 0)
- goto finish;
+ goto fail;
r = fopen_temporary(m->state_file, &f, &temp_path);
if (r < 0)
- goto finish;
+ goto fail;
- fchmod(fileno(f), 0644);
+ (void) fchmod(fileno(f), 0644);
fprintf(f,
"# This is private data. Do not parse.\n"
@@ -131,7 +131,7 @@ int machine_save(Machine *m) {
escaped = cescape(m->unit);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "SCOPE=%s\n", escaped); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */
@@ -146,7 +146,7 @@ int machine_save(Machine *m) {
escaped = cescape(m->service);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "SERVICE=%s\n", escaped);
}
@@ -157,7 +157,7 @@ int machine_save(Machine *m) {
escaped = cescape(m->root_directory);
if (!escaped) {
r = -ENOMEM;
- goto finish;
+ goto fail;
}
fprintf(f, "ROOT=%s\n", escaped);
}
@@ -195,16 +195,13 @@ int machine_save(Machine *m) {
r = fflush_and_check(f);
if (r < 0)
- goto finish;
+ goto fail;
if (rename(temp_path, m->state_file) < 0) {
r = -errno;
- goto finish;
+ goto fail;
}
- free(temp_path);
- temp_path = NULL;
-
if (m->unit) {
char *sl;
@@ -215,14 +212,15 @@ int machine_save(Machine *m) {
(void) symlink(m->name, sl);
}
-finish:
- if (temp_path)
- unlink(temp_path);
+ return 0;
- if (r < 0)
- log_error_errno(r, "Failed to save machine data %s: %m", m->state_file);
+fail:
+ (void) unlink(m->state_file);
- return r;
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save machine data %s: %m", m->state_file);
}
static void machine_unlink(Machine *m) {
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index f20f68b482..78e96c4e5b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2059,10 +2059,9 @@ int link_update(Link *link, sd_netlink_message *m) {
link_free_carrier_maps(link);
- free(link->ifname);
- link->ifname = strdup(ifname);
- if (!link->ifname)
- return -ENOMEM;
+ r = free_and_strdup(&link->ifname, ifname);
+ if (r < 0)
+ return r;
r = link_new_carrier_maps(link);
if (r < 0)
@@ -2388,14 +2387,13 @@ int link_save(Link *link) {
}
return 0;
+
fail:
- log_link_error_errno(link, r, "Failed to save link data to %s: %m", link->state_file);
(void) unlink(link->state_file);
-
if (temp_path)
(void) unlink(temp_path);
- return r;
+ return log_link_error_errno(link, r, "Failed to save link data to %s: %m", link->state_file);
}
static const char* const link_state_table[_LINK_STATE_MAX] = {
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index a5c2351cf9..e718c4840a 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -818,10 +818,10 @@ int manager_save(Manager *m) {
return 0;
fail:
- log_error_errno(r, "Failed to save network state to %s: %m", m->state_file);
- unlink(m->state_file);
- unlink(temp_path);
- return r;
+ (void) unlink(m->state_file);
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save network state to %s: %m", m->state_file);
}
int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found) {
diff --git a/src/network/networkd-netdev-gperf.gperf b/src/network/networkd-netdev-gperf.gperf
index 7e46293a06..9469160eba 100644
--- a/src/network/networkd-netdev-gperf.gperf
+++ b/src/network/networkd-netdev-gperf.gperf
@@ -54,6 +54,7 @@ VXLAN.UDPCheckSum, config_parse_bool, 0,
VXLAN.UDP6ZeroCheckSumRx, config_parse_bool, 0, offsetof(VxLan, udp6zerocsumrx)
VXLAN.UDP6ZeroCheckSumTx, config_parse_bool, 0, offsetof(VxLan, udp6zerocsumtx)
VXLAN.FDBAgeingSec, config_parse_sec, 0, offsetof(VxLan, fdb_ageing)
+VXLAN.GroupPolicyExtension, config_parse_bool, 0, offsetof(VxLan, group_policy)
Tun.OneQueue, config_parse_bool, 0, offsetof(TunTap, one_queue)
Tun.MultiQueue, config_parse_bool, 0, offsetof(TunTap, multi_queue)
Tun.PacketInfo, config_parse_bool, 0, offsetof(TunTap, packet_info)
diff --git a/src/network/networkd-netdev-tunnel.c b/src/network/networkd-netdev-tunnel.c
index 7fd9ef584b..265e67b7e3 100644
--- a/src/network/networkd-netdev-tunnel.c
+++ b/src/network/networkd-netdev-tunnel.c
@@ -404,12 +404,6 @@ int config_parse_tunnel_address(const char *unit,
return 0;
}
-static const char* const ipv6_flowlabel_table[_NETDEV_IPV6_FLOWLABEL_MAX] = {
- [NETDEV_IPV6_FLOWLABEL_INHERIT] = "inherit",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(ipv6_flowlabel, IPv6FlowLabel);
-
int config_parse_ipv6_flowlabel(const char* unit,
const char *filename,
unsigned line,
@@ -422,7 +416,6 @@ int config_parse_ipv6_flowlabel(const char* unit,
void *userdata) {
IPv6FlowLabel *ipv6_flowlabel = data;
Tunnel *t = userdata;
- IPv6FlowLabel s;
int k = 0;
int r;
@@ -431,12 +424,11 @@ int config_parse_ipv6_flowlabel(const char* unit,
assert(rvalue);
assert(ipv6_flowlabel);
- s = ipv6_flowlabel_from_string(rvalue);
- if (s != _NETDEV_IPV6_FLOWLABEL_INVALID) {
+ if (streq(rvalue, "inherit")) {
*ipv6_flowlabel = IP6_FLOWINFO_FLOWLABEL;
t->flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
} else {
- r = config_parse_unsigned(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &k, userdata);
+ r = config_parse_int(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &k, userdata);
if (r >= 0) {
if (k > 0xFFFFF)
log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse IPv6 flowlabel option, ignoring: %s", rvalue);
diff --git a/src/network/networkd-netdev-tunnel.h b/src/network/networkd-netdev-tunnel.h
index 1fd2b94ae1..e4fa74aef4 100644
--- a/src/network/networkd-netdev-tunnel.h
+++ b/src/network/networkd-netdev-tunnel.h
@@ -45,6 +45,7 @@ struct Tunnel {
uint8_t encap_limit;
int family;
+ int ipv6_flowlabel;
unsigned ttl;
unsigned tos;
@@ -54,7 +55,6 @@ struct Tunnel {
union in_addr_union remote;
Ip6TnlMode ip6tnl_mode;
- IPv6FlowLabel ipv6_flowlabel;
bool pmtudisc;
bool copy_dscp;
@@ -90,9 +90,6 @@ int config_parse_tunnel_address(const char *unit,
void *data,
void *userdata);
-const char *ipv6_flowlabel_to_string(IPv6FlowLabel d) _const_;
-IPv6FlowLabel ipv6_flowlabel_from_string(const char *d) _pure_;
-
int config_parse_ipv6_flowlabel(const char *unit, const char *filename,
unsigned line, const char *section,
unsigned section_line, const char *lvalue,
diff --git a/src/network/networkd-netdev-vxlan.c b/src/network/networkd-netdev-vxlan.c
index 2a5c5f0baa..2518e2732b 100644
--- a/src/network/networkd-netdev-vxlan.c
+++ b/src/network/networkd-netdev-vxlan.c
@@ -3,7 +3,7 @@
/***
This file is part of systemd.
- Copyright 2014 Susant Sahani <susant@redhat.com>
+ Copyright 2014 Susant Sahani
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
@@ -101,6 +101,12 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
+ if (v->group_policy) {
+ r = sd_netlink_message_append_flag(m, IFLA_VXLAN_GBP);
+ if (r < 0)
+ return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GBP attribute: %m");
+ }
+
return r;
}
diff --git a/src/network/networkd-netdev-vxlan.h b/src/network/networkd-netdev-vxlan.h
index e7d1306f13..4ec33946cc 100644
--- a/src/network/networkd-netdev-vxlan.h
+++ b/src/network/networkd-netdev-vxlan.h
@@ -50,6 +50,7 @@ struct VxLan {
bool udpcsum;
bool udp6zerocsumtx;
bool udp6zerocsumrx;
+ bool group_policy;
};
extern const NetDevVTable vxlan_vtable;
diff --git a/src/network/networkd-wait-online-manager.c b/src/network/networkd-wait-online-manager.c
index 1fc724f5a4..112d92a568 100644
--- a/src/network/networkd-wait-online-manager.c
+++ b/src/network/networkd-wait-online-manager.c
@@ -38,9 +38,15 @@ bool manager_ignore_link(Manager *m, Link *link) {
assert(m);
assert(link);
+ /* always ignore the loopback interface */
if (link->flags & IFF_LOOPBACK)
return true;
+ /* if interfaces are given on the command line, ignore all others */
+ if (m->interfaces && !strv_contains(m->interfaces, link->ifname))
+ return true;
+
+ /* ignore interfaces we explicitly are asked to ignore */
STRV_FOREACH(ignore, m->ignore)
if (fnmatch(*ignore, link->ifname, 0) == 0)
return true;
@@ -77,7 +83,7 @@ bool manager_all_configured(Manager *m) {
return false;
}
- if (streq(l->state, "configuring")) {
+ if (STR_IN_SET(l->state, "configuring", "pending")) {
log_debug("link %s is being processed by networkd",
l->ifname);
return false;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 65b9a5071b..d46f768cfa 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -503,9 +503,8 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'u':
- free(arg_user);
- arg_user = strdup(optarg);
- if (!arg_user)
+ r = free_and_strdup(&arg_user, optarg);
+ if (r < 0)
return log_oom();
break;
diff --git a/src/run/run.c b/src/run/run.c
index 148854a9b5..3dd97022de 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -1129,13 +1129,9 @@ int main(int argc, char* argv[]) {
}
if (arg_unit && isempty(description)) {
- free(description);
- description = strdup(arg_unit);
-
- if (!description) {
- r = log_oom();
+ r = free_and_strdup(&description, arg_unit);
+ if (r < 0)
goto finish;
- }
}
arg_description = description;
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index 3941605cec..ca4c24ebde 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -382,11 +382,9 @@ int ask_password_agent(
if (id)
fprintf(f, "Id=%s\n", id);
- fflush(f);
-
- if (ferror(f)) {
- log_error_errno(errno, "Failed to write query file: %m");
- r = -errno;
+ r = fflush_and_check(f);
+ if (r < 0) {
+ log_error_errno(r, "Failed to write query file: %m");
goto finish;
}
diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h
index 24a9ed8e77..cb462bf48f 100644
--- a/src/systemd/sd-netlink.h
+++ b/src/systemd/sd-netlink.h
@@ -69,6 +69,7 @@ int sd_netlink_attach_event(sd_netlink *nl, sd_event *e, int priority);
int sd_netlink_detach_event(sd_netlink *nl);
int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data);
+int sd_netlink_message_append_flag(sd_netlink_message *m, unsigned short type);
int sd_netlink_message_append_u8(sd_netlink_message *m, unsigned short type, uint8_t data);
int sd_netlink_message_append_u16(sd_netlink_message *m, unsigned short type, uint16_t data);
int sd_netlink_message_append_u32(sd_netlink_message *m, unsigned short type, uint32_t data);
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index d7ba482834..b3fa29b84c 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -891,8 +891,10 @@ static int add_user(Item *i) {
i->uid = p->pw_uid;
i->uid_set = true;
- free(i->description);
- i->description = strdup(p->pw_gecos);
+ r = free_and_strdup(&i->description, p->pw_gecos);
+ if (r < 0)
+ return log_oom();
+
return 0;
}
if (!IN_SET(errno, 0, ENOENT))
@@ -1149,9 +1151,8 @@ static int process_item(Item *i) {
}
if (i->gid_path) {
- free(j->gid_path);
- j->gid_path = strdup(i->gid_path);
- if (!j->gid_path)
+ r = free_and_strdup(&j->gid_path, i->gid_path);
+ if (r < 0)
return log_oom();
}
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index d00f90afa6..bbb9f97226 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -2429,8 +2429,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
rules_str(rules, rule->rule.filename_off), rule->rule.filename_line);
break;
}
- free(event->name);
- event->name = strdup(name_str);
+ free_and_strdup(&event->name, name_str);
log_debug("NAME '%s' %s:%u",
event->name,
rules_str(rules, rule->rule.filename_off),