X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils%2Fmount%2Ffstab.c;h=eedbddab87c63e3ea99c2a8507d7028c0d6cc2b5;hb=d3143a07f71a7177aca9391dcf50be46ef9d5eea;hp=a742e648d0e4d133c7e24eb07f2c4d591ad44cd5;hpb=ffa577350b03ddd421d455a8cd4cff86e3718264;p=nfs-utils.git diff --git a/utils/mount/fstab.c b/utils/mount/fstab.c index a742e64..eedbdda 100644 --- a/utils/mount/fstab.c +++ b/utils/mount/fstab.c @@ -86,10 +86,13 @@ mtab_is_writable() { struct mntentchn mounttable; static int got_mtab = 0; +struct mntentchn procmounts; +static int got_procmounts = 0; struct mntentchn fstab; static int got_fstab = 0; static void read_mounttable(void); +static void read_procmounts(void); static void read_fstab(void); static struct mntentchn * @@ -100,6 +103,14 @@ mtab_head(void) return &mounttable; } +static struct mntentchn * +procmounts_head(void) +{ + if (!got_procmounts) + read_procmounts(); + return &procmounts; +} + static struct mntentchn * fstab_head(void) { @@ -186,6 +197,30 @@ read_mounttable() { read_mntentchn(mfp, fnam, mc); } +/* + * Read /proc/mounts. + * This produces a linked list. The list head procmounts is a dummy. + * Return 0 on success. + */ +static void +read_procmounts() { + mntFILE *mfp; + const char *fnam; + struct mntentchn *mc = &procmounts; + + got_procmounts = 1; + mc->nxt = mc->prev = NULL; + + fnam = PROC_MOUNTS; + mfp = nfs_setmntent(fnam, "r"); + if (mfp == NULL || mfp->mntent_fp == NULL) { + nfs_error(_("warning: can't open %s: %s"), + PROC_MOUNTS, strerror (errno)); + return; + } + read_mntentchn(mfp, fnam, mc); +} + static void read_fstab() { @@ -224,6 +259,23 @@ getmntdirbackward (const char *name, struct mntentchn *mcprev) { return NULL; } +/* + * Given the directory name NAME, and the place MCPREV we found it last time, + * try to find more occurrences. + */ +struct mntentchn * +getprocmntdirbackward (const char *name, struct mntentchn *mcprev) { + struct mntentchn *mc, *mc0; + + mc0 = procmounts_head(); + if (!mcprev) + mcprev = mc0; + for (mc = mcprev->prev; mc && mc != mc0; mc = mc->prev) + if (streq(mc->m.mnt_dir, name)) + return mc; + return NULL; +} + /* * Given the device name NAME, and the place MCPREV we found it last time, * try to find more occurrences. @@ -331,16 +383,43 @@ lock_mtab (void) { int sig = 0; struct sigaction sa; - sa.sa_handler = handler; sa.sa_flags = 0; sigfillset (&sa.sa_mask); - while (sigismember (&sa.sa_mask, ++sig) != -1 - && sig != SIGCHLD) { - if (sig == SIGALRM) + while (sigismember (&sa.sa_mask, ++sig) != -1) { + switch(sig) { + case SIGCHLD: + case SIGKILL: + case SIGCONT: + case SIGSTOP: + /* The cannot be caught, or should not, + * so don't even try. + */ + continue; + case SIGALRM: sa.sa_handler = setlkw_timeout; - else + break; + case SIGHUP: + case SIGINT: + case SIGQUIT: + case SIGWINCH: + case SIGTSTP: + case SIGTTIN: + case SIGTTOU: + case SIGPIPE: + case SIGXFSZ: + case SIGXCPU: + /* non-priv user can cause these to be + * generated, so ignore them. + */ + sa.sa_handler = SIG_IGN; + break; + default: + /* The rest should not be possible, so just + * print a message and unlock mtab. + */ sa.sa_handler = handler; + } sigaction (sig, &sa, (struct sigaction *) 0); } signals_have_been_setup = 1;