summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-29 09:16:45 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-29 09:16:45 -0400
commit3e39355a96f615f2cb1e805c7d74efbc272de1cd (patch)
treea31b20b819e007d959db412c8d18ee1bf37bed8d /src
parent427a28ecbe0eb170e651e0530ab58d6e6f6c498c (diff)
parent1fcefd8815455e416c1eda3c8c1220831a2f82e9 (diff)
Merge pull request #3126 from poettering/small-fixes
fsync directory when creating or rotating journal files and other small fixes, most importantly for the DHCP DUID code.
Diffstat (limited to 'src')
-rw-r--r--src/basic/fd-util.c8
-rw-r--r--src/journal/journal-file.c39
-rw-r--r--src/network/networkd-conf.c55
-rw-r--r--src/network/networkd-gperf.gperf4
-rw-r--r--src/network/networkd-network-gperf.gperf4
-rw-r--r--src/network/networkd-network.c1
6 files changed, 81 insertions, 30 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index 9130d023d7..8b466cff15 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -361,8 +361,14 @@ bool fdname_is_valid(const char *s) {
int fd_get_path(int fd, char **ret) {
char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
+ int r;
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
- return readlink_malloc(procfs_path, ret);
+ r = readlink_malloc(procfs_path, ret);
+
+ if (r == -ENOENT) /* If the file doesn't exist the fd is invalid */
+ return -EBADF;
+
+ return r;
}
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 35f4abab1d..c9ce5c73be 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -439,6 +439,39 @@ static int journal_file_init_header(JournalFile *f, JournalFile *template) {
return 0;
}
+static int fsync_directory_of_file(int fd) {
+ _cleanup_free_ char *path = NULL, *dn = NULL;
+ _cleanup_close_ int dfd = -1;
+ struct stat st;
+ int r;
+
+ if (fstat(fd, &st) < 0)
+ return -errno;
+
+ if (!S_ISREG(st.st_mode))
+ return -EBADFD;
+
+ r = fd_get_path(fd, &path);
+ if (r < 0)
+ return r;
+
+ if (!path_is_absolute(path))
+ return -EINVAL;
+
+ dn = dirname_malloc(path);
+ if (!dn)
+ return -ENOMEM;
+
+ dfd = open(dn, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
+ if (dfd < 0)
+ return -errno;
+
+ if (fsync(dfd) < 0)
+ return -errno;
+
+ return 0;
+}
+
static int journal_file_refresh_header(JournalFile *f) {
sd_id128_t boot_id;
int r;
@@ -464,6 +497,9 @@ static int journal_file_refresh_header(JournalFile *f) {
/* Sync the online state to disk */
(void) fsync(f->fd);
+ /* We likely just created a new file, also sync the directory this file is located in. */
+ (void) fsync_directory_of_file(f->fd);
+
return r;
}
@@ -3177,6 +3213,9 @@ int journal_file_rotate(JournalFile **f, bool compress, bool seal, Set *deferred
if (r < 0 && errno != ENOENT)
return -errno;
+ /* Sync the rename to disk */
+ (void) fsync_directory_of_file(old_file->fd);
+
/* Set as archive so offlining commits w/state=STATE_ARCHIVED.
* Previously we would set old_file->header->state to STATE_ARCHIVED directly here,
* but journal_file_set_offline() short-circuits when state != STATE_ONLINE, which
diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c
index 73a8d16b58..70f0121d6d 100644
--- a/src/network/networkd-conf.c
+++ b/src/network/networkd-conf.c
@@ -31,7 +31,7 @@ int manager_parse_config_file(Manager *m) {
return config_parse_many(PKGSYSCONFDIR "/networkd.conf",
CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
- "DUID\0",
+ "DHCP\0",
config_item_perf_lookup, networkd_gperf_lookup,
false, m);
}
@@ -57,7 +57,8 @@ int config_parse_duid_rawdata(
const char *rvalue,
void *data,
void *userdata) {
- int r, n1, n2, byte;
+
+ int r;
char *cbyte;
const char *pduid = rvalue;
Manager *m = userdata;
@@ -72,71 +73,78 @@ int config_parse_duid_rawdata(
assert(rvalue);
assert(userdata);
- duidtype = (ltype == DUID_CONFIG_SOURCE_GLOBAL) ? m->duid_type
- : n->duid_type;
+ duidtype = (ltype == DUID_CONFIG_SOURCE_GLOBAL) ? m->duid_type : n->duid_type;
if (duidtype == _DUID_TYPE_INVALID)
duidtype = DUID_TYPE_RAW;
switch (duidtype) {
+
case DUID_TYPE_LLT:
/* RawData contains DUID-LLT link-layer address (offset 6) */
duid_start_offset = 6;
break;
+
case DUID_TYPE_EN:
/* RawData contains DUID-EN identifier (offset 4) */
duid_start_offset = 4;
break;
+
case DUID_TYPE_LL:
/* RawData contains DUID-LL link-layer address (offset 2) */
duid_start_offset = 2;
break;
+
case DUID_TYPE_UUID:
/* RawData specifies UUID (offset 0) - fall thru */
+
case DUID_TYPE_RAW:
/* First two bytes of RawData is DUID Type - fall thru */
+
default:
break;
}
if (duidtype != DUID_TYPE_RAW)
- dhcp_duid_type = (uint16_t)duidtype;
+ dhcp_duid_type = (uint16_t) duidtype;
/* RawData contains DUID in format " NN:NN:NN... " */
for (;;) {
+ int n1, n2;
+ uint32_t byte;
+
r = extract_first_word(&pduid, &cbyte, ":", 0);
if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to read DUID, ignoring assignment: %s.", rvalue);
- goto exit;
+ log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
+ return 0;
}
if (r == 0)
break;
- if ((duid_start_offset + dhcp_duid_len) >= MAX_DUID_LEN) {
- log_syntax(unit, LOG_ERR, filename, line, 0,
- "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
- goto exit;
+ if (duid_start_offset + dhcp_duid_len >= MAX_DUID_LEN) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
+ return 0;
}
len = strlen(cbyte);
- if ((len == 0) || (len > 2)) {
- log_syntax(unit, LOG_ERR, filename, line, 0,
- "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
- goto exit;
+ if (len != 1 && len != 2) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
+ return 0;
}
- n2 = 0;
n1 = unhexchar(cbyte[0]);
if (len == 2)
n2 = unhexchar(cbyte[1]);
- if ((n1 < 0) || (n2 < 0)) {
- log_syntax(unit, LOG_ERR, filename, line, 0,
- "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
- goto exit;
+ else
+ n2 = 0;
+
+ if (n1 < 0 || n2 < 0) {
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
+ return 0;
}
- byte = (n1 << (4 * (len-1))) | n2;
+
+ byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
/* If DUID_TYPE_RAW, first two bytes hold DHCP DUID type code */
- if ((duidtype == DUID_TYPE_RAW) && (count < 2)) {
+ if (duidtype == DUID_TYPE_RAW && count < 2) {
dhcp_duid_type |= (byte << (8 * (1 - count)));
count++;
continue;
@@ -159,6 +167,5 @@ int config_parse_duid_rawdata(
memcpy(&n->dhcp_duid[duid_start_offset], dhcp_duid, dhcp_duid_len);
}
-exit:
return 0;
}
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf
index 0625fb335b..afc71b4cb8 100644
--- a/src/network/networkd-gperf.gperf
+++ b/src/network/networkd-gperf.gperf
@@ -14,5 +14,5 @@ struct ConfigPerfItem;
%struct-type
%includes
%%
-DUID.Type, config_parse_duid_type, 0, offsetof(Manager, duid_type)
-DUID.RawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_GLOBAL, offsetof(Manager, dhcp_duid)
+DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Manager, duid_type)
+DHCP.DUIDRawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_GLOBAL, offsetof(Manager, dhcp_duid)
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 1da99cd5bc..654d6a0316 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -28,8 +28,6 @@ Match.Architecture, config_parse_net_condition,
Link.MACAddress, config_parse_hwaddr, 0, offsetof(Network, mac)
Link.MTUBytes, config_parse_iec_size, 0, offsetof(Network, mtu)
Link.IAID, config_parse_iaid, 0, offsetof(Network, iaid)
-DUID.Type, config_parse_duid_type, 0, offsetof(Network, duid_type)
-DUID.RawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_NETWORK, offsetof(Network, dhcp_duid)
Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
@@ -85,6 +83,8 @@ DHCP.Hostname, config_parse_hostname,
DHCP.RequestBroadcast, config_parse_bool, 0, offsetof(Network, dhcp_broadcast)
DHCP.CriticalConnection, config_parse_bool, 0, offsetof(Network, dhcp_critical)
DHCP.VendorClassIdentifier, config_parse_string, 0, offsetof(Network, dhcp_vendor_class_identifier)
+DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Network, duid_type)
+DHCP.DUIDRawData, config_parse_duid_rawdata, DUID_CONFIG_SOURCE_NETWORK, offsetof(Network, dhcp_duid)
DHCP.RouteMetric, config_parse_unsigned, 0, offsetof(Network, dhcp_route_metric)
DHCP.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_use_timezone)
DHCPServer.MaxLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_max_lease_time_usec)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 07f8fb028f..2ebcdfa744 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -137,7 +137,6 @@ static int network_load_one(Manager *manager, const char *filename) {
r = config_parse(NULL, filename, file,
"Match\0"
"Link\0"
- "DUID\0"
"Network\0"
"Address\0"
"Route\0"