Commit Graph

32 Commits

Author SHA1 Message Date
Lennart Poettering ec6bdf7259 copy: rework copy_file_atomic() to copy the specified file via O_TMPFILE if possible 2018-06-07 17:40:14 +02:00
Zbigniew Jędrzejewski-Szmek 9421cab6db test-copy: remove unnecessary initialization
Initializing just some of the values doesn't make sense. We should handle them
all in the same way. In those tests there are no jumps, all steps are covered
with assert_se(), so we know everything will be set if we get to the end of the
function. And _not_ initializing those variables has the advantage that it
allows valgrind to catch potential initalization errors in the function being
tested.
2018-05-14 17:22:22 +02:00
Zbigniew Jędrzejewski-Szmek dcd6361ea1 tree-wide: do not wrap assert_se in extra parentheses
We were inconsitently using them in some cases, but in majority not.
Using assignment in assert_se is very common, not an exception like in
'if', so let's drop the extra parens everywhere.
2018-05-14 17:22:22 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 842e456e79 fs-util: drop readlink_and_canonicalize() 2018-02-09 16:49:54 +09:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 6fbdf424b4 test-copy: fix operation when test-copy is too small
Fixes #6981.
2017-10-04 15:17:09 +02:00
Lennart Poettering d01cd40196 machined: when copying files from/to userns containers chown to root
This changes the file copy logic of machined to set the UID/GID of all
copied files to 0 if the host and container do not share the same user
namespace.

Fixes: #4078
2017-02-17 10:22:28 +01:00
Lennart Poettering 1c876927e4 copy: change the various copy_xyz() calls to take a unified flags parameter
This adds a unified "copy_flags" parameter to all copy_xyz() function
calls, replacing the various boolean flags so far used. This should make
many invocations more readable as it is clear what behaviour is
precisely requested. This also prepares ground for adding support for
more modes later on.
2017-02-17 10:22:28 +01:00
Lennart Poettering e187369587 tree-wide: stop using canonicalize_file_name(), use chase_symlinks() instead
Let's use chase_symlinks() everywhere, and stop using GNU
canonicalize_file_name() everywhere. For most cases this should not change
behaviour, however increase exposure of our function to get better tested. Most
importantly in a few cases (most notably nspawn) it can take the correct root
directory into account when chasing symlinks.
2016-12-01 00:25:51 +01:00
Zbigniew Jędrzejewski-Szmek f60dad309a test-copy: wrap assignments in function call in parentheses 2016-10-23 11:46:51 -04:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Topi Miettinen 646853bdd8 fileio: simplify mkostemp_safe() (#4090)
According to its manual page, flags given to mkostemp(3) shouldn't include
O_RDWR, O_CREAT or O_EXCL flags as these are always included. Beyond
those, the only flag that all callers (except a few tests where it
probably doesn't matter) use is O_CLOEXEC, so set that unconditionally.
2016-09-13 08:20:38 +02:00
Lennart Poettering 2397bc4312 test-copy: never call alloca() in a loop
That's a total no-no, hence rework this to use malloc()-based memory instead of
alloca()-based memory.

Also see CODING_STYLE about this.
2016-04-29 14:28:04 +02:00
Lennart Poettering 0e2b2caccd copy: also copy AF_UNIX sockets
We previously would fail with EOPNOTSUPP when encountering an AF_UNIX socket in
the directory tree to copy. Fix that, and copy them too (even if they are dead
in the result).

Fixes: #2914
2016-04-29 14:28:03 +02:00
Martin Pitt fa13cf9e21 test-copy: use correct data type for max_bytes
copy_bytes() and the comparisons in test_copy_bytes_regular_file() expect an
uint64_t, not a size_t. On 32 bit architectures the latter is 32 bit, leading
to truncation errors.

Fixes regression from commit 7a827fcb.
2016-03-21 14:58:30 +01:00
Zbigniew Jędrzejewski-Szmek 7a827fcb11 test-copy: test with different max_bytes values 2016-03-15 19:26:28 -04:00
Zbigniew Jędrzejewski-Szmek ce33fddad0 test-copy: add a test shuffling bytes between normal files
I started looking into adding copy_file_range support, and discovered
that we can improve the way we call sendfile:
- sendfile(2) man page is missing an important bit: the number of bytes to
  copy cannot be too big (SSIZE_MAX actually), and the description of EINVAL
  return code does not mention this either,
- our implementation works but calls sendfile over and over with a small
  size, which seems suboptimal.

First add a test which (under strace) can be used to see current behaviour.
2016-03-15 14:53:31 -04:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +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 59f448cf15 tree-wide: never use the off_t unless glibc makes us use it
off_t is a really weird type as it is usually 64bit these days (at least
in sane programs), but could theoretically be 32bit. We don't support
off_t as 32bit builds though, but still constantly deal with safely
converting from off_t to other types and back for no point.

Hence, never use the type anymore. Always use uint64_t instead. This has
various benefits, including that we can expose these values directly as
D-Bus properties, and also that the values parse the same in all cases.
2015-09-10 18:16:18 +02:00
Daniel Mack 4c1fc3e404 fileio: consolidate write_string_file*()
Merge write_string_file(), write_string_file_no_create() and
write_string_file_atomic() into write_string_file() and provide a flags mask
that allows combinations of atomic writing, newline appending and automatic
file creation. Change all users accordingly.
2015-07-06 19:19:25 -04:00
Dimitri John Ledkov 4f36d4004c test: fix test-copy without /etc/os-release. 2015-06-23 16:22:40 +01:00
Zbigniew Jędrzejewski-Szmek ad5ecc1138 test-copy: test copy_bytes() 2015-06-10 10:14:40 -04: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
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Lennart Poettering f2068bcce0 machined: when cloning a raw disk image, also set the NOCOW flag 2015-01-08 23:13:45 +01:00
Lennart Poettering 7430ec6ac0 copy: use btrfs reflinking only whe we know we copy full files 2014-12-12 17:30:25 +01:00
Lennart Poettering cda134ab1e copy: teach copy_bytes() sendfile() support, and then replace sendfile_full() by it 2014-11-07 01:19:56 +01:00
Ronny Chevalier 641d1f99b8 tests: add test-copy 2014-10-31 10:57:22 +01:00