Merge pull request #32863 from YHNdnzj/switch-root-followup

Two minor followups
This commit is contained in:
Luca Boccassi 2024-05-16 15:53:18 +02:00 committed by GitHub
commit aa4644882e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 16 deletions

View file

@ -896,21 +896,18 @@ int fd_reopen_propagate_append_and_position(int fd, int flags) {
if (new_fd < 0)
return new_fd;
/* Try to adjust the offset, but ignore errors for now. */
/* Try to adjust the offset, but ignore errors. */
off_t p = lseek(fd, 0, SEEK_CUR);
if (p <= 0)
return new_fd;
off_t new_p = lseek(new_fd, p, SEEK_SET);
if (new_p == (off_t) -1)
log_debug_errno(errno,
"Failed to propagate file position for re-opened fd %d, ignoring: %m",
fd);
else if (new_p != p)
log_debug("Failed to propagate file position for re-opened fd %d (%lld != %lld), ignoring: %m",
fd,
(long long) new_p,
(long long) p);
if (p > 0) {
off_t new_p = lseek(new_fd, p, SEEK_SET);
if (new_p < 0)
log_debug_errno(errno,
"Failed to propagate file position for re-opened fd %d, ignoring: %m",
fd);
else if (new_p != p)
log_debug("Failed to propagate file position for re-opened fd %d (%lld != %lld), ignoring.",
fd, (long long) new_p, (long long) p);
}
return new_fd;
}

View file

@ -30,8 +30,8 @@ int switch_root(const char *new_root,
const char *old_root_after, /* path below the new root, where to place the old root after the transition; may be NULL to unmount it */
SwitchRootFlags flags) {
/* Stuff mounted below /run/ we don't save on soft reboot, as it might have lost its relevance, i.e.
* credentials, removable media and such, we rather want that the new boot mounts this fresh. But on
/* Stuff mounted below /run/ we don't save on soft reboot, as it might have lost its relevance,
* e.g. removable media and such. We rather want that the new boot mounts this fresh. But on
* the switch from initrd we do use MS_REC, as it is expected that mounts set up in /run/ are
* maintained. */
static const struct {