Skip to content

Commit fe2f05b

Browse files
yuwatakeszybz
authored andcommitted
tmpfiles: minor modernization
1 parent 6a09dbb commit fe2f05b

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/tmpfiles/tmpfiles.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static Set *unix_sockets = NULL;
194194

195195
STATIC_DESTRUCTOR_REGISTER(items, ordered_hashmap_freep);
196196
STATIC_DESTRUCTOR_REGISTER(globs, ordered_hashmap_freep);
197-
STATIC_DESTRUCTOR_REGISTER(unix_sockets, set_free_freep);
197+
STATIC_DESTRUCTOR_REGISTER(unix_sockets, set_freep);
198198
STATIC_DESTRUCTOR_REGISTER(arg_include_prefixes, freep);
199199
STATIC_DESTRUCTOR_REGISTER(arg_exclude_prefixes, freep);
200200
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
@@ -421,7 +421,7 @@ static struct Item* find_glob(OrderedHashmap *h, const char *match) {
421421
}
422422

423423
static int load_unix_sockets(void) {
424-
_cleanup_set_free_free_ Set *sockets = NULL;
424+
_cleanup_set_free_ Set *sockets = NULL;
425425
_cleanup_fclose_ FILE *f = NULL;
426426
int r;
427427

@@ -430,10 +430,6 @@ static int load_unix_sockets(void) {
430430

431431
/* We maintain a cache of the sockets we found in /proc/net/unix to speed things up a little. */
432432

433-
sockets = set_new(&path_hash_ops);
434-
if (!sockets)
435-
return log_oom();
436-
437433
f = fopen("/proc/net/unix", "re");
438434
if (!f)
439435
return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, errno,
@@ -447,7 +443,7 @@ static int load_unix_sockets(void) {
447443
return log_warning_errno(SYNTHETIC_ERRNO(EIO), "Premature end of file reading /proc/net/unix.");
448444

449445
for (;;) {
450-
_cleanup_free_ char *line = NULL, *s = NULL;
446+
_cleanup_free_ char *line = NULL;
451447
char *p;
452448

453449
r = read_line(f, LONG_LINE_MAX, &line);
@@ -468,22 +464,12 @@ static int load_unix_sockets(void) {
468464
p += strcspn(p, WHITESPACE); /* skip one more word */
469465
p += strspn(p, WHITESPACE);
470466

471-
if (*p != '/')
467+
if (!path_is_absolute(p))
472468
continue;
473469

474-
s = strdup(p);
475-
if (!s)
476-
return log_oom();
477-
478-
path_simplify(s);
479-
480-
r = set_consume(sockets, s);
481-
if (r == -EEXIST)
482-
continue;
470+
r = set_put_strdup_full(&sockets, &path_hash_ops_free, p);
483471
if (r < 0)
484472
return log_warning_errno(r, "Failed to add AF_UNIX socket to set, ignoring: %m");
485-
486-
TAKE_PTR(s);
487473
}
488474

489475
unix_sockets = TAKE_PTR(sockets);
@@ -496,7 +482,7 @@ static bool unix_socket_alive(const char *fn) {
496482
if (load_unix_sockets() < 0)
497483
return true; /* We don't know, so assume yes */
498484

499-
return !!set_get(unix_sockets, (char*) fn);
485+
return set_contains(unix_sockets, fn);
500486
}
501487

502488
static DIR* xopendirat_nomod(int dirfd, const char *path) {

0 commit comments

Comments
 (0)