diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-06 21:29:55 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-06 21:29:55 -0500 |
commit | 2b6bf07dd23bb467099d213c97b3875c5e453491 (patch) | |
tree | 2127e24f28714b48f6c00e92eaec351bcb57e5d5 | |
parent | f4336098941f94d23f2f6c79bc8d055a0907c392 (diff) |
Get rid of our reimplementation of basename
The only problem is that libgen.h #defines basename to point to it's
own broken implementation instead of the GNU one. This can be fixed
by #undefining basename.
-rw-r--r-- | src/core/execute.c | 7 | ||||
-rw-r--r-- | src/core/load-fragment.c | 2 | ||||
-rw-r--r-- | src/core/manager.c | 2 | ||||
-rw-r--r-- | src/core/service.c | 4 | ||||
-rw-r--r-- | src/core/unit.c | 4 | ||||
-rw-r--r-- | src/delta/delta.c | 8 | ||||
-rw-r--r-- | src/journal/journalctl.c | 2 | ||||
-rw-r--r-- | src/locale/localectl.c | 2 | ||||
-rw-r--r-- | src/login/logind-inhibit.c | 2 | ||||
-rw-r--r-- | src/login/logind-seat.c | 2 | ||||
-rw-r--r-- | src/login/logind-session.c | 2 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 2 | ||||
-rw-r--r-- | src/shared/cgroup-show.c | 4 | ||||
-rw-r--r-- | src/shared/conf-files.c | 4 | ||||
-rw-r--r-- | src/shared/install.c | 16 | ||||
-rw-r--r-- | src/shared/path-util.c | 12 | ||||
-rw-r--r-- | src/shared/path-util.h | 1 | ||||
-rw-r--r-- | src/shared/util.c | 7 | ||||
-rw-r--r-- | src/shared/utmp-wtmp.c | 2 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 10 | ||||
-rw-r--r-- | src/test/test-install.c | 18 | ||||
-rw-r--r-- | src/test/test-path-util.c | 8 |
22 files changed, 55 insertions, 66 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index a0d63a41f9..55b8bb5bea 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -41,6 +41,7 @@ #include <linux/seccomp-bpf.h> #include <glob.h> #include <libgen.h> +#undef basename #ifdef HAVE_PAM #include <security/pam_appl.h> @@ -908,7 +909,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 = path_get_file_name(path); + p = basename(path); if (isempty(p)) { rename_process("(...)"); return; @@ -1197,13 +1198,13 @@ int exec_spawn(ExecCommand *command, goto fail_child; } - err = setup_output(context, STDOUT_FILENO, socket_fd, path_get_file_name(command->path), unit_id, apply_tty_stdin); + err = setup_output(context, STDOUT_FILENO, socket_fd, basename(command->path), unit_id, apply_tty_stdin); if (err < 0) { r = EXIT_STDOUT; goto fail_child; } - err = setup_output(context, STDERR_FILENO, socket_fd, path_get_file_name(command->path), unit_id, apply_tty_stdin); + err = setup_output(context, STDERR_FILENO, socket_fd, basename(command->path), unit_id, apply_tty_stdin); if (err < 0) { r = EXIT_STDERR; goto fail_child; diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index d43d1b4162..99cf20dcce 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2431,7 +2431,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 = path_get_file_name(*filename); + name = basename(*filename); if (unit_name_is_valid(name, true)) { diff --git a/src/core/manager.c b/src/core/manager.c index 0a3e840de7..f06df54d91 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -1078,7 +1078,7 @@ int manager_load_unit_prepare( return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path); if (!name) - name = path_get_file_name(path); + name = basename(path); t = unit_name_to_type(name); diff --git a/src/core/service.c b/src/core/service.c index 530a305b4b..702443d215 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -790,7 +790,7 @@ static int service_load_sysv_path(Service *s, const char *path) { goto finish; } - r = sysv_translate_facility(n, path_get_file_name(path), &m); + r = sysv_translate_facility(n, basename(path), &m); free(n); if (r < 0) @@ -842,7 +842,7 @@ static int service_load_sysv_path(Service *s, const char *path) { goto finish; } - r = sysv_translate_facility(n, path_get_file_name(path), &m); + r = sysv_translate_facility(n, basename(path), &m); if (r < 0) { log_error_unit(u->id, "[%s:%u] Failed to translate LSB dependency %s, ignoring: %s", diff --git a/src/core/unit.c b/src/core/unit.c index 81d21622d0..6458c7f570 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1848,7 +1848,7 @@ static const char *resolve_template(Unit *u, const char *name, const char*path, assert(p); if (!name) - name = path_get_file_name(path); + name = basename(path); if (!unit_name_is_template(name)) { *p = NULL; @@ -2615,7 +2615,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 == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, - NULL, path_get_file_name(u->fragment_path)); + NULL, basename(u->fragment_path)); return u->unit_file_state; } diff --git a/src/delta/delta.c b/src/delta/delta.c index 4aaf1dfb14..0785e7b5e7 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -251,7 +251,7 @@ static int enumerate_dir_d(Hashmap *top, Hashmap *bottom, Hashmap *drops, const if (!p) return -ENOMEM; - k = hashmap_put(h, path_get_file_name(p), p); + k = hashmap_put(h, basename(p), p); if (k < 0) { free(p); if (k != -EEXIST) @@ -303,7 +303,7 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, Hashmap *drops, const ch path_kill_slashes(p); - k = hashmap_put(top, path_get_file_name(p), p); + k = hashmap_put(top, basename(p), p); if (k >= 0) { p = strdup(p); if (!p) @@ -313,8 +313,8 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, Hashmap *drops, const ch return k; } - free(hashmap_remove(bottom, path_get_file_name(p))); - k = hashmap_put(bottom, path_get_file_name(p), p); + free(hashmap_remove(bottom, basename(p))); + k = hashmap_put(bottom, basename(p), p); if (k < 0) { free(p); return k; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index c44be745b8..f74dde9c48 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -658,7 +658,7 @@ static int add_matches(sd_journal *j, char **args) { if (executable_is_script(path, &interpreter) > 0) { _cleanup_free_ char *comm; - comm = strndup(path_get_file_name(path), 15); + comm = strndup(basename(path), 15); if (!comm) return log_oom(); diff --git a/src/locale/localectl.c b/src/locale/localectl.c index 76a53f6fff..b0abe7b051 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -415,7 +415,7 @@ static int nftw_cb( !endswith(fpath, ".map.gz")) return 0; - p = strdup(path_get_file_name(fpath)); + p = strdup(basename(fpath)); if (!p) return log_oom(); diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 35e1abd729..ec6a722ce3 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -45,7 +45,7 @@ Inhibitor* inhibitor_new(Manager *m, const char* id) { return NULL; } - i->id = path_get_file_name(i->state_file); + i->id = basename(i->state_file); if (hashmap_put(m->inhibitors, i->id, i) < 0) { free(i->state_file); diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index b1a5ec30ef..c73860478d 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -51,7 +51,7 @@ Seat *seat_new(Manager *m, const char *id) { return NULL; } - s->id = path_get_file_name(s->state_file); + s->id = basename(s->state_file); s->manager = m; if (hashmap_put(m->seats, s->id, s) < 0) { diff --git a/src/login/logind-session.c b/src/login/logind-session.c index beaa60124f..10ea526517 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -79,7 +79,7 @@ Session* session_new(Manager *m, const char *id) { return NULL; } - s->id = path_get_file_name(s->state_file); + s->id = basename(s->state_file); if (hashmap_put(m->sessions, s->id, s) < 0) { hashmap_free(s->devices); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index eef0e9a281..583912f57c 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1096,7 +1096,7 @@ int main(int argc, char *argv[]) { path_kill_slashes(arg_directory); if (!arg_machine) { - arg_machine = strdup(path_get_file_name(arg_directory)); + arg_machine = strdup(basename(arg_directory)); if (!arg_machine) { log_oom(); goto finish; diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index ce02b76e36..ee14cee4ed 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -178,7 +178,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns if (last) { printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_BRANCH), - path_get_file_name(last)); + basename(last)); if (!p1) { p1 = strappend(prefix, draw_special_char(DRAW_TREE_VERT)); @@ -202,7 +202,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns if (last) { printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT), - path_get_file_name(last)); + basename(last)); if (!p2) { p2 = strappend(prefix, " "); diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c index ed4070c662..92204a6a09 100644 --- a/src/shared/conf-files.c +++ b/src/shared/conf-files.c @@ -71,7 +71,7 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char if (!p) return -ENOMEM; - r = hashmap_put(h, path_get_file_name(p), p); + r = hashmap_put(h, basename(p), p); if (r == -EEXIST) { log_debug("Skipping overridden file: %s.", p); free(p); @@ -92,7 +92,7 @@ static int base_cmp(const void *a, const void *b) { s1 = *(char * const *)a; s2 = *(char * const *)b; - return strcmp(path_get_file_name(s1), path_get_file_name(s2)); + return strcmp(basename(s1), basename(s2)); } static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) { diff --git a/src/shared/install.c b/src/shared/install.c index 100ed69744..17e8a7508e 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -276,10 +276,10 @@ static int remove_marked_symlinks_fd( found = set_get(remove_symlinks_to, dest) || - set_get(remove_symlinks_to, path_get_file_name(dest)); + set_get(remove_symlinks_to, basename(dest)); if (unit_name_is_instance(p)) - found = found && strv_contains(files, path_get_file_name(p)); + found = found && strv_contains(files, basename(p)); if (found) { @@ -451,7 +451,7 @@ static int find_symlinks_fd( if (path_is_absolute(name)) found_dest = path_equal(dest, name); else - found_dest = streq(path_get_file_name(dest), name); + found_dest = streq(basename(dest), name); if (found_path && found_dest) { _cleanup_free_ char *t = NULL; @@ -718,7 +718,7 @@ int unit_file_link( char *fn; struct stat st; - fn = path_get_file_name(*i); + fn = basename(*i); if (!path_is_absolute(*i) || !unit_name_is_valid(fn, true)) { @@ -861,7 +861,7 @@ static int install_info_add( assert(name || path); if (!name) - name = path_get_file_name(path); + name = basename(path); if (!unit_name_is_valid(name, true)) return -EINVAL; @@ -1429,7 +1429,7 @@ static int install_context_mark_for_removal( char *unit_file; if (i->path) { - unit_file = path_get_file_name(i->path); + unit_file = basename(i->path); if (unit_name_is_instance(unit_file)) /* unit file named as instance exists, thus all symlinks @@ -1647,7 +1647,7 @@ int unit_file_get_default( else if (r < 0) return r; else - n = strdup(path_get_file_name(tmp)); + n = strdup(basename(tmp)); if (!n) return -ENOMEM; @@ -2007,7 +2007,7 @@ int unit_file_get_list( f->state = UNIT_FILE_STATIC; found: - r = hashmap_put(h, path_get_file_name(f->path), f); + r = hashmap_put(h, basename(f->path), f); if (r < 0) return r; f = NULL; /* prevent cleanup */ diff --git a/src/shared/path-util.c b/src/shared/path-util.c index 6c4efbfd94..3843861779 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -45,18 +45,6 @@ bool is_path(const char *p) { return !!strchr(p, '/'); } -char *path_get_file_name(const char *p) { - char *r; - - assert(p); - - r = strrchr(p, '/'); - if (r) - 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; diff --git a/src/shared/path-util.h b/src/shared/path-util.h index 42b4189d77..1098f6540c 100644 --- a/src/shared/path-util.h +++ b/src/shared/path-util.h @@ -34,7 +34,6 @@ bool is_path(const char *p) _pure_; char** path_split_and_make_absolute(const char *p); -char* path_get_file_name(const char *p) _pure_; int path_get_parent(const char *path, char **parent); bool path_is_absolute(const char *p) _pure_; char* path_make_absolute(const char *p, const char *prefix); diff --git a/src/shared/util.c b/src/shared/util.c index c71293106f..9c07392c59 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -59,6 +59,7 @@ #include <langinfo.h> #include <locale.h> #include <libgen.h> +#undef basename #include "macro.h" #include "util.h" @@ -3961,8 +3962,8 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) { if (!t) return -ENOMEM; - fn = path_get_file_name(path); - k = fn-path; + fn = basename(path); + k = fn - path; memcpy(t, path, k); t[k] = '.'; stpcpy(stpcpy(t+k+1, fn), "XXXXXX"); @@ -4147,7 +4148,7 @@ int symlink_atomic(const char *from, const char *to) { if (!t) return -ENOMEM; - fn = path_get_file_name(to); + fn = basename(to); k = fn-to; memcpy(t, to, k); t[k] = '.'; diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 5d88405e13..4a3a3f4dd3 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -216,7 +216,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, path_get_file_name(line), sizeof(store.ut_line)); + strncpy(store.ut_line, basename(line), sizeof(store.ut_line)); return write_entry_both(&store); } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 6b6cb3d1d8..c6ebf9b011 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -980,7 +980,7 @@ static int compare_unit_file_list(const void *a, const void *b) { return r; } - return strcasecmp(path_get_file_name(u->path), path_get_file_name(v->path)); + return strcasecmp(basename(u->path), basename(v->path)); } static bool output_show_unit_file(const UnitFileList *u) { @@ -1000,7 +1000,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(path_get_file_name(u->path))); + max_id_len = MAX(max_id_len, strlen(basename(u->path))); state_cols = MAX(state_cols, strlen(unit_file_state_to_string(u->state))); } @@ -1041,7 +1041,7 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { } else on = off = ""; - id = path_get_file_name(u->path); + id = basename(u->path); e = arg_full ? NULL : ellipsize(id, id_cols, 33); @@ -2688,7 +2688,7 @@ static void print_status_info( last = ! (*(dropin + 1) && startswith(*(dropin + 1), dir)); - printf("%s%s", path_get_file_name(*dropin), last ? "\n" : ", "); + printf("%s%s", basename(*dropin), last ? "\n" : ", "); } } @@ -4404,7 +4404,7 @@ static int enable_sysv_units(const char *verb, char **args) { if (!isempty(arg_root)) argv[c++] = q = strappend("--root=", arg_root); - argv[c++] = path_get_file_name(p); + argv[c++] = basename(p); argv[c++] = streq(verb, "enable") ? "on" : streq(verb, "disable") ? "off" : "--level=5"; diff --git a/src/test/test-install.c b/src/test/test-install.c index 2c1b9efcb8..2087d52994 100644 --- a/src/test/test-install.c +++ b/src/test/test-install.c @@ -58,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, path_get_file_name(p->path)); + s = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(p->path)); assert_se(p->state == s); @@ -176,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, path_get_file_name(files2[0])) == UNIT_FILE_ENABLED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_ENABLED); log_error("disable files2"); changes = NULL; @@ -188,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, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == _UNIT_FILE_STATE_INVALID); log_error("link files2"); changes = NULL; @@ -200,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, path_get_file_name(files2[0])) == UNIT_FILE_LINKED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_LINKED); log_error("disable files2"); changes = NULL; @@ -212,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, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == _UNIT_FILE_STATE_INVALID); log_error("link files2"); changes = NULL; @@ -224,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, path_get_file_name(files2[0])) == UNIT_FILE_LINKED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_LINKED); log_error("reenable files2"); changes = NULL; @@ -236,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, path_get_file_name(files2[0])) == UNIT_FILE_ENABLED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == UNIT_FILE_ENABLED); log_error("disable files2"); changes = NULL; @@ -248,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, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0])) == _UNIT_FILE_STATE_INVALID); log_error("preset files"); changes = NULL; n_changes = 0; @@ -259,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, path_get_file_name(files[0])) == UNIT_FILE_ENABLED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files[0])) == UNIT_FILE_ENABLED); return 0; } diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index ed3b315a61..bec2a83611 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -50,10 +50,10 @@ static void test_path(void) { assert_se(is_path("a/b")); assert_se(!is_path(".")); - assert_se(streq(path_get_file_name("./aa/bb/../file.da."), "file.da.")); - assert_se(streq(path_get_file_name("/aa///.file"), ".file")); - assert_se(streq(path_get_file_name("/aa///file..."), "file...")); - assert_se(streq(path_get_file_name("file.../"), "")); + assert_se(streq(basename("./aa/bb/../file.da."), "file.da.")); + assert_se(streq(basename("/aa///.file"), ".file")); + assert_se(streq(basename("/aa///file..."), "file...")); + assert_se(streq(basename("file.../"), "")); #define test_parent(x, y) { \ char _cleanup_free_ *z = NULL; \ |