#include <errno.h>
#include <getopt.h>
-#include <string.h>
#include <sys/prctl.h>
#include <unistd.h>
#include "locale-util.h"
#include "log.h"
#include "main-func.h"
+#include "nulstr-util.h"
#include "pager.h"
#include "parse-util.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
-#include "util.h"
static const char prefixes[] =
"/etc\0"
_cleanup_free_ char *x = NULL, *y = NULL;
int r;
- r = chase_symlinks(a, NULL, CHASE_TRAIL_SLASH, &x);
+ r = chase_symlinks(a, NULL, CHASE_TRAIL_SLASH, &x, NULL);
if (r < 0)
return r;
- r = chase_symlinks(b, NULL, CHASE_TRAIL_SLASH, &y);
+ r = chase_symlinks(b, NULL, CHASE_TRAIL_SLASH, &y, NULL);
if (r < 0)
return r;
assert(!endswith(drop, "/"));
- path = strjoin(toppath, "/", drop);
+ path = path_join(toppath, drop);
if (!path)
return -ENOMEM;
if (!endswith(*file, ".conf"))
continue;
- p = strjoin(path, "/", *file);
+ p = path_join(path, *file);
if (!p)
return -ENOMEM;
d = p + strlen(toppath) + 1;
STRV_FOREACH(t, files) {
_cleanup_free_ char *p = NULL;
- p = strjoin(path, "/", *t);
+ p = path_join(path, *t);
if (!p)
return -ENOMEM;
return 0;
}
-static bool should_skip_path(const char *prefix, const char *suffix) {
+static int should_skip_path(const char *prefix, const char *suffix) {
#if HAVE_SPLIT_USR
_cleanup_free_ char *target = NULL;
- const char *p;
- char *dirname;
+ const char *dirname, *p;
- dirname = strjoina(prefix, "/", suffix);
+ dirname = prefix_roota(prefix, suffix);
- if (chase_symlinks(dirname, NULL, 0, &target) < 0)
+ if (chase_symlinks(dirname, NULL, 0, &target, NULL) < 0)
return false;
NULSTR_FOREACH(p, prefixes) {
+ _cleanup_free_ char *tmp = NULL;
+
if (path_startswith(dirname, p))
continue;
- if (path_equal(target, strjoina(p, "/", suffix))) {
+ tmp = path_join(p, suffix);
+ if (!tmp)
+ return -ENOMEM;
+
+ if (path_equal(target, tmp)) {
log_debug("%s redirects to %s, skipping.", dirname, target);
return true;
}
static int process_suffix(const char *suffix, const char *onlyprefix) {
const char *p;
- char *f;
- OrderedHashmap *top, *bottom, *drops;
- OrderedHashmap *h;
- char *key;
- int r = 0, k;
- Iterator i, j;
- int n_found = 0;
+ char *f, *key;
+ OrderedHashmap *top, *bottom, *drops, *h;
+ int r = 0, k, n_found = 0;
bool dropins;
assert(suffix);
NULSTR_FOREACH(p, prefixes) {
_cleanup_free_ char *t = NULL;
- if (should_skip_path(p, suffix))
+ if (should_skip_path(p, suffix) > 0)
continue;
- t = strjoin(p, "/", suffix);
+ t = path_join(p, suffix);
if (!t) {
r = -ENOMEM;
goto finish;
r = k;
}
- ORDERED_HASHMAP_FOREACH_KEY(f, key, top, i) {
+ ORDERED_HASHMAP_FOREACH_KEY(f, key, top) {
char *o;
o = ordered_hashmap_get(bottom, key);
h = ordered_hashmap_get(drops, key);
if (h)
- ORDERED_HASHMAP_FOREACH(o, h, j)
+ ORDERED_HASHMAP_FOREACH(o, h)
if (!onlyprefix || startswith(o, onlyprefix))
n_found += notify_override_extended(f, o);
}
ordered_hashmap_free_free(top);
ordered_hashmap_free_free(bottom);
- ORDERED_HASHMAP_FOREACH_KEY(h, key, drops, i) {
+ ORDERED_HASHMAP_FOREACH_KEY(h, key, drops) {
ordered_hashmap_free_free(ordered_hashmap_remove(drops, key));
ordered_hashmap_remove(drops, key);
free(key);
static int run(int argc, char *argv[]) {
int r, k, n_found = 0;
- log_parse_environment();
- log_open();
+ log_setup_cli();
r = parse_argv(argc, argv);
if (r <= 0)