diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-15 11:55:43 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-15 11:57:07 +0200 |
commit | 70c949a42b2b0d0c9a2a567890483940cdc5f72c (patch) | |
tree | 11bd2bc1e49e2e89e19528b669f5af04cea3a9d6 /src/shared/fileio.c | |
parent | ce049dcda4a9d0c9a44667ca82bc9e21d7ea7748 (diff) |
cgroup: never try to create files in cgroupfs, only open them for writing
This should have the benefit that cg_set_attribute() returns ENOENT
instead of EACCESS when we use it for non-existing attributes.
Diffstat (limited to 'src/shared/fileio.c')
-rw-r--r-- | src/shared/fileio.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/fileio.c b/src/shared/fileio.c index cbb40c2379..18960abf02 100644 --- a/src/shared/fileio.c +++ b/src/shared/fileio.c @@ -58,6 +58,28 @@ int write_string_file(const char *fn, const char *line) { return write_string_stream(f, line); } +int write_string_file_no_create(const char *fn, const char *line) { + _cleanup_fclose_ FILE *f = NULL; + int fd; + + assert(fn); + assert(line); + + /* We manually build our own version of fopen(..., "we") that + * without O_CREAT */ + fd = open(fn, O_WRONLY|O_CLOEXEC|O_NOCTTY); + if (fd < 0) + return -errno; + + f = fdopen(fd, "we"); + if (!f) { + safe_close(fd); + return -errno; + } + + return write_string_stream(f, line); +} + int write_string_file_atomic(const char *fn, const char *line) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *p = NULL; |