Commit graph

91 commits

Author SHA1 Message Date
Felipe Sateler cc8b113e0b build-sys: Add new libsystemd-shared private library
Link as many binaries as possible with it, to save storage space.

Preserve the static libshared and libbasic for use in libraries, nss
modules and udev.

Libraries need to be static in order to avoid polluting the symbol
namespace.

Udev needs to be static so downstream can avoid strict version dependencies
with the systemd package, and this can complicate upgrade scenarios.
2016-06-24 22:36:28 -04:00
Zbigniew Jędrzejewski-Szmek b05b9cde12 test-path-util: add a trivial test for hidden_or_backup_file 2016-04-28 08:25:17 -04:00
Zbigniew Jędrzejewski-Szmek 24737c2917 install: allow paths like LookupPath.generator to be NULL
Fixes #3047.
2016-04-16 23:08:23 -04:00
Zbigniew Jędrzejewski-Szmek 3ae5990c6e tree-wide: introduce PATH_IN_SET macro 2016-04-16 22:57:05 -04:00
Ronny Chevalier 6329266386 tests: move path-util related tests to test-path-util.c 2016-03-03 19:04:06 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 4349cd7c1d util-lib: move mount related utility calls to mount-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 5f311f8c0e util: remove path_get_parent(), in favour of dirname_malloc()
We don't need two functions that do essentialy the same, hence drop
path_get_parent(), and stick to dirname_malloc(), but move it to
path-util.[ch].
2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 85eca92e20 path-util: rework find_binary(), fsck_exists() and mkfs_exists()
Modernize the code a bit:

- Get rid of FOREACH_WORD_SEPARATOR() loop in favour of a
  extract_first_word() loop.

- Remove find_binary()'s "local" flag. It's not reasonably possible to
  look for binaries on remote systems, we hence should not pretend we
  could.

- When we cannot find a suitable binary, return the last error returned
  from access() rather than ENOENT unconditionally.

- Rework fsck_exists() and mkfs_exists() to return 1 on success, 0 if
  the implementation is missing and negative on real errors. This is
  more like we do it in other functions.

- Make sure we also detect direct fsck symlinks to "true", rather than
  just absolute ones to /bin/true.
2015-10-24 23:03:49 +02:00
Martin Pitt 36908eb87d path-util: Fix path_is_mount_point for parent mount points in symlink mode
When we have a structure like this:

  /bin -> /usr/bin
  /usr is a mount point

Then path_is_mount_point("/bin", AT_SYMLINK_FOLLOW) needs to look at the pair
/usr/bin and /usr, not at the pair / and /usr/bin, as the latter have different
mount IDs. But we only want to consider the base name, not any parent.

Thus we have to resolve the given path first to get the real parent when
allowing symlinks.

Bug: https://github.com/systemd/systemd/issues/61
2015-06-09 16:16:56 +02:00
Martin Pitt e26d6ce517 path-util: Change path_is_mount_point() symlink arg from bool to flags
This makes path_is_mount_point() consistent with fd_is_mount_point() wrt.
flags.
2015-05-29 17:42:44 +02:00
Martin Pitt 5d40903401 path-util: Fix path_is_mount_point for files
Commits 27cc6f166 and f25afeb broke path_is_mount_point() for files (such as
/etc/machine-id → /run/machine-id bind mounts) as with the factorization of
fd_is_mount_point() we lost the parent directory. We cannot determine that from
an fd only as openat(fd, "..") only works for directory fds.

Change fd_is_mount_point() to behave like openat(): It now takes a file
descriptor of the containing directory, a file name in it, and flags (which can
be 0 or AT_SYMLINK_FOLLOW). Unlike name_to_handle_at() or openat(), fstatat()
only accepts the inverse flag AT_SYMLINK_NOFOLLOW and complains with EINVAL
about AT_SYMLINK_FOLLOW; so we need to transform the flags for that fallback.

Adjust rm_rf_children() accordingly (only other caller of fd_is_mount_point()
aside from path_is_mount_point()).

Add test cases for files, links, and file bind mounts (the latter will only
work when running as root). Split out a new test_path_is_mount_point() test
case function as it got significantly larger now.
2015-05-29 17:40:12 +02:00
Lennart Poettering 1d13f648d0 util: add generic calls for prefixing a root directory to a path
So far a number of utilities implemented their own calls for this, unify
them in prefix_root() and prefix_roota(). The former uses heap memory,
the latter allocates from the stack via alloca().

Port over most users of a --root= logic.
2015-05-13 17:42:10 +02:00
Lennart Poettering 3f72b427b4 path-util: make use of "mnt_id" field exported in /proc/self/fdinfo/<fd> to test for mount points
It's a very recent kernel addition, but certainly makes sense to
support.
2015-04-23 13:40:54 +02:00
Lennart Poettering da00518b3f path-util: fix more path_is_mount e792e890f fallout 2015-04-07 16:03:45 +02:00
Lennart Poettering c687863750 util: rework rm_rf() logic
- Move to its own file rm-rf.c

- Change parameters into a single flags parameter

- Remove "honour sticky" logic, it's unused these days
2015-04-06 10:57:53 +02:00
Michal Schmidt 2230852bd9 shared: add path_compare(), an ordering path comparison
... and make path_equal() a simple wrapper around it.
2015-03-16 22:01:41 +01:00
Zbigniew Jędrzejewski-Szmek bc854dc7cd systemctl: refuse to edit runtime dropins when they already exist in /etc
The check for existing unit files and dropins is unified.

path_join() is updated to not insert duplicate separators.
2014-12-16 00:30:34 -05:00
Thomas Hindoe Paaboel Andersen f08c4c08c7 test-path-util: fix a leak 2014-12-04 00:13:10 +01:00
Zbigniew Jędrzejewski-Szmek b63bd1090b Do not check for existence of remote binaries
systemd-run would fail when run with -M or -H and an absolute path,
if this path did not exists locally. Allow it to continue, since we
don't have a nice way of checking if the binary exists remotely.

The case where -M or -H is used and a local path is unchanged, and we
still iterate over $PATH to find the binary. We need to convert to an
absolute path, and we don't have a nice mechanism to check remotely,
so we assume that the binary will be located in the same place locally
and remotely.

http://lists.freedesktop.org/archives/systemd-devel/2014-November/025418.html
2014-11-22 18:01:43 -05:00
Ronny Chevalier 5895b62f1d tests: add tests for path_startswith 2014-10-31 10:57:21 +01:00
Thomas Hindoe Paaboel Andersen 59ae3a9573 test-path-util: fix a mem leak and avoid confusing coverity
Found with coverity. Fixes CID#1237754 and #1237790
2014-09-30 22:28:46 +02:00
Filipe Brandenburger 8d95631ea6 test-path-util: use assert_se in all assertions
Otherwise they get optimized out when CPPFLAGS='-DNDEBUG' is used, and that
causes the tests to fail.

Tested:
- make check TESTS='test-path-util' CPPFLAGS='-DNDEBUG'
2014-08-26 20:31:31 +02:00
Zbigniew Jędrzejewski-Szmek 0c6ea3a4e2 Add utility function to append root to path 2014-07-26 15:08:42 -04:00
Thomas Hindoe Paaboel Andersen c8b32e11ee consistently order cleanup attribute before type 2014-06-22 00:45:15 +02:00
Michael Marineau 3e8a78c8dc test: unit test for using alternate roots with path_strv_resolve 2014-06-20 00:10:47 -04:00
Tanu Kaskinen 6b56a65123 test-path-util: add tests for path_make_relative() 2014-05-25 11:21:24 +08:00
Zbigniew Jędrzejewski-Szmek 7f076504b8 test-path-util: fix running with separate build dir
test-path-utils attempts to find itself, but if the binary is not
in current directory, the test would fail.
2014-04-16 22:04:48 -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
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 e203f7c3ad util: properly handle the root dir in PATH_FOREACH_PREFIX
Also add PATH_FOREACH_PREFIX_MORE which includes the specified dir
itself in the iteration
2013-09-26 20:20:30 +02:00
Lennart Poettering fecffe5d0a util: add macro for iterating through all prefixes of a path
Syntactic sugar in a macro PATH_FOREACH_PREFIX.
2013-09-25 21:04:35 +02: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 b463b81399 test-path-util,test-sched-prio: uninitialize manager to appease valgrind 2013-07-12 13:24:06 -04:00
Zbigniew Jędrzejewski-Szmek a696dbef34 test-path-util: fix another stupid test failure 2013-03-29 20:30:21 -04:00
Zbigniew Jędrzejewski-Szmek 590f50130f test-path-util: fix botched test 2013-03-29 10:49:06 -04:00
Zbigniew Jędrzejewski-Szmek 76877b46b6 tests: add some silly tests for path-util.c 2013-03-28 23:45:59 -04:00