1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 00:51:24 +03:00

Merge pull request #7618 from tiagosh/sysctl_use_read_line

Make systemd-sysctl use read_line() and LONG_LINE_MAX
This commit is contained in:
Yu Watanabe 2017-12-14 13:58:53 +09:00 committed by GitHub
commit 1bb8d1fce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 8 deletions

View File

@ -167,6 +167,9 @@ int write_string_file_ts(
}
}
if (flags & WRITE_STRING_FILE_DISABLE_BUFFER)
setvbuf(f, NULL, _IONBF, 0);
r = write_string_stream_ts(f, line, flags, ts);
if (r < 0)
goto fail;

View File

@ -35,6 +35,7 @@ typedef enum {
WRITE_STRING_FILE_AVOID_NEWLINE = 1<<2,
WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3,
WRITE_STRING_FILE_SYNC = 1<<4,
WRITE_STRING_FILE_DISABLE_BUFFER = 1<<5,
/* And before you wonder, why write_string_file_atomic_label_ts() is a separate function instead of just one
more flag here: it's about linking: we don't want to pull -lselinux into all users of write_string_file()

View File

@ -60,7 +60,7 @@ int sysctl_write(const char *property, const char *value) {
log_debug("Setting '%s' to '%s'", property, value);
p = strjoina("/proc/sys/", property);
return write_string_file(p, value, 0);
return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER);
}
int sysctl_read(const char *property, char **content) {

View File

@ -106,16 +106,16 @@ static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ign
log_debug("Parsing %s", path);
for (;;) {
char l[LINE_MAX], *p, *value, *new_value, *property, *existing;
char *p, *value, *new_value, *property, *existing;
_cleanup_free_ char *l = NULL;
void *v;
int k;
k = read_line(f, LONG_LINE_MAX, &l);
if (k == 0)
break;
if (!fgets(l, sizeof(l), f)) {
if (feof(f))
break;
return log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
}
if (k < 0)
return log_error_errno(k, "Failed to read file '%s', ignoring: %m", path);
c++;