Commit graph

32 commits

Author SHA1 Message Date
Tanu Kaskinen 7cb9c51ce8 path-util: add path_make_relative()
In user_dirs() in path-lookup.c, I want to replace this:
        symlink("../../../.config/systemd/user", data_home);
with
        symlink(config_home, data_home);
to avoid hardcoding .config when XDG_CONFIG_HOME is set.

The problem is that config_home is an absolute path, and it's better
to make the symlink relative. path_make_relative() is an utility
function that converts an absolute path into a relative one.
2014-05-16 18:47:34 +02:00
Zbigniew Jędrzejewski-Szmek 12ed81d9c8 Make systemctl --root look for files in the proper places
Running systemctl enable/disable/set-default/... with the --root
option under strace reveals that it accessed various files and
directories in the main fs, and not underneath the specified root.
This can lead to correct results only when the layout and
configuration in the container are identical, which often is not the
case. Fix this by adding the specified root to all file access
operations.

This patch does not handle some corner cases: symlinks which point
outside of the specified root might be interpreted differently than
they would be by the kernel if the specified root was the real root.
But systemctl does not create such symlinks by itself, and I think
this is enough of a corner case not to be worth the additional
complexity of reimplementing link chasing in systemd.

Also, simplify the code in a few places and remove an hypothetical
memory leak on error.
2014-05-15 15:29:58 +02:00
Lennart Poettering 21749924e1 util: make sure all our name_to_handle_at() code makes use of file_handle_union 2014-04-24 08:12:20 +02:00
Dave Reisner dbb9401dba condense assignment and path_kill_slashes calls 2014-04-21 09:52:08 -04:00
Zbigniew Jędrzejewski-Szmek b972115c97 path-util: also check for existence of binary when given absolute path
In contrast to a filename-only argument, find_binary() did not
actually check if an path exists, allowing the code to fail later on.
This was OK, but it seems nicer to treat both paths identically.

Also take advantage of path_make_absolute_cwd doing strdup() by itself
if necessary to simplify.
2014-04-12 17:23:13 -04:00
Mike Gilbert eb66db55fc fsck: Search for fsck.type in PATH
Modifies find_binary() to accept NULL in the second argument.

fsck.type lookup logic moved to new fsck_exists() function, with a test.
2014-04-12 17:23:13 -04:00
Michael Marineau 112cfb1814 shared: include root when canonicalizing conf paths
The conf_files_list family accepts an alternate root path to prefix all
directories in the list but path_strv_canonicalize_uniq doesn't use it.
This results in the suspicious behavior of resolving directory symlinks
based on the contents of / instead of the alternate root.

This adds a prefix argument to path_strv_canonicalize which will now
prepend the prefix, if given, to every path in the list. To avoid
answering what a relative path means when called with a root prefix
path_strv_canonicalize is now path_strv_canonicalize_absolute and only
considers absolute paths. Fortunately all users of already call
path_strv_canonicalize with a list of absolute paths.
2014-02-14 00:58:00 +01:00
Zbigniew Jędrzejewski-Szmek 2ad8416dd0 No need to canonicalize fixed paths 2014-01-08 22:15:27 -05:00
Lennart Poettering 9f6445e34a log: log_error() and friends add a newline after each line anyway, so avoid including it in the log strings 2013-12-24 16:39:37 +01:00
Zbigniew Jędrzejewski-Szmek 2b6bf07dd2 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.
2013-12-06 21:29:55 -05:00
Lennart Poettering 4087cb9e8f path-util: paths_check_timestamp() opimizations 2013-11-06 17:34:54 +01:00
Tom Gundersen 97f2d76d4f path_check_timestamp: only keep the most recent timestamp
There is no point in keeping one timestamp for each directory, as we only
ever care about the most recent one.
2013-10-29 16:12:11 +01:00
Tom Gundersen 8e18485284 udev: move udev_rules_check_timestamp to shared
I want to use this from a bulitin in a subsequent patch.
2013-10-26 14:34:31 +02:00
Zbigniew Jędrzejewski-Szmek 4bcc8c3cb5 Fix two compiler warnings 2013-09-09 17:35:52 -04:00
Zbigniew Jędrzejewski-Szmek c9d954b27e run: allow non-absolute paths as command 2013-09-09 13:49:30 -04:00
Zbigniew Jędrzejewski-Szmek 116cc02874 path-util.c: small modernization 2013-09-09 13:49:30 -04:00
Zbigniew Jędrzejewski-Szmek 11f22867f9 time-dst: use _cleanup_ 2013-05-02 22:55:38 -04:00
Lennart Poettering 6606089752 path-util: unify code for detecting OS trees
This also makes sure we always detect an OS tree the same way, by
checking for /etc/os-release.
2013-04-16 05:47:04 +02:00
Lennart Poettering fabe5c0e5f binfmt,tmpfiles,modules-load,sysctl: rework the various early-boot services that work on .d/ directories
This unifies much of the logic behind them:

- All four will now ofllow the rule that the earlier file and earlier
  assignment in the .d/ directories wins. Before, sysctl was the only
  outlier, where the later setting always won.

- All four now support getopt() and --help on the command line.

- All four can now handle specification of configuration file names on
  the command line to apply. The tools will automatically find them, and
  apply them. Previously only tmpfiles could do that. This is useful for
  %post scripts in RPMs and suchlike.

- This fixes various error path issues in conf_files_list()
2013-02-11 23:54:30 +01:00
Lennart Poettering 91a6489d99 path-util: fix memory leak 2013-02-11 05:10:23 +01:00
Zbigniew Jędrzejewski-Szmek 0783951b93 shared: remove now unused function 2013-02-06 23:16:17 -05:00
Zbigniew Jędrzejewski-Szmek 874310b7b6 systemd: do not remove empty paths from unit lookup path
The ability to start a new unit with 'systemctl start ...' should not
depend on whether there are other units in the directory. Previously,
an additional 'systemctl daemon-reload' would be necessary to tell
systemd to update the list of unit lookup paths.
2013-02-06 23:16:16 -05:00
Michal Sekletar c9c7aef24f path-util: set pointer to null after calling free()
In cases where path_strv_canonicalize() returns NULL, strv_free() is
called afterwards and it will call free() on pointers which were freed
already in path_strv_canonicalize()
2012-12-17 11:41:31 +01:00
Lennart Poettering 424a19f8a2 timedate: assorted improvements
- Make writing/reading of /etc/timezone dependendent of HAVE_SYSV_COMPAT

- Introduce symlink_atomic() after all, and use it

- Use relative symlink for /etc/localtime
2012-09-14 20:02:52 +02:00
Mantas Mikulėnas fa125f4e44 path-util: fall back to stat() if kernel does not support name_to_handle_at()
Fixes instant hang on kernels that do not have CONFIG_FHANDLE enabled.
2012-09-10 09:21:24 +02:00
Mantas Mikulėnas 8ac7549330 path-util: do not fail in path_is_mountpoint() if path doesn't exist
This was accidentally lost in commit 1640a0b6b0.
2012-09-10 09:21:10 +02:00
Lennart Poettering f408b8f1bb path: fix invalid variable access in path_is_mount_point() 2012-09-04 17:05:23 -07:00
Lennart Poettering 1640a0b6b0 path-util: in path_is_mount_point() fall back to the classic stat() test if fs does not support name_to_handle_at() 2012-09-04 16:37:57 -07:00
Lennart Poettering a8348796c0 missing: define name_to_handle_at on our own if it is missing 2012-09-04 15:30:24 -07:00
Lennart Poettering cde9cb343a util: make path_is_mount_point() recognize bind mounts, too 2012-09-03 18:59:05 -07:00
Lennart Poettering b7def68494 util: rename join() to strjoin()
This is to match strappend() and the other string related functions.
2012-07-13 13:41:01 +02:00
Kay Sievers 9eb977db5b util: split-out path-util.[ch] 2012-05-08 02:33:10 +02:00