summaryrefslogtreecommitdiffstats
path: root/src/tmpfiles/tmpfiles.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-09-04 22:46:21 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-09-05 10:07:04 +0200
commitfe2f05b72e3e651d7e3b14066f616a72225abfe0 (patch)
tree16d0eea149e1be9b51342996d4469e3b878061f6 /src/tmpfiles/tmpfiles.c
parenthome: 'secret' argument of handle_generic_user_record_error may be null (diff)
downloadsystemd-fe2f05b72e3e651d7e3b14066f616a72225abfe0.tar.xz
systemd-fe2f05b72e3e651d7e3b14066f616a72225abfe0.zip
tmpfiles: minor modernization
Diffstat (limited to 'src/tmpfiles/tmpfiles.c')
-rw-r--r--src/tmpfiles/tmpfiles.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 38e9844d35..8a02e6c9dd 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -194,7 +194,7 @@ static Set *unix_sockets = NULL;
STATIC_DESTRUCTOR_REGISTER(items, ordered_hashmap_freep);
STATIC_DESTRUCTOR_REGISTER(globs, ordered_hashmap_freep);
-STATIC_DESTRUCTOR_REGISTER(unix_sockets, set_free_freep);
+STATIC_DESTRUCTOR_REGISTER(unix_sockets, set_freep);
STATIC_DESTRUCTOR_REGISTER(arg_include_prefixes, freep);
STATIC_DESTRUCTOR_REGISTER(arg_exclude_prefixes, freep);
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
@@ -421,7 +421,7 @@ static struct Item* find_glob(OrderedHashmap *h, const char *match) {
}
static int load_unix_sockets(void) {
- _cleanup_set_free_free_ Set *sockets = NULL;
+ _cleanup_set_free_ Set *sockets = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
@@ -430,10 +430,6 @@ static int load_unix_sockets(void) {
/* We maintain a cache of the sockets we found in /proc/net/unix to speed things up a little. */
- sockets = set_new(&path_hash_ops);
- if (!sockets)
- return log_oom();
-
f = fopen("/proc/net/unix", "re");
if (!f)
return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, errno,
@@ -447,7 +443,7 @@ static int load_unix_sockets(void) {
return log_warning_errno(SYNTHETIC_ERRNO(EIO), "Premature end of file reading /proc/net/unix.");
for (;;) {
- _cleanup_free_ char *line = NULL, *s = NULL;
+ _cleanup_free_ char *line = NULL;
char *p;
r = read_line(f, LONG_LINE_MAX, &line);
@@ -468,22 +464,12 @@ static int load_unix_sockets(void) {
p += strcspn(p, WHITESPACE); /* skip one more word */
p += strspn(p, WHITESPACE);
- if (*p != '/')
+ if (!path_is_absolute(p))
continue;
- s = strdup(p);
- if (!s)
- return log_oom();
-
- path_simplify(s);
-
- r = set_consume(sockets, s);
- if (r == -EEXIST)
- continue;
+ r = set_put_strdup_full(&sockets, &path_hash_ops_free, p);
if (r < 0)
return log_warning_errno(r, "Failed to add AF_UNIX socket to set, ignoring: %m");
-
- TAKE_PTR(s);
}
unix_sockets = TAKE_PTR(sockets);
@@ -496,7 +482,7 @@ static bool unix_socket_alive(const char *fn) {
if (load_unix_sockets() < 0)
return true; /* We don't know, so assume yes */
- return !!set_get(unix_sockets, (char*) fn);
+ return set_contains(unix_sockets, fn);
}
static DIR* xopendirat_nomod(int dirfd, const char *path) {