mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Only unmount non-protected filesystems at shutdown
This patch adds support for a more fine grained approach to what filesystems are unmounted at shutdown/reboot. This so we later can add support for `mdadm --wait-clean --scan`, which relies on /proc, /sys, and /dev being there before we call reboot(). Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
b1fb536468
commit
f4327910d9
3 files changed
+121
-6
No files matched your search
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
sbin_PROGRAMS = finit initctl reboot
|
sbin_PROGRAMS = finit initctl reboot
|
||||||
finit_SOURCES = finit.c api.c client.c conf.c exec.c getty.c helpers.c pid.c \
|
finit_SOURCES = finit.c api.c client.c conf.c exec.c getty.c helpers.c \
|
||||||
sig.c svc.c service.c plugin.c tty.c cond.c cond-w.c sm.c \
|
mount.c pid.c sig.c svc.c service.c plugin.c tty.c \
|
||||||
utmp-api.c utmp-api.h
|
cond.c cond-w.c sm.c utmp-api.c utmp-api.h
|
||||||
pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h
|
pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h
|
||||||
if INETD
|
if INETD
|
||||||
finit_SOURCES += inetd.c
|
finit_SOURCES += inetd.c
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/* Mount and unmount helpers
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <mntent.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SysV init on Debian/Ubuntu skips these protected mount points
|
||||||
|
*
|
||||||
|
* It also skips anything below /proc, /sys and /run for good meausre so
|
||||||
|
* we do the same here. What we want is a list of non-protected tmpfs
|
||||||
|
* and regular filesystems that can be safely unmounted before we do
|
||||||
|
* swapoff, and remount / as read-only, respectively.
|
||||||
|
*/
|
||||||
|
static int is_protected(char *dir)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *protected[] = {
|
||||||
|
"/sys", "/proc",
|
||||||
|
"/.dev", "/dev", "/dev/pts", "/dev/shm", "dev/.static/dev", "/dev/vcs",
|
||||||
|
"/run", "/var/run",
|
||||||
|
"/", NULL
|
||||||
|
};
|
||||||
|
char *any[] = {
|
||||||
|
"/proc/", "/sys/", "/run/", NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; protected[i]; i++) {
|
||||||
|
if (!strcmp(dir, protected[i]))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; any[i]; i++) {
|
||||||
|
if (!strncmp(dir, any[i], strlen(any[i])))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct mntent *iterator(char *fstab)
|
||||||
|
{
|
||||||
|
static FILE *fp = NULL;
|
||||||
|
static struct mntent *mnt;
|
||||||
|
|
||||||
|
if (!fp && fstab) {
|
||||||
|
fp = setmntent(fstab, "r");
|
||||||
|
if (!fp)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((mnt = getmntent(fp))) {
|
||||||
|
if (is_protected(mnt->mnt_dir))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return mnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
endmntent(fp);
|
||||||
|
fp = NULL;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unmount_tmpfs(void)
|
||||||
|
{
|
||||||
|
struct mntent *mnt;
|
||||||
|
|
||||||
|
while ((mnt = iterator("/proc/mounts"))) {
|
||||||
|
if (!strcmp("tmpfs", mnt->mnt_fsname))
|
||||||
|
umount(mnt->mnt_dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unmount_regular(void)
|
||||||
|
{
|
||||||
|
struct mntent *mnt;
|
||||||
|
|
||||||
|
while ((mnt = iterator("/proc/mounts"))) {
|
||||||
|
umount(mnt->mnt_dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -86,6 +86,9 @@ static uev_t sighup_watcher, sigint_watcher, sigpwr_watcher;
|
|||||||
static uev_t sigchld_watcher, sigsegv_watcher;
|
static uev_t sigchld_watcher, sigsegv_watcher;
|
||||||
static uev_t sigstop_watcher, sigtstp_watcher, sigcont_watcher;
|
static uev_t sigstop_watcher, sigtstp_watcher, sigcont_watcher;
|
||||||
|
|
||||||
|
void unmount_tmpfs(void);
|
||||||
|
void unmount_regular(void);
|
||||||
|
|
||||||
|
|
||||||
void do_shutdown(shutop_t op)
|
void do_shutdown(shutop_t op)
|
||||||
{
|
{
|
||||||
@@ -141,17 +144,19 @@ void do_shutdown(shutop_t op)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Unmount any tmpfs before unmounting swap ... */
|
/* Unmount any tmpfs before unmounting swap ... */
|
||||||
run("/bin/umount -r -a");
|
unmount_tmpfs();
|
||||||
run("/sbin/swapoff -e -a");
|
run("/sbin/swapoff -e -a");
|
||||||
|
|
||||||
/* Now, unmount everything else ... err, just force it. */
|
/* ... unmount remaining regular file systems. */
|
||||||
run("/bin/umount -n -f -r -a");
|
unmount_regular();
|
||||||
|
|
||||||
/* We sit on / so we must remount it ro, try all the things! */
|
/* We sit on / so we must remount it ro, try all the things! */
|
||||||
run("/bin/mount -n -o remount,ro -t dummytype dummydev /");
|
run("/bin/mount -n -o remount,ro -t dummytype dummydev /");
|
||||||
run("/bin/mount -n -o remount,ro dummydev /");
|
run("/bin/mount -n -o remount,ro dummydev /");
|
||||||
run("/bin/mount -n -o remount,ro /");
|
run("/bin/mount -n -o remount,ro /");
|
||||||
|
|
||||||
|
/* XXX: Call mdadm to mark RAID array(s) as clean before halting. */
|
||||||
|
|
||||||
_d("%s.", op == SHUT_REBOOT ? "Rebooting" : "Halting");
|
_d("%s.", op == SHUT_REBOOT ? "Rebooting" : "Halting");
|
||||||
if (op == SHUT_REBOOT)
|
if (op == SHUT_REBOOT)
|
||||||
reboot(RB_AUTOBOOT);
|
reboot(RB_AUTOBOOT);
|
||||||
|
|||||||
Reference in new issue
Block a user