]> git.ipfire.org Git - thirdparty/systemd.git/commit
fs-utils: new wrapper fd_reopen_propagate_append_and_position()
authorLars Ellenberg <lars.ellenberg@linbit.com>
Wed, 7 Feb 2024 12:12:50 +0000 (13:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Mar 2024 18:01:00 +0000 (19:01 +0100)
commitb8e25bff386548f679902c6b797a5a8ff1542c8b
tree452e85a53e8362a5ddcbc408ef6653f35f4ef62a
parentd3d880e558e608de351c0b518c10953cba2ed0b3
fs-utils: new wrapper fd_reopen_propagate_append_and_position()

We may want to propagate O_APPEND, or (try to) keep the current file position,
even if we use fd_reopen() to re-initialize (and "unshare") other file
description status.

For now, used only with --pty to keep/propagate O_APPEND (and/or) position
if set on stdin/stdout.

If we re-open stdout and "drop" the O_APPEND,
we get rather "unexpected" behavior,
for example with repeated "systemd-run --pty >> some-log".

If someone carefully pre-positioned the passed in original file descriptors,
we avoid surprises if we do not reset file postition to zero.

fcntl F_GETFL first, and propagate O_APPEND if present in the existing flags.

Then use lseek to propagate the file position.
src/basic/fd-util.c
src/basic/fd-util.h
src/shared/ptyfwd.c