chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
clean-ipc: shorten code a bit
[elogind.git]
/
src
/
shared
/
clean-ipc.c
diff --git
a/src/shared/clean-ipc.c
b/src/shared/clean-ipc.c
index d2e0240a800a1cbea965064da08a553596aa4ab8..0d3bad7cecdafe4126ee935fcbc04be12ae1299f 100644
(file)
--- a/
src/shared/clean-ipc.c
+++ b/
src/shared/clean-ipc.c
@@
-1,5
+1,3
@@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
/***
This file is part of systemd.
@@
-20,22
+18,29
@@
***/
#include <dirent.h>
***/
#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
+#include <limits.h>
#include <mqueue.h>
#include <mqueue.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/stat.h>
+#include <unistd.h>
#include "clean-ipc.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
#include "clean-ipc.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
+#include "log.h"
+#include "macro.h"
#include "string-util.h"
#include "strv.h"
#include "string-util.h"
#include "strv.h"
-#include "util.h"
static int clean_sysvipc_shm(uid_t delete_uid) {
_cleanup_fclose_ FILE *f = NULL;
static int clean_sysvipc_shm(uid_t delete_uid) {
_cleanup_fclose_ FILE *f = NULL;
@@
-202,7
+207,7
@@
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
assert(dir);
assert(dir);
- FOREACH_DIRENT(de, dir, goto fail) {
+ FOREACH_DIRENT
_ALL
(de, dir, goto fail) {
struct stat st;
if (STR_IN_SET(de->d_name, "..", "."))
struct stat st;
if (STR_IN_SET(de->d_name, "..", "."))
@@
-212,8
+217,7
@@
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
if (errno == ENOENT)
continue;
if (errno == ENOENT)
continue;
- log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s: %m", de->d_name);
- ret = -errno;
+ ret = log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s: %m", de->d_name);
continue;
}
continue;
}
@@
-225,10
+229,8
@@
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME);
if (!kid) {
kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME);
if (!kid) {
- if (errno != ENOENT) {
- log_warning_errno(errno, "Failed to enter shared memory directory %s: %m", de->d_name);
- ret = -errno;
- }
+ if (errno != ENOENT)
+ ret = log_warning_errno(errno, "Failed to enter shared memory directory %s: %m", de->d_name);
} else {
r = clean_posix_shm_internal(kid, uid);
if (r < 0)
} else {
r = clean_posix_shm_internal(kid, uid);
if (r < 0)
@@
-240,8
+242,7
@@
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
if (errno == ENOENT)
continue;
if (errno == ENOENT)
continue;
- log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s: %m", de->d_name);
- ret = -errno;
+ ret = log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s: %m", de->d_name);
}
} else {
}
} else {
@@
-250,8
+251,7
@@
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
if (errno == ENOENT)
continue;
if (errno == ENOENT)
continue;
- log_warning_errno(errno, "Failed to remove POSIX shared memory segment %s: %m", de->d_name);
- ret = -errno;
+ ret = log_warning_errno(errno, "Failed to remove POSIX shared memory segment %s: %m", de->d_name);
}
}
}
}
}
}
@@
-259,8
+259,7
@@
static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
return ret;
fail:
return ret;
fail:
- log_warning_errno(errno, "Failed to read /dev/shm: %m");
- return -errno;
+ return log_warning_errno(errno, "Failed to read /dev/shm: %m");
}
static int clean_posix_shm(uid_t uid) {
}
static int clean_posix_shm(uid_t uid) {
@@
-277,8
+276,7
@@
static int clean_posix_shm(uid_t uid) {
return clean_posix_shm_internal(dir, uid);
}
return clean_posix_shm_internal(dir, uid);
}
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
static int clean_posix_mq(uid_t uid) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
static int clean_posix_mq(uid_t uid) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
@@
-292,7
+290,7
@@
static int clean_posix_mq(uid_t uid) {
return log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
}
return log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
}
- FOREACH_DIRENT(de, dir, goto fail) {
+ FOREACH_DIRENT
_ALL
(de, dir, goto fail) {
struct stat st;
char fn[1+strlen(de->d_name)+1];
struct stat st;
char fn[1+strlen(de->d_name)+1];
@@
-355,8
+353,7
@@
int clean_ipc(uid_t uid) {
if (r < 0)
ret = r;
if (r < 0)
ret = r;
-/// elogind does not use mq_open anywhere
-#if 0
+#if 0 /// elogind does not use mq_open anywhere
r = clean_posix_mq(uid);
if (r < 0)
ret = r;
r = clean_posix_mq(uid);
if (r < 0)
ret = r;