]> err.no Git - systemd/commitdiff
util: split-out path-util.[ch]
authorKay Sievers <kay@vrfy.org>
Mon, 7 May 2012 19:36:12 +0000 (21:36 +0200)
committerKay Sievers <kay@vrfy.org>
Tue, 8 May 2012 00:33:10 +0000 (02:33 +0200)
49 files changed:
Makefile.am
src/cgls/cgls.c
src/cgtop/cgtop.c
src/core/automount.c
src/core/cgroup.c
src/core/condition.c
src/core/device.c
src/core/execute.c
src/core/load-fragment.c
src/core/manager.c
src/core/mount-setup.c
src/core/mount.c
src/core/namespace.c
src/core/path.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/umount.c
src/core/unit.c
src/cryptsetup/cryptsetup.c
src/journal/sd-journal.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-seat.c
src/login/logind-session.c
src/login/sysfs-show.c
src/nspawn/nspawn.c
src/remount-fs/remount-fs.c
src/shared/cgroup-show.c
src/shared/cgroup-util.c
src/shared/conf-files.c
src/shared/conf-parser.c
src/shared/install.c
src/shared/label.c
src/shared/path-lookup.c
src/shared/path-util.c [new file with mode: 0644]
src/shared/path-util.h [new file with mode: 0644]
src/shared/socket-util.c
src/shared/unit-name.c
src/shared/util.c
src/shared/util.h
src/shared/utmp-wtmp.c
src/sysctl/sysctl.c
src/systemctl/systemctl.c
src/test/test-cgroup.c
src/test/test-install.c
src/tmpfiles/tmpfiles.c
src/tty-ask-password-agent/tty-ask-password-agent.c
src/udev/udev-rules.c

index a6c49883825eddc01ad88f9988c944ad341b2377..dbcfeb384f0fdd513447f15e20d623f0eabf8998 100644 (file)
@@ -526,6 +526,8 @@ libsystemd_shared_la_SOURCES = \
        src/shared/util.h \
        src/shared/virt.c \
        src/shared/virt.h \
+       src/shared/path-util.c \
+       src/shared/path-util.h \
        src/shared/hashmap.c \
        src/shared/hashmap.h \
        src/shared/set.c \
index 4bec6a827e115e4f9c8e2118fb9faaa32df7c10d..b2cd968e46cfeeae5b39f347db7b50739235ff82 100644 (file)
@@ -29,6 +29,7 @@
 #include "cgroup-show.h"
 #include "cgroup-util.h"
 #include "log.h"
+#include "path-util.h"
 #include "util.h"
 #include "pager.h"
 #include "build.h"
index 1fe247c667afae1f5b0a7687411af5d771a8fa19..cc7a99f3dfbe11e11b741326190f40a1e38944e6 100644 (file)
@@ -26,6 +26,7 @@
 #include <alloca.h>
 #include <getopt.h>
 
+#include "path-util.h"
 #include "util.h"
 #include "hashmap.h"
 #include "cgroup-util.h"
index 11c217beb9f10abfbf90bf82f0cfe081b3c2f528..c31e3d8bacf1538a75282561385f6680215d13e4 100644 (file)
@@ -39,6 +39,7 @@
 #include "special.h"
 #include "label.h"
 #include "mkdir.h"
+#include "path-util.h"
 
 static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
         [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
index 713c1ca768276aa5185ef1eacb5d2176ce31962e..5513f6560c26be9e74d68ac2e5a8a548cd564d45 100644 (file)
@@ -31,6 +31,7 @@
 #include "cgroup-util.h"
 #include "log.h"
 #include "strv.h"
+#include "path-util.h"
 
 int cgroup_bonding_realize(CGroupBonding *b) {
         int r;
index 5d44039e5d24cd07c3e94ad2e49f1a3629b88578..e4080d569d7601bdaf1c75edd6bc69fa4e20866b 100644 (file)
@@ -33,6 +33,7 @@
 #include "util.h"
 #include "condition.h"
 #include "virt.h"
+#include "path-util.h"
 
 Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
         Condition *c;
index 88ce0cdd18719174de07cbe502152cdb7ae87421..f2bb656397a4aa85a20cc7b1517466272386523f 100644 (file)
@@ -30,6 +30,7 @@
 #include "unit-name.h"
 #include "dbus-device.h"
 #include "def.h"
+#include "path-util.h"
 
 static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = {
         [DEVICE_DEAD] = UNIT_INACTIVE,
index 99a7881f1cbbc81c03d2af9fe36ca5dfe87e7ec1..953cfa2baa30d795677a46cc0cd343b0ab65e9a1 100644 (file)
@@ -59,6 +59,7 @@
 #include "utmp-wtmp.h"
 #include "def.h"
 #include "loopback-setup.h"
+#include "path-util.h"
 
 /* This assumes there is a 'tty' group */
 #define TTY_MODE 0620
@@ -929,7 +930,7 @@ static void rename_process_from_path(const char *path) {
         /* This resulting string must fit in 10 chars (i.e. the length
          * of "/sbin/init") to look pretty in /bin/ps */
 
-        p = file_name_from_path(path);
+        p = path_get_file_name(path);
         if (isempty(p)) {
                 rename_process("(...)");
                 return;
@@ -1152,14 +1153,14 @@ int exec_spawn(ExecCommand *command,
                 }
 
                 if (!keep_stdout) {
-                        err = setup_output(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin);
+                        err = setup_output(context, socket_fd, path_get_file_name(command->path), apply_tty_stdin);
                         if (err < 0) {
                                 r = EXIT_STDOUT;
                                 goto fail_child;
                         }
                 }
 
-                err = setup_error(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin);
+                err = setup_error(context, socket_fd, path_get_file_name(command->path), apply_tty_stdin);
                 if (err < 0) {
                         r = EXIT_STDERR;
                         goto fail_child;
index d24919f998fb0fca4af5d5cb942bced68ce0499f..c2efec6657fa23fb33a708c8349a1e280c47a65d 100644 (file)
@@ -44,6 +44,7 @@
 #include "unit-name.h"
 #include "bus-errors.h"
 #include "utf8.h"
+#include "path-util.h"
 
 #ifndef HAVE_SYSV_COMPAT
 int config_parse_warn_compat(
@@ -2089,7 +2090,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
                 /* Add the file name we are currently looking at to
                  * the names of this unit, but only if it is a valid
                  * unit name. */
-                name = file_name_from_path(*filename);
+                name = path_get_file_name(*filename);
 
                 if (unit_name_is_valid(name, true)) {
 
index 62222e6c7a3654f28d6af2cdf57296902d353130..c6baf22ae510bb2401458082de18e5f84c8ce550 100644 (file)
@@ -65,6 +65,7 @@
 #include "virt.h"
 #include "watchdog.h"
 #include "cgroup-util.h"
+#include "path-util.h"
 
 /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
 #define GC_QUEUE_ENTRIES_MAX 16
@@ -785,7 +786,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DB
         }
 
         if (!name)
-                name = file_name_from_path(path);
+                name = path_get_file_name(path);
 
         t = unit_name_to_type(name);
 
index 6d37bbde3c8bf6cddf7da6dfead1b25f266e6682..56ce2ae71a01a72634020e2cfeeebafff69af573 100644 (file)
@@ -38,6 +38,7 @@
 #include "set.h"
 #include "strv.h"
 #include "mkdir.h"
+#include "path-util.h"
 
 #ifndef TTY_GID
 #define TTY_GID 5
index 8bdd462ea1cac0d8a478d7f1d56aaf0cf0371e14..01e9d78ad52a1ff29ae8abd588e10d900fd7513b 100644 (file)
@@ -32,6 +32,7 @@
 #include "log.h"
 #include "strv.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "mount-setup.h"
 #include "unit-name.h"
 #include "dbus-mount.h"
index 7ac6b381abb772870457a1fe7e3e628f009622d1..ba1edbe512c593fa2256e056a58bdf4fb2d39f85 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "strv.h"
 #include "util.h"
+#include "path-util.h"
 #include "namespace.h"
 #include "missing.h"
 
index 0f23f1494d1a859dec6a47536b216128c4c06de6..d6fedc736ae21aafd6dfd64b329ca5a087457155 100644 (file)
@@ -32,6 +32,7 @@
 #include "dbus-path.h"
 #include "special.h"
 #include "bus-errors.h"
+#include "path-util.h"
 
 static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
         [PATH_DEAD] = UNIT_INACTIVE,
index 40f1682784545ac2761241a1095716049a85f647..e9a7000bae067517994ed9a766154af04a95e69c 100644 (file)
@@ -38,6 +38,7 @@
 #include "bus-errors.h"
 #include "exit-status.h"
 #include "def.h"
+#include "path-util.h"
 #include "util.h"
 #include "utf8.h"
 
@@ -722,7 +723,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 goto finish;
                                         }
 
-                                        r = sysv_translate_facility(n, file_name_from_path(path), &m);
+                                        r = sysv_translate_facility(n, path_get_file_name(path), &m);
                                         free(n);
 
                                         if (r < 0)
@@ -772,7 +773,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 goto finish;
                                         }
 
-                                        r = sysv_translate_facility(n, file_name_from_path(path), &m);
+                                        r = sysv_translate_facility(n, path_get_file_name(path), &m);
 
                                         if (r < 0) {
                                                 log_error("[%s:%u] Failed to translate LSB dependency %s, ignoring: %s", path, line, n, strerror(-r));
index 60ea3cb25cfb4b794c1444829395ae9e4b893acf..37e85d5fbe4e1ae2a2635484e6fa93c2c5fac505 100644 (file)
@@ -37,6 +37,7 @@
 #include "load-fragment.h"
 #include "strv.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "unit-name.h"
 #include "dbus-socket.h"
 #include "missing.h"
index 3881d2831f8469dc21d6dedf711f5c9ab0de2ba0..a7e2126edde5780ca3bb1e1f880c7985a71078dd 100644 (file)
@@ -38,6 +38,7 @@
 #include "bus-errors.h"
 #include "exit-status.h"
 #include "def.h"
+#include "path-util.h"
 
 static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = UNIT_INACTIVE,
index 488e1e4a4d84941c2887ed64f1cb5922b5334705..71ad4b623d9ddcff8ef430cd72c5b4e7eea33a17 100644 (file)
@@ -32,6 +32,7 @@
 #include "list.h"
 #include "mount-setup.h"
 #include "umount.h"
+#include "path-util.h"
 #include "util.h"
 
 typedef struct MountPoint {
index fea75e88fe6fa4dbaafd0ea50588d73ef64c1d37..68948574eda83ed69a6f12abf3439e9dc316c407 100644 (file)
@@ -33,6 +33,7 @@
 #include "unit.h"
 #include "macro.h"
 #include "strv.h"
+#include "path-util.h"
 #include "load-fragment.h"
 #include "load-dropin.h"
 #include "log.h"
@@ -1670,7 +1671,7 @@ static const char *resolve_template(Unit *u, const char *name, const char*path,
         assert(name || path);
 
         if (!name)
-                name = file_name_from_path(path);
+                name = path_get_file_name(path);
 
         if (!unit_name_is_template(name)) {
                 *p = NULL;
@@ -2179,7 +2180,7 @@ static char *specifier_cgroup_root(char specifier, void *data, void *userdata) {
         if (specifier == 'r')
                 return strdup(u->manager->cgroup_hierarchy);
 
-        if (parent_of_path(u->manager->cgroup_hierarchy, &p) < 0)
+        if (path_get_parent(u->manager->cgroup_hierarchy, &p) < 0)
                 return strdup("");
 
         if (streq(p, "/")) {
@@ -2681,7 +2682,7 @@ UnitFileState unit_get_unit_file_state(Unit *u) {
         if (u->unit_file_state < 0 && u->fragment_path)
                 u->unit_file_state = unit_file_get_state(
                                 u->manager->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER,
-                                NULL, file_name_from_path(u->fragment_path));
+                                NULL, path_get_file_name(u->fragment_path));
 
         return u->unit_file_state;
 }
index 3ff0ddf2cc8b2285e554e3fc264716e2ef369327..6d4e965fe11be56eface30edb832816962058e69 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "log.h"
 #include "util.h"
+#include "path-util.h"
 #include "strv.h"
 #include "ask-password-api.h"
 #include "def.h"
index 9d381e044cf77b636d6b2bccaea3251c51637a90..4f3f1b5ff393aede86ecc858503c642c53af545d 100644 (file)
@@ -30,6 +30,7 @@
 #include "journal-file.h"
 #include "hashmap.h"
 #include "list.h"
+#include "path-util.h"
 #include "lookup3.h"
 #include "compress.h"
 #include "journal-internal.h"
@@ -765,7 +766,7 @@ _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) {
                      bid, (unsigned long long) le64toh(o->entry.monotonic),
                      (unsigned long long) le64toh(o->entry.realtime),
                      (unsigned long long) le64toh(o->entry.xor_hash),
-                     file_name_from_path(j->current_file->path)) < 0)
+                     path_get_file_name(j->current_file->path)) < 0)
                 return -ENOMEM;
 
         return 1;
index a361b93dc76a0b011dc748a686ccf47ed89179db..9fc3a14317d3c60aa9000b65143ea893ed16fc55 100644 (file)
@@ -28,6 +28,7 @@
 #include "dbus-common.h"
 #include "strv.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "polkit.h"
 #include "special.h"
 
index e4eefd0def4af912054a0fce8cd35fd972c6e1a0..b5b801e5e09a84bcbaa8d9cb43391c66e0304366 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "util.h"
 #include "mkdir.h"
-
+#include "path-util.h"
 #include "logind-inhibit.h"
 
 Inhibitor* inhibitor_new(Manager *m, const char* id) {
@@ -46,7 +46,7 @@ Inhibitor* inhibitor_new(Manager *m, const char* id) {
                 return NULL;
         }
 
-        i->id = file_name_from_path(i->state_file);
+        i->id = path_get_file_name(i->state_file);
 
         if (hashmap_put(m->inhibitors, i->id, i) < 0) {
                 free(i->state_file);
index 1bae6f6e0780fb877ccdd64e72c6e6c6ad9279c4..06debf887a0da77d802d43c4c35dbd8914fa3efd 100644 (file)
@@ -31,6 +31,7 @@
 #include "logind-acl.h"
 #include "util.h"
 #include "mkdir.h"
+#include "path-util.h"
 
 Seat *seat_new(Manager *m, const char *id) {
         Seat *s;
@@ -48,7 +49,7 @@ Seat *seat_new(Manager *m, const char *id) {
                 return NULL;
         }
 
-        s->id = file_name_from_path(s->state_file);
+        s->id = path_get_file_name(s->state_file);
         s->manager = m;
 
         if (hashmap_put(m->seats, s->id, s) < 0) {
index e297d3feeba689880c2b01e51ffd8c0e31df79b2..475ebcaa5ea27265ba78839b98ffd0c1308ac054 100644 (file)
@@ -28,6 +28,7 @@
 #include "strv.h"
 #include "util.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "cgroup-util.h"
 #include "logind-session.h"
 
@@ -49,7 +50,7 @@ Session* session_new(Manager *m, User *u, const char *id) {
                 return NULL;
         }
 
-        s->id = file_name_from_path(s->state_file);
+        s->id = path_get_file_name(s->state_file);
 
         if (hashmap_put(m->sessions, s->id, s) < 0) {
                 free(s->state_file);
index b0edc33b8031c418d0b8e6a7dc599d45b1052231..bc1bbccff71593ebab87008f43f229aa035d3d1f 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "util.h"
 #include "sysfs-show.h"
+#include "path-util.h"
 
 static int show_sysfs_one(
                 struct udev *udev,
index 2a1f37bffcd50dca1a40bc3763e4f0827dc230e7..31e8b015df2d1895b7974f7d1d53873dc2735773 100644 (file)
@@ -50,6 +50,7 @@
 #include "missing.h"
 #include "cgroup-util.h"
 #include "strv.h"
+#include "path-util.h"
 #include "loopback-setup.h"
 
 static char *arg_directory = NULL;
@@ -524,7 +525,7 @@ static int setup_hostname(void) {
         char *hn;
         int r = 0;
 
-        hn = file_name_from_path(arg_directory);
+        hn = path_get_file_name(arg_directory);
         if (hn) {
                 hn = strdup(hn);
                 if (!hn)
index 35b71548a30d88a046424c779e495b58f504920f..ef68e506e5097da4628acad62cb5af547a800042 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "log.h"
 #include "util.h"
+#include "path-util.h"
 #include "set.h"
 #include "mount-setup.h"
 #include "exit-status.h"
index 19f87e4bc6c4289d88899feeda1aac310d35bc05..9003a1228e1443d920777fe4f1b22f83065b7db8 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "util.h"
 #include "macro.h"
+#include "path-util.h"
 #include "cgroup-util.h"
 #include "cgroup-show.h"
 
@@ -205,7 +206,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 }
 
                 if (last) {
-                        printf("%s\342\224\234 %s\n", prefix, file_name_from_path(last));
+                        printf("%s\342\224\234 %s\n", prefix, path_get_file_name(last));
 
                         if (!p1) {
                                 p1 = strappend(prefix, "\342\224\202 ");
@@ -230,7 +231,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                 show_cgroup_one_by_path(path, prefix, n_columns, !!last, kernel_threads);
 
         if (last) {
-                printf("%s\342\224\224 %s\n", prefix, file_name_from_path(last));
+                printf("%s\342\224\224 %s\n", prefix, path_get_file_name(last));
 
                 if (!p2) {
                         p2 = strappend(prefix, "  ");
index 1f310d31f0967b07b670d5cf866725459ff3213e..8d3bdce0f576fa2184cf317e4758259b1e22a9e2 100644 (file)
@@ -34,6 +34,7 @@
 #include "set.h"
 #include "macro.h"
 #include "util.h"
+#include "path-util.h"
 #include "strv.h"
 
 int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) {
@@ -673,7 +674,7 @@ int cg_delete(const char *controller, const char *path) {
         assert(controller);
         assert(path);
 
-        if ((r = parent_of_path(path, &parent)) < 0)
+        if ((r = path_get_parent(path, &parent)) < 0)
                 return r;
 
         r = cg_migrate_recursive(controller, path, parent, false, true);
index 019fadcf5ee5bb22f2c50ff8a63727362d67c603..487c9a5e6861f966f769185fa49adad1961de207 100644 (file)
@@ -33,6 +33,7 @@
 #include "missing.h"
 #include "log.h"
 #include "strv.h"
+#include "path-util.h"
 #include "hashmap.h"
 #include "conf-files.h"
 
@@ -69,7 +70,7 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) {
                         goto finish;
                 }
 
-                if (hashmap_put(h, file_name_from_path(p), p) <= 0) {
+                if (hashmap_put(h, path_get_file_name(p), p) <= 0) {
                         log_debug("Skip overridden file: %s.", p);
                         free(p);
                 }
@@ -85,7 +86,7 @@ static int base_cmp(const void *a, const void *b) {
 
         s1 = *(char * const *)a;
         s2 = *(char * const *)b;
-        return strcmp(file_name_from_path(s1), file_name_from_path(s2));
+        return strcmp(path_get_file_name(s1), path_get_file_name(s2));
 }
 
 int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs) {
@@ -137,7 +138,7 @@ int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
                 goto finish;
         }
 
-        if (!strv_path_canonicalize(dirs)) {
+        if (!path_strv_canonicalize(dirs)) {
                 r = -ENOMEM;
                 goto finish;
         }
index 30980a3ea228d0d213c6e7ae7464ec5655e7d940..65035e4c6a1873daac4688616b05092a7c916032 100644 (file)
@@ -31,6 +31,7 @@
 #include "strv.h"
 #include "log.h"
 #include "utf8.h"
+#include "path-util.h"
 
 int config_item_table_lookup(
                 void *table,
index a77dfc77e4a096dd698c564d5d18fd63d3dbb091..fc1bf9620705c5c6a13fcc58e8e6a63d75223d9e 100644 (file)
@@ -29,6 +29,7 @@
 #include "mkdir.h"
 #include "hashmap.h"
 #include "set.h"
+#include "path-util.h"
 #include "path-lookup.h"
 #include "strv.h"
 #include "unit-name.h"
@@ -283,7 +284,7 @@ static int remove_marked_symlinks_fd(
 
                         found =
                                 set_get(remove_symlinks_to, dest) ||
-                                set_get(remove_symlinks_to, file_name_from_path(dest));
+                                set_get(remove_symlinks_to, path_get_file_name(dest));
 
                         if (found) {
 
@@ -468,7 +469,7 @@ static int find_symlinks_fd(
                         if (path_is_absolute(name))
                                 found_dest = path_equal(dest, name);
                         else
-                                found_dest = streq(file_name_from_path(dest), name);
+                                found_dest = streq(path_get_file_name(dest), name);
 
                         free(dest);
 
@@ -754,7 +755,7 @@ int unit_file_link(
                 char *path, *fn;
                 struct stat st;
 
-                fn = file_name_from_path(*i);
+                fn = path_get_file_name(*i);
 
                 if (!path_is_absolute(*i) ||
                     !unit_name_is_valid_no_type(fn, true)) {
@@ -917,7 +918,7 @@ static int install_info_add(
         assert(name || path);
 
         if (!name)
-                name = file_name_from_path(path);
+                name = path_get_file_name(path);
 
         if (!unit_name_is_valid_no_type(name, true))
                 return -EINVAL;
@@ -1915,7 +1916,7 @@ int unit_file_get_list(
                         continue;
 
                 found:
-                        r = hashmap_put(h, file_name_from_path(f->path), f);
+                        r = hashmap_put(h, path_get_file_name(f->path), f);
                         if (r < 0) {
                                 free(f->path);
                                 free(f);
index bd38f0ba67987d3ff81979b1752c95ddabb5a7dc..2d7d42a40e7338a7f2ceb83266ab1399a5b5d34a 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "label.h"
 #include "util.h"
+#include "path-util.h"
 
 #ifdef HAVE_SELINUX
 #include <selinux/selinux.h>
index 1d95f7d1f83f5b4c64305e108366d7c430f8f45a..41ebc7f5b3e38c7eafe96437d262cb6067df2a65 100644 (file)
@@ -28,7 +28,7 @@
 #include "util.h"
 #include "mkdir.h"
 #include "strv.h"
-
+#include "path-util.h"
 #include "path-lookup.h"
 
 int user_config_home(char **config_home) {
@@ -165,7 +165,7 @@ static char** user_dirs(void) {
         strv_free(r);
         r = t;
 
-        if (!strv_path_make_absolute_cwd(r))
+        if (!path_strv_make_absolute_cwd(r))
             goto fail;
 
 finish:
@@ -191,7 +191,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
         /* First priority is whatever has been passed to us via env
          * vars */
         if ((e = getenv("SYSTEMD_UNIT_PATH")))
-                if (!(p->unit_path = split_path_and_make_absolute(e)))
+                if (!(p->unit_path = path_split_and_make_absolute(e)))
                         return -ENOMEM;
 
         if (strv_isempty(p->unit_path)) {
@@ -239,11 +239,11 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
         }
 
         if (p->unit_path)
-                if (!strv_path_canonicalize(p->unit_path))
+                if (!path_strv_canonicalize(p->unit_path))
                         return -ENOMEM;
 
         strv_uniq(p->unit_path);
-        strv_path_remove_empty(p->unit_path);
+        path_strv_remove_empty(p->unit_path);
 
         if (!strv_isempty(p->unit_path)) {
 
@@ -262,7 +262,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                 /* /etc/init.d/ compatibility does not matter to users */
 
                 if ((e = getenv("SYSTEMD_SYSVINIT_PATH")))
-                        if (!(p->sysvinit_path = split_path_and_make_absolute(e)))
+                        if (!(p->sysvinit_path = path_split_and_make_absolute(e)))
                                 return -ENOMEM;
 
                 if (strv_isempty(p->sysvinit_path)) {
@@ -275,7 +275,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                 }
 
                 if ((e = getenv("SYSTEMD_SYSVRCND_PATH")))
-                        if (!(p->sysvrcnd_path = split_path_and_make_absolute(e)))
+                        if (!(p->sysvrcnd_path = path_split_and_make_absolute(e)))
                                 return -ENOMEM;
 
                 if (strv_isempty(p->sysvrcnd_path)) {
@@ -288,18 +288,18 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal
                 }
 
                 if (p->sysvinit_path)
-                        if (!strv_path_canonicalize(p->sysvinit_path))
+                        if (!path_strv_canonicalize(p->sysvinit_path))
                                 return -ENOMEM;
 
                 if (p->sysvrcnd_path)
-                        if (!strv_path_canonicalize(p->sysvrcnd_path))
+                        if (!path_strv_canonicalize(p->sysvrcnd_path))
                                 return -ENOMEM;
 
                 strv_uniq(p->sysvinit_path);
                 strv_uniq(p->sysvrcnd_path);
 
-                strv_path_remove_empty(p->sysvinit_path);
-                strv_path_remove_empty(p->sysvrcnd_path);
+                path_strv_remove_empty(p->sysvinit_path);
+                path_strv_remove_empty(p->sysvrcnd_path);
 
                 if (!strv_isempty(p->sysvinit_path)) {
 
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
new file mode 100644 (file)
index 0000000..ccd7667
--- /dev/null
@@ -0,0 +1,371 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010-2012 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/statvfs.h>
+
+#include "macro.h"
+#include "util.h"
+#include "log.h"
+#include "strv.h"
+#include "path-util.h"
+
+bool path_is_absolute(const char *p) {
+        return p[0] == '/';
+}
+
+bool is_path(const char *p) {
+        return !!strchr(p, '/');
+}
+
+char *path_get_file_name(const char *p) {
+        char *r;
+
+        assert(p);
+
+        if ((r = strrchr(p, '/')))
+                return r + 1;
+
+        return (char*) p;
+}
+
+int path_get_parent(const char *path, char **_r) {
+        const char *e, *a = NULL, *b = NULL, *p;
+        char *r;
+        bool slash = false;
+
+        assert(path);
+        assert(_r);
+
+        if (!*path)
+                return -EINVAL;
+
+        for (e = path; *e; e++) {
+
+                if (!slash && *e == '/') {
+                        a = b;
+                        b = e;
+                        slash = true;
+                } else if (slash && *e != '/')
+                        slash = false;
+        }
+
+        if (*(e-1) == '/')
+                p = a;
+        else
+                p = b;
+
+        if (!p)
+                return -EINVAL;
+
+        if (p == path)
+                r = strdup("/");
+        else
+                r = strndup(path, p-path);
+
+        if (!r)
+                return -ENOMEM;
+
+        *_r = r;
+        return 0;
+}
+
+char **path_split_and_make_absolute(const char *p) {
+        char **l;
+        assert(p);
+
+        if (!(l = strv_split(p, ":")))
+                return NULL;
+
+        if (!path_strv_make_absolute_cwd(l)) {
+                strv_free(l);
+                return NULL;
+        }
+
+        return l;
+}
+
+char *path_make_absolute(const char *p, const char *prefix) {
+        assert(p);
+
+        /* Makes every item in the list an absolute path by prepending
+         * the prefix, if specified and necessary */
+
+        if (path_is_absolute(p) || !prefix)
+                return strdup(p);
+
+        return join(prefix, "/", p, NULL);
+}
+
+char *path_make_absolute_cwd(const char *p) {
+        char *cwd, *r;
+
+        assert(p);
+
+        /* Similar to path_make_absolute(), but prefixes with the
+         * current working directory. */
+
+        if (path_is_absolute(p))
+                return strdup(p);
+
+        if (!(cwd = get_current_dir_name()))
+                return NULL;
+
+        r = path_make_absolute(p, cwd);
+        free(cwd);
+
+        return r;
+}
+
+char **path_strv_make_absolute_cwd(char **l) {
+        char **s;
+
+        /* Goes through every item in the string list and makes it
+         * absolute. This works in place and won't rollback any
+         * changes on failure. */
+
+        STRV_FOREACH(s, l) {
+                char *t;
+
+                if (!(t = path_make_absolute_cwd(*s)))
+                        return NULL;
+
+                free(*s);
+                *s = t;
+        }
+
+        return l;
+}
+
+char **path_strv_canonicalize(char **l) {
+        char **s;
+        unsigned k = 0;
+        bool enomem = false;
+
+        if (strv_isempty(l))
+                return l;
+
+        /* Goes through every item in the string list and canonicalize
+         * the path. This works in place and won't rollback any
+         * changes on failure. */
+
+        STRV_FOREACH(s, l) {
+                char *t, *u;
+
+                t = path_make_absolute_cwd(*s);
+                free(*s);
+
+                if (!t) {
+                        enomem = true;
+                        continue;
+                }
+
+                errno = 0;
+                u = canonicalize_file_name(t);
+                free(t);
+
+                if (!u) {
+                        if (errno == ENOMEM || !errno)
+                                enomem = true;
+
+                        continue;
+                }
+
+                l[k++] = u;
+        }
+
+        l[k] = NULL;
+
+        if (enomem)
+                return NULL;
+
+        return l;
+}
+
+char **path_strv_remove_empty(char **l) {
+        char **f, **t;
+
+        if (!l)
+                return NULL;
+
+        for (f = t = l; *f; f++) {
+
+                if (dir_is_empty(*f) > 0) {
+                        free(*f);
+                        continue;
+                }
+
+                *(t++) = *f;
+        }
+
+        *t = NULL;
+        return l;
+}
+
+char *path_kill_slashes(char *path) {
+        char *f, *t;
+        bool slash = false;
+
+        /* Removes redundant inner and trailing slashes. Modifies the
+         * passed string in-place.
+         *
+         * ///foo///bar/ becomes /foo/bar
+         */
+
+        for (f = path, t = path; *f; f++) {
+
+                if (*f == '/') {
+                        slash = true;
+                        continue;
+                }
+
+                if (slash) {
+                        slash = false;
+                        *(t++) = '/';
+                }
+
+                *(t++) = *f;
+        }
+
+        /* Special rule, if we are talking of the root directory, a
+        trailing slash is good */
+
+        if (t == path && slash)
+                *(t++) = '/';
+
+        *t = 0;
+        return path;
+}
+
+bool path_startswith(const char *path, const char *prefix) {
+        assert(path);
+        assert(prefix);
+
+        if ((path[0] == '/') != (prefix[0] == '/'))
+                return false;
+
+        for (;;) {
+                size_t a, b;
+
+                path += strspn(path, "/");
+                prefix += strspn(prefix, "/");
+
+                if (*prefix == 0)
+                        return true;
+
+                if (*path == 0)
+                        return false;
+
+                a = strcspn(path, "/");
+                b = strcspn(prefix, "/");
+
+                if (a != b)
+                        return false;
+
+                if (memcmp(path, prefix, a) != 0)
+                        return false;
+
+                path += a;
+                prefix += b;
+        }
+}
+
+bool path_equal(const char *a, const char *b) {
+        assert(a);
+        assert(b);
+
+        if ((a[0] == '/') != (b[0] == '/'))
+                return false;
+
+        for (;;) {
+                size_t j, k;
+
+                a += strspn(a, "/");
+                b += strspn(b, "/");
+
+                if (*a == 0 && *b == 0)
+                        return true;
+
+                if (*a == 0 || *b == 0)
+                        return false;
+
+                j = strcspn(a, "/");
+                k = strcspn(b, "/");
+
+                if (j != k)
+                        return false;
+
+                if (memcmp(a, b, j) != 0)
+                        return false;
+
+                a += j;
+                b += k;
+        }
+}
+
+int path_is_mount_point(const char *t, bool allow_symlink) {
+        struct stat a, b;
+        char *parent;
+        int r;
+
+        if (allow_symlink)
+                r = stat(t, &a);
+        else
+                r = lstat(t, &a);
+
+        if (r < 0) {
+                if (errno == ENOENT)
+                        return 0;
+
+                return -errno;
+        }
+
+        r = path_get_parent(t, &parent);
+        if (r < 0)
+                return r;
+
+        r = lstat(parent, &b);
+        free(parent);
+
+        if (r < 0)
+                return -errno;
+
+        return a.st_dev != b.st_dev;
+}
+
+int path_is_read_only_fs(const char *path) {
+        struct statvfs st;
+
+        assert(path);
+
+        if (statvfs(path, &st) < 0)
+                return -errno;
+
+        return !!(st.f_flag & ST_RDONLY);
+}
diff --git a/src/shared/path-util.h b/src/shared/path-util.h
new file mode 100644 (file)
index 0000000..181b981
--- /dev/null
@@ -0,0 +1,46 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef foopathutilhfoo
+#define foopathutilhfoo
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010-2012 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "stdbool.h"
+
+bool is_path(const char *p);
+char **path_split_and_make_absolute(const char *p);
+char *path_get_file_name(const char *p);
+int path_get_parent(const char *path, char **parent);
+bool path_is_absolute(const char *p);
+char *path_make_absolute(const char *p, const char *prefix);
+char *path_make_absolute_cwd(const char *p);
+int path_parent(const char *path, char **parent);
+char *path_kill_slashes(char *path);
+bool path_startswith(const char *path, const char *prefix);
+bool path_equal(const char *a, const char *b);
+
+char **path_strv_make_absolute_cwd(char **l);
+char **path_strv_canonicalize(char **l);
+char **path_strv_remove_empty(char **l);
+
+int path_is_mount_point(const char *path, bool allow_symlink);
+int path_is_read_only_fs(const char *path);
+
+#endif
index 471b6dc2842719ac525bc6bcdd019909d70af1e4..7e65f8a691871218afe9a253068147cde8927460 100644 (file)
@@ -35,6 +35,7 @@
 #include "macro.h"
 #include "util.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "socket-util.h"
 #include "missing.h"
 
index 566cdc51cce4feb2204dafecf3e0b38dfc0aa6c3..e0a18d135793d433d14cf1ad12a843606090e08a 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include "path-util.h"
 #include "util.h"
 #include "unit-name.h"
 
index a055ce197ddf44881182d4e3b4d9da65fa4d6ab5..8a0b2a1b464f8f8b064185d18df579b0e6a88271 100644 (file)
@@ -55,7 +55,6 @@
 #include <glob.h>
 #include <grp.h>
 #include <sys/mman.h>
-#include <sys/statvfs.h>
 
 #include "macro.h"
 #include "util.h"
@@ -64,6 +63,7 @@
 #include "log.h"
 #include "strv.h"
 #include "label.h"
+#include "path-util.h"
 #include "exit-status.h"
 #include "hashmap.h"
 
@@ -486,21 +486,6 @@ char *split_quoted(const char *c, size_t *l, char **state) {
         return (char*) current;
 }
 
-char **split_path_and_make_absolute(const char *p) {
-        char **l;
-        assert(p);
-
-        if (!(l = strv_split(p, ":")))
-                return NULL;
-
-        if (!strv_path_make_absolute_cwd(l)) {
-                strv_free(l);
-                return NULL;
-        }
-
-        return l;
-}
-
 int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
         int r;
         FILE *f;
@@ -1313,187 +1298,6 @@ int readlink_and_canonicalize(const char *p, char **r) {
         return 0;
 }
 
-int parent_of_path(const char *path, char **_r) {
-        const char *e, *a = NULL, *b = NULL, *p;
-        char *r;
-        bool slash = false;
-
-        assert(path);
-        assert(_r);
-
-        if (!*path)
-                return -EINVAL;
-
-        for (e = path; *e; e++) {
-
-                if (!slash && *e == '/') {
-                        a = b;
-                        b = e;
-                        slash = true;
-                } else if (slash && *e != '/')
-                        slash = false;
-        }
-
-        if (*(e-1) == '/')
-                p = a;
-        else
-                p = b;
-
-        if (!p)
-                return -EINVAL;
-
-        if (p == path)
-                r = strdup("/");
-        else
-                r = strndup(path, p-path);
-
-        if (!r)
-                return -ENOMEM;
-
-        *_r = r;
-        return 0;
-}
-
-
-char *file_name_from_path(const char *p) {
-        char *r;
-
-        assert(p);
-
-        if ((r = strrchr(p, '/')))
-                return r + 1;
-
-        return (char*) p;
-}
-
-bool path_is_absolute(const char *p) {
-        assert(p);
-
-        return p[0] == '/';
-}
-
-bool is_path(const char *p) {
-
-        return !!strchr(p, '/');
-}
-
-char *path_make_absolute(const char *p, const char *prefix) {
-        assert(p);
-
-        /* Makes every item in the list an absolute path by prepending
-         * the prefix, if specified and necessary */
-
-        if (path_is_absolute(p) || !prefix)
-                return strdup(p);
-
-        return join(prefix, "/", p, NULL);
-}
-
-char *path_make_absolute_cwd(const char *p) {
-        char *cwd, *r;
-
-        assert(p);
-
-        /* Similar to path_make_absolute(), but prefixes with the
-         * current working directory. */
-
-        if (path_is_absolute(p))
-                return strdup(p);
-
-        if (!(cwd = get_current_dir_name()))
-                return NULL;
-
-        r = path_make_absolute(p, cwd);
-        free(cwd);
-
-        return r;
-}
-
-char **strv_path_make_absolute_cwd(char **l) {
-        char **s;
-
-        /* Goes through every item in the string list and makes it
-         * absolute. This works in place and won't rollback any
-         * changes on failure. */
-
-        STRV_FOREACH(s, l) {
-                char *t;
-
-                if (!(t = path_make_absolute_cwd(*s)))
-                        return NULL;
-
-                free(*s);
-                *s = t;
-        }
-
-        return l;
-}
-
-char **strv_path_canonicalize(char **l) {
-        char **s;
-        unsigned k = 0;
-        bool enomem = false;
-
-        if (strv_isempty(l))
-                return l;
-
-        /* Goes through every item in the string list and canonicalize
-         * the path. This works in place and won't rollback any
-         * changes on failure. */
-
-        STRV_FOREACH(s, l) {
-                char *t, *u;
-
-                t = path_make_absolute_cwd(*s);
-                free(*s);
-
-                if (!t) {
-                        enomem = true;
-                        continue;
-                }
-
-                errno = 0;
-                u = canonicalize_file_name(t);
-                free(t);
-
-                if (!u) {
-                        if (errno == ENOMEM || !errno)
-                                enomem = true;
-
-                        continue;
-                }
-
-                l[k++] = u;
-        }
-
-        l[k] = NULL;
-
-        if (enomem)
-                return NULL;
-
-        return l;
-}
-
-char **strv_path_remove_empty(char **l) {
-        char **f, **t;
-
-        if (!l)
-                return NULL;
-
-        for (f = t = l; *f; f++) {
-
-                if (dir_is_empty(*f) > 0) {
-                        free(*f);
-                        continue;
-                }
-
-                *(t++) = *f;
-        }
-
-        *t = NULL;
-        return l;
-}
-
 int reset_all_signal_handlers(void) {
         int sig;
 
@@ -1972,107 +1776,6 @@ char *bus_path_unescape(const char *f) {
         return r;
 }
 
-char *path_kill_slashes(char *path) {
-        char *f, *t;
-        bool slash = false;
-
-        /* Removes redundant inner and trailing slashes. Modifies the
-         * passed string in-place.
-         *
-         * ///foo///bar/ becomes /foo/bar
-         */
-
-        for (f = path, t = path; *f; f++) {
-
-                if (*f == '/') {
-                        slash = true;
-                        continue;
-                }
-
-                if (slash) {
-                        slash = false;
-                        *(t++) = '/';
-                }
-
-                *(t++) = *f;
-        }
-
-        /* Special rule, if we are talking of the root directory, a
-        trailing slash is good */
-
-        if (t == path && slash)
-                *(t++) = '/';
-
-        *t = 0;
-        return path;
-}
-
-bool path_startswith(const char *path, const char *prefix) {
-        assert(path);
-        assert(prefix);
-
-        if ((path[0] == '/') != (prefix[0] == '/'))
-                return false;
-
-        for (;;) {
-                size_t a, b;
-
-                path += strspn(path, "/");
-                prefix += strspn(prefix, "/");
-
-                if (*prefix == 0)
-                        return true;
-
-                if (*path == 0)
-                        return false;
-
-                a = strcspn(path, "/");
-                b = strcspn(prefix, "/");
-
-                if (a != b)
-                        return false;
-
-                if (memcmp(path, prefix, a) != 0)
-                        return false;
-
-                path += a;
-                prefix += b;
-        }
-}
-
-bool path_equal(const char *a, const char *b) {
-        assert(a);
-        assert(b);
-
-        if ((a[0] == '/') != (b[0] == '/'))
-                return false;
-
-        for (;;) {
-                size_t j, k;
-
-                a += strspn(a, "/");
-                b += strspn(b, "/");
-
-                if (*a == 0 && *b == 0)
-                        return true;
-
-                if (*a == 0 || *b == 0)
-                        return false;
-
-                j = strcspn(a, "/");
-                k = strcspn(b, "/");
-
-                if (j != k)
-                        return false;
-
-                if (memcmp(a, b, j) != 0)
-                        return false;
-
-                a += j;
-                b += k;
-        }
-}
-
 char *ascii_strlower(char *t) {
         char *p;
 
@@ -2986,36 +2689,6 @@ ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
         return n;
 }
 
-int path_is_mount_point(const char *t, bool allow_symlink) {
-        struct stat a, b;
-        char *parent;
-        int r;
-
-        if (allow_symlink)
-                r = stat(t, &a);
-        else
-                r = lstat(t, &a);
-
-        if (r < 0) {
-                if (errno == ENOENT)
-                        return 0;
-
-                return -errno;
-        }
-
-        r = parent_of_path(t, &parent);
-        if (r < 0)
-                return r;
-
-        r = lstat(parent, &b);
-        free(parent);
-
-        if (r < 0)
-                return -errno;
-
-        return a.st_dev != b.st_dev;
-}
-
 int parse_usec(const char *t, usec_t *usec) {
         static const struct {
                 const char *suffix;
@@ -4746,7 +4419,7 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
         if (!t)
                 return -ENOMEM;
 
-        fn = file_name_from_path(path);
+        fn = path_get_file_name(path);
         k = fn-path;
         memcpy(t, path, k);
         t[k] = '.';
@@ -4928,8 +4601,8 @@ int symlink_or_copy(const char *from, const char *to) {
         assert(from);
         assert(to);
 
-        if (parent_of_path(from, &pf) < 0 ||
-            parent_of_path(to, &pt) < 0) {
+        if (path_get_parent(from, &pf) < 0 ||
+            path_get_parent(to, &pt) < 0) {
                 r = -ENOMEM;
                 goto finish;
         }
@@ -4976,7 +4649,7 @@ int symlink_or_copy_atomic(const char *from, const char *to) {
         if (!t)
                 return -ENOMEM;
 
-        fn = file_name_from_path(to);
+        fn = path_get_file_name(to);
         k = fn-to;
         memcpy(t, to, k);
         t[k] = '.';
@@ -5218,7 +4891,7 @@ int in_search_path(const char *path, char **search) {
         char **i, *parent;
         int r;
 
-        r = parent_of_path(path, &parent);
+        r = path_get_parent(path, &parent);
         if (r < 0)
                 return r;
 
@@ -5857,17 +5530,6 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) {
         return 0;
 }
 
-int path_is_read_only_fs(const char *path) {
-        struct statvfs st;
-
-        assert(path);
-
-        if (statvfs(path, &st) < 0)
-                return -errno;
-
-        return !!(st.f_flag & ST_RDONLY);
-}
-
 int getenv_for_pid(pid_t pid, const char *field, char **_value) {
         char path[sizeof("/proc/")-1+10+sizeof("/environ")], *value = NULL;
         int r;
index cca611836370778bc751e081be94540a96a6a983..59a69a898a3b47281de7e4a7d631a7a41b40c0c6 100644 (file)
@@ -122,10 +122,6 @@ static inline const char *strna(const char *s) {
         return s ? s : "n/a";
 }
 
-static inline bool is_path_absolute(const char *p) {
-        return *p == '/';
-}
-
 static inline bool isempty(const char *p) {
         return !p || !p[0];
 }
@@ -205,8 +201,6 @@ char *split_quoted(const char *c, size_t *l, char **state);
 #define FOREACH_WORD_QUOTED(word, length, s, state)                     \
         for ((state) = NULL, (word) = split_quoted((s), &(length), &(state)); (word); (word) = split_quoted((s), &(length), &(state)))
 
-char **split_path_and_make_absolute(const char *p);
-
 pid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
 int get_starttime_of_pid(pid_t pid, unsigned long long *st);
 
@@ -229,17 +223,6 @@ int readlink_malloc(const char *p, char **r);
 int readlink_and_make_absolute(const char *p, char **r);
 int readlink_and_canonicalize(const char *p, char **r);
 
-char *file_name_from_path(const char *p);
-bool is_path(const char *p);
-
-bool path_is_absolute(const char *p);
-char *path_make_absolute(const char *p, const char *prefix);
-char *path_make_absolute_cwd(const char *p);
-
-char **strv_path_make_absolute_cwd(char **l);
-char **strv_path_canonicalize(char **l);
-char **strv_path_remove_empty(char **l);
-
 int reset_all_signal_handlers(void);
 
 char *strstrip(char *s);
@@ -248,8 +231,6 @@ char *truncate_nl(char *s);
 
 char *file_in_same_dir(const char *path, const char *filename);
 
-int parent_of_path(const char *path, char **parent);
-
 int rmdir_parents(const char *path, const char *stop);
 
 int get_process_comm(pid_t pid, char **name);
@@ -273,11 +254,6 @@ char *xescape(const char *s, const char *bad);
 char *bus_path_escape(const char *s);
 char *bus_path_unescape(const char *s);
 
-char *path_kill_slashes(char *path);
-
-bool path_startswith(const char *path, const char *prefix);
-bool path_equal(const char *a, const char *b);
-
 char *ascii_strlower(char *path);
 
 bool dirent_is_file(const struct dirent *de);
@@ -351,9 +327,6 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
 ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
 ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
 
-int path_is_mount_point(const char *path, bool allow_symlink);
-int path_is_read_only_fs(const char *path);
-
 bool is_device_path(const char *path);
 
 int dir_is_empty(const char *path);
index 6bba325d3ecc25ebcaf9fde3e621889084d10887..046fb584fb08cb18506f89ffc1d0a68eca03f313 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/poll.h>
 
 #include "macro.h"
+#include "path-util.h"
 #include "utmp-wtmp.h"
 
 int utmp_get_runlevel(int *runlevel, int *previous) {
@@ -224,7 +225,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line
         strncpy(store.ut_id, sanitize_id(id), sizeof(store.ut_id));
 
         if (line)
-                strncpy(store.ut_line, file_name_from_path(line), sizeof(store.ut_line));
+                strncpy(store.ut_line, path_get_file_name(line), sizeof(store.ut_line));
 
         return write_entry_both(&store);
 }
index 575095f8126a9bc283fad9bf529333d6840166e4..72a74f9e44340126453013eaa15768aef326b507 100644 (file)
@@ -31,6 +31,7 @@
 #include "strv.h"
 #include "util.h"
 #include "strv.h"
+#include "path-util.h"
 #include "conf-files.h"
 
 #define PROC_SYS_PREFIX "/proc/sys/"
index c08d80912a3ad70dab44371bdeceecdcce97aa28..acede4e765959ce32a2d136b6cc911de2e74b6ab 100644 (file)
@@ -45,6 +45,7 @@
 #include "utmp-wtmp.h"
 #include "special.h"
 #include "initreq.h"
+#include "path-util.h"
 #include "strv.h"
 #include "dbus-common.h"
 #include "cgroup-show.h"
@@ -61,6 +62,7 @@
 #include "spawn-polkit-agent.h"
 #include "install.h"
 #include "logs-show.h"
+#include "path-util.h"
 
 static const char *arg_type = NULL;
 static char **arg_property = NULL;
@@ -560,7 +562,7 @@ static int compare_unit_file_list(const void *a, const void *b) {
                         return r;
         }
 
-        return strcasecmp(file_name_from_path(u->path), file_name_from_path(v->path));
+        return strcasecmp(path_get_file_name(u->path), path_get_file_name(v->path));
 }
 
 static bool output_show_unit_file(const UnitFileList *u) {
@@ -579,7 +581,7 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) {
                 if (!output_show_unit_file(u))
                         continue;
 
-                max_id_len = MAX(max_id_len, strlen(file_name_from_path(u->path)));
+                max_id_len = MAX(max_id_len, strlen(path_get_file_name(u->path)));
                 state_cols = MAX(state_cols, strlen(unit_file_state_to_string(u->state)));
         }
 
@@ -616,7 +618,7 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) {
                 } else
                         on = off = "";
 
-                id = file_name_from_path(u->path);
+                id = path_get_file_name(u->path);
 
                 e = arg_full ? NULL : ellipsize(id, id_cols, 33);
 
@@ -3721,7 +3723,7 @@ static int enable_sysv_units(char **args) {
                 if (!isempty(arg_root))
                         argv[c++] = q = strappend("--root=", arg_root);
 
-                argv[c++] = file_name_from_path(p);
+                argv[c++] = path_get_file_name(p);
                 argv[c++] =
                         streq(verb, "enable") ? "on" :
                         streq(verb, "disable") ? "off" : "--level=5";
index e742632032ccb435b225c8467d7f29df64bd45bc..6d64a4e47fd3fae977da00cc9e521fa222cec1c7 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include "cgroup-util.h"
+#include "path-util.h"
 #include "util.h"
 #include "log.h"
 
index 709974f9e5ff9e0f67b54e1a760e7e4f16c723bf..2c1b9efcb80d01761fbebd849a0a768df63fe3ec 100644 (file)
@@ -25,6 +25,7 @@
 #include <fcntl.h>
 
 #include "util.h"
+#include "path-util.h"
 #include "install.h"
 
 static void dump_changes(UnitFileChange *c, unsigned n) {
@@ -57,7 +58,7 @@ int main(int argc, char* argv[]) {
         HASHMAP_FOREACH(p, h, i) {
                 UnitFileState s;
 
-                s = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(p->path));
+                s = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(p->path));
 
                 assert_se(p->state == s);
 
@@ -175,7 +176,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_ENABLED);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_ENABLED);
 
         log_error("disable files2");
         changes = NULL;
@@ -187,7 +188,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == _UNIT_FILE_STATE_INVALID);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID);
 
         log_error("link files2");
         changes = NULL;
@@ -199,7 +200,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_LINKED);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_LINKED);
 
         log_error("disable files2");
         changes = NULL;
@@ -211,7 +212,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == _UNIT_FILE_STATE_INVALID);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID);
 
         log_error("link files2");
         changes = NULL;
@@ -223,7 +224,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_LINKED);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_LINKED);
 
         log_error("reenable files2");
         changes = NULL;
@@ -235,7 +236,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_ENABLED);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_ENABLED);
 
         log_error("disable files2");
         changes = NULL;
@@ -247,7 +248,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == _UNIT_FILE_STATE_INVALID);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID);
         log_error("preset files");
         changes = NULL;
         n_changes = 0;
@@ -258,7 +259,7 @@ int main(int argc, char* argv[]) {
         dump_changes(changes, n_changes);
         unit_file_changes_free(changes, n_changes);
 
-        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files[0])) == UNIT_FILE_ENABLED);
+        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files[0])) == UNIT_FILE_ENABLED);
 
         return 0;
 }
index 16666ce5a6cdf9b986c6c3c558b1294bd78e23f1..235617853b592e1a8b99c8343df2a993b203d674 100644 (file)
@@ -42,6 +42,7 @@
 #include "log.h"
 #include "util.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "strv.h"
 #include "label.h"
 #include "set.h"
index 9fbd7f5fb2eda43c3ead712e2ea0bd8ad2ec45f2..de843b437e8bc04ec2a8868040f9f015dcdd2da7 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "util.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "conf-parser.h"
 #include "utmp-wtmp.h"
 #include "socket-util.h"
index 45a611474de6cf03da7b51d7a8a4ca9a182ab8d5..930c4770fec9d54990c4cd3d556059044a0bd703 100644 (file)
@@ -31,6 +31,7 @@
 #include <time.h>
 
 #include "udev.h"
+#include "path-util.h"
 #include "conf-files.h"
 
 #define PREALLOC_TOKEN          2048
@@ -1764,7 +1765,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
                 log_error("failed to build config directory array");
                 return NULL;
         }
-        if (!strv_path_canonicalize(rules->dirs)) {
+        if (!path_strv_canonicalize(rules->dirs)) {
                 log_error("failed to canonicalize config directories\n");
                 return NULL;
         }