diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-23 19:05:43 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-24 00:25:04 -0400 |
commit | 90ae6c0b822bbfd433c801d7945cadcabd1bc1c3 (patch) | |
tree | 6dbb5dd0008818dac95afedb346d7ae94517c468 /src | |
parent | ef42202ac8ed27e7ff1fc90ef8bc2590046dff25 (diff) |
readahead: be more verbose about creation failures
systemd-readahead reports "Failed to create shared memory segment:
No such file or directory", but it's unclear how it can happen. Be
more verbose about failures.
Diffstat (limited to 'src')
-rw-r--r-- | src/readahead/readahead-common.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c index ed81c14d89..a234a89954 100644 --- a/src/readahead/readahead-common.c +++ b/src/readahead/readahead-common.c @@ -216,16 +216,23 @@ bool enough_ram(void) { return si.totalram > 127 * 1024*1024 / si.mem_unit; } +static void mkdirs(void) { + if (mkdir("/run/systemd", 0755) && errno != EEXIST) + log_warning("Failed to create /run/systemd: %m"); + if (mkdir("/run/systemd/readahead", 0755) && errno != EEXIST) + log_warning("Failed to create /run/systemd: %m"); +} + int open_inotify(void) { int fd; - if ((fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) { + fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); + if (fd < 0) { log_error("Failed to create inotify handle: %m"); return -errno; } - mkdir("/run/systemd", 0755); - mkdir("/run/systemd/readahead", 0755); + mkdirs(); if (inotify_add_watch(fd, "/run/systemd/readahead", IN_CREATE) < 0) { log_error("Failed to watch /run/systemd/readahead: %m"); @@ -237,32 +244,28 @@ int open_inotify(void) { } ReadaheadShared *shared_get(void) { - int fd; + int _cleanup_close_ fd = -1; ReadaheadShared *m = NULL; - mkdir("/run/systemd", 0755); - mkdir("/run/systemd/readahead", 0755); + mkdirs(); - if ((fd = open("/run/systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644)) < 0) { + fd = open("/run/systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644); + if (fd < 0) { log_error("Failed to create shared memory segment: %m"); - goto finish; + return NULL; } if (ftruncate(fd, sizeof(ReadaheadShared)) < 0) { log_error("Failed to truncate shared memory segment: %m"); - goto finish; + return NULL; } - if ((m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { + m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); + if (m == MAP_FAILED) { log_error("Failed to mmap shared memory segment: %m"); - m = NULL; - goto finish; + return NULL; } -finish: - if (fd >= 0) - close_nointr_nofail(fd); - return m; } |