summaryrefslogtreecommitdiffstats
path: root/sys-utils/switch_root.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fix a bug where switch_root would erroneously try to parse initargsPaul Asmuth2018-11-121-1/+1
| | | | | | before this change, switch_root would try to parse all arguments, including 'initargs', using getopt, which would lead to an 'unrecognized option' error when trying to pass a flag to the init program
* sys-utils: use errexec()Karel Zak2018-02-011-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-7/+12
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* switch_root: use getopt_long() to parse optionsSami Kerola2017-05-101-6/+18
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* switch_root: unlink files without _DIRENT_HAVE_D_TYPEPatrick Steinhardt2017-04-261-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When _DIRENT_HAVE_D_TYPE is not defined, we need to always fstat the directory entry in order to determine whether it is a directory or not. If we determine that the file is indeed a directory on the same device, we proceed to recursively remove its contents as well. Otherwise, we simply skip removing the entry altogether. This logic is not entirely correct though. Note that we actually skip deletion of the entry if it is either not a directory or if it is not on the same device. The second condition is obviously correct here, as we do not want to delete files on other mounts here. But skipping deletion of the entry itself if it is not a directory is wrong. When _DIRENT_HAVE_D_TYPE is defined, this condition should never be triggered, as we have already determined that the entry is a directory. But if it is not, we will always do the fstat and check. Because of this, we will now skip deletion of all files which are not directories, which is wrong. Fix the issue by disentangling both conditions. We now first check whether we are still on the same device - if not, we skip recursive deletion as well as deletion of the directory entry. Afterwards, we check whether it is a directory - if so, we do delete its contents recursively. And finally, we will now unlink the entry disregarding whether it is a directory or not. Signed-off-by: Patrick Steinhardt <ps@pks.im>
* switch_root: simplify code and reduce indentation [oclint]Sami Kerola2016-07-211-15/+14Star
| | | | | | | The if statement in line 162 already ensures value of cfd to be 0 or greater, so the later if is not needed. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* textual: grammarize and harmonize the stat error messageBenno Schulenberg2015-02-021-2/+2
| | | | | | | | | The message "stat failed %s" seems to say that stat() failed to do something, or failed to pass a test, but of course it means that the statting of something failed. So say so. Also make two very similar messages equal to this one. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+4
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* include/statfs_magic: use macro rather than type for f_typeKarel Zak2014-11-101-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: improve statfs->f_type portabilityKarel Zak2014-11-061-2/+2
| | | | | | | | | __SWORD_TYPE is not available everywhere, for example it's not defined by musl libc. It also seems that __SWORD_TYPE is not used for f_type on some architectures (s390x). Reported-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* build: fix some compiler warningsRuediger Meier2014-05-301-1/+2
| | | | | | | | | | | | Most of them catched on 32bit gcc and icc. disk-utils/fsck.cramfs.c: printf format type lib/boottime.c: unused variables misc-utils/cal.c: set but never used sys-utils/losetup.c: set but never used sys-utils/lscpu-dmi.c: defined but not used sys-utils/switch_root.c: comparison between signed and unsigned tests/helpers/test_sysinfo.c: printf format type
* switch_root: verify initramfs by f_type, not devnoDave Reisner2014-04-041-6/+8
| | | | | | | | As of linux 3.14, the initramfs device will have both major and minor 0, causing our paranoia check to fail. Make this version agnostic by checking the filesystem type, rather than a device number. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
* switch_root: make dirent d_type usage more robustKarel Zak2014-03-041-5/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: Add a sanity checkRichard Weinberger2013-02-131-1/+7
| | | | | | | As switch_root basically does rm -Rf / we should make sure that / is really an initramfs. Signed-off-by: Richard Weinberger <richard@nod.at>
* switch_root: check open() return value [coverity scan]Karel Zak2012-09-071-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* translation: unify stat error messagesSami Kerola2012-07-161-3/+3
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* sys-utils: verify writing to streams was successfulSami Kerola2012-04-041-0/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* switch_root: close open file after usage [cppcheck]Sami Kerola2012-02-081-0/+2
| | | | | | [sys-utils/switch_root.c:159]: (error) Resource leak: cfd Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* switch_root: umount mount points we cannot move with MNT_DETACHHarald Hoyer2011-11-141-1/+5
| | | | | | | | | | | If a mount point cannot be moved to the new root, umount it with MNT_DETACH, so that it is lazy umounted and does not show up in /proc/mounts anymore. [kzak@redhat.com: - add MNT_DETACH macro fallback] Signed-off-by: Harald Hoyer <harald@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: add nls supportSami Kerola2011-10-301-15/+15
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* switch_root: align with howto-usage-function.txtSami Kerola2011-10-301-12/+15
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* switch_root: handle /run and do not mount over existing mountsHarald Hoyer2011-10-201-1/+13
| | | | | | | | | | Handle /run just like /dev, /sys and /proc Do not mount move, if there is already something mounted on the destination folder. Signed-off-by: Harald Hoyer <harald@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: provide alternatives for err, errx, warn and warnxFabian Groffen2011-02-141-1/+1
| | | | | | | | Solaris lacks err, errx, warn and warnx. This also means the err.h header doesn't exist. Removed err.h include from all files, and included err.h from c.h instead if it exists, otherwise alternatives are provided. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
* Revert "switch_root: add subroot support"Karel Zak2009-11-201-76/+5Star
| | | | | | | | | | | | | This reverts commit a692a8745941a192528c5e2a05de97155ba586f9. On Wed, Nov 18, 2009 at 03:33:12PM +0000, Daniel Drake wrote: > Booting into a system this way just leads to problems because > you cannot remount the root read-only at shutdown (leading to unclean > shutdowns). > Miklos Szeredi pointed out a trick to turn any directory into a > mount point which avoids this problem. Therefore we can simplify > switch_root again and simply document that its users should set
* switch_root: remove TIOCSCTTY and setsid()Karel Zak2009-10-091-7/+0Star
| | | | | | | | | requested by dracut developers because: bash: cannot set terminal process group (-1): Inappropriate ioctl for device Addresses-Red-Hat-Bug: #519237 Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: add subroot supportDaniel Drake2009-07-141-5/+76
| | | | | | | | | | | | | | | | | | | | | | The current switch_root can only switch to a new root that is the root of a mount point. This patch adds support for "subroots", where the new root is somewhere below a mount point. It does this by adding in a few extra steps to chroot into the subroot after the enclosing partition has been moved and entered. This will be used by OLPC, who sort-of have 2 copies of Fedora stored on a single partition under different directory trees, where the initramfs decides which one to boot into [kzak@redhat.com: - port to the current u-l-ng switch_root code - don't use static buffer for "dir" in get_parent_mount()] CC: Peter Jones <pjones@redhat.com> Signed-off-by: Daniel Drake <dsd@laptop.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: do recursiveRemove after our root is moved to avoid races.Peter Jones2009-06-221-9/+10
| | | | | | | This way there's no race between unlinking the /newroot directory and the MS_MOVE/chroot() to get away from it. Signed-off-by: Peter Jones <pjones@redhat.com>
* switch_root: fork before cleaning up the filesystem.Peter Jones2009-06-221-1/+7
| | | | | | | Fork before cleaning up the old filesystem, so it becomes asyncronous, which results in a faster boot time. Signed-off-by: Peter Jones <pjones@redhat.com>
* switch_root: use file descriptor instead of path for recursiveRemove()Peter Jones2009-06-221-12/+20
| | | | | | | | This makes recursiveRemove() use fdopendir() instead of taking a path, so we're always sure about which namespace we're starting from. Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: use snprintf() rather tan str{cpy,cat}()Karel Zak2009-06-221-3/+4
| | | | | Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: clean up argv[] usage, add -h and -VKarel Zak2009-06-221-20/+27
| | | | | Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: use err.h, clean up return codesKarel Zak2009-06-221-28/+25Star
| | | | | Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: rewrite to use fstatat() and unlinkat()Karel Zak2009-06-221-43/+44
| | | | | Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: fix coding styleKarel Zak2009-06-221-80/+70Star
| | | | | | Signed-off-by: Peter Jones <pjones@redhat.com> Acked-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* switch_root: new commandKarel Zak2009-06-221-0/+198
Copied from Dracut project: git://dracut.git.sourceforge.net/gitroot/dracut switch_root history in dracut.git repository: $ git shortlog switch_root.c Harald Hoyer (5): replace switch_root shell script with binary add \n to switch_root use switch_root code from http://pjones.fedorapeople.org/mkstart/usr/lib/mkstart/switchroot.c mount move instead of umount and fix the search for fallback inits setsid() and set controlling terminal for real /sbin/init Victor Lowther (2): Simplify switch_root.c a bit Remove all files on the initramfs before switching root Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>