Convert fsck and mount to using execvP to find fsck_foo and mount_foo.
This simplifies the code path and makes the default path easy to override in the /rescue case. Submitted by: Tim Kientzle <kientzle@acm.org>
This commit is contained in:
parent
6bff75208c
commit
2da83d3d2b
@ -44,6 +44,9 @@
|
||||
/* All standard utilities path. */
|
||||
#define _PATH_STDPATH \
|
||||
"/usr/bin:/bin:/usr/sbin:/sbin:"
|
||||
/* Locate system binaries */
|
||||
#define _PATH_SYSPATH \
|
||||
"/sbin:/usr/sbin"
|
||||
|
||||
#define _PATH_AUTHCONF "/etc/auth.conf"
|
||||
#define _PATH_BSHELL "/bin/sh"
|
||||
|
@ -62,7 +62,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pathnames.h"
|
||||
#include "fsutil.h"
|
||||
|
||||
static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
|
||||
@ -281,16 +280,10 @@ static int
|
||||
checkfs(const char *pvfstype, const char *spec, const char *mntpt,
|
||||
char *auxopt, pid_t *pidp)
|
||||
{
|
||||
/* List of directories containing fsck_xxx subcommands. */
|
||||
static const char *edirs[] = {
|
||||
_PATH_SBIN,
|
||||
_PATH_USRSBIN,
|
||||
NULL
|
||||
};
|
||||
const char **argv, **edir;
|
||||
const char **argv;
|
||||
pid_t pid;
|
||||
int argc, i, status, maxargc;
|
||||
char *optbuf, execname[MAXPATHLEN + 1], execbase[MAXPATHLEN];
|
||||
char *optbuf, execbase[MAXPATHLEN];
|
||||
char *vfstype = NULL;
|
||||
const char *extra = NULL;
|
||||
|
||||
@ -361,25 +354,11 @@ checkfs(const char *pvfstype, const char *spec, const char *mntpt,
|
||||
_exit(0);
|
||||
|
||||
/* Go find an executable. */
|
||||
edir = edirs;
|
||||
do {
|
||||
(void)snprintf(execname,
|
||||
sizeof(execname), "%s/%s", *edir, execbase);
|
||||
execv(execname, (char * const *)argv);
|
||||
if (errno != ENOENT) {
|
||||
if (spec)
|
||||
warn("exec %s for %s", execname, spec);
|
||||
else
|
||||
warn("exec %s", execname);
|
||||
}
|
||||
} while (*++edir != NULL);
|
||||
|
||||
if (errno == ENOENT) {
|
||||
if (spec)
|
||||
warn("exec %s for %s", execname, spec);
|
||||
else
|
||||
warn("exec %s", execname);
|
||||
}
|
||||
execvP(execbase, _PATH_SYSPATH, (char * const *)argv);
|
||||
if (spec)
|
||||
warn("exec %s for %s in %s", execbase, spec, _PATH_SYSPATH);
|
||||
else
|
||||
warn("exec %s in %s", execbase, _PATH_SYSPATH);
|
||||
_exit(1);
|
||||
/* NOTREACHED */
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
/* $NetBSD: pathnames.h,v 1.1 1996/09/11 20:27:15 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Christos Zoulas.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define _PATH_SBIN "/sbin"
|
||||
#define _PATH_USRSBIN "/usr/sbin"
|
@ -54,6 +54,7 @@ static const char rcsid[] =
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fstab.h>
|
||||
#include <paths.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@ -392,13 +393,8 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
|
||||
const char *vfstype, *spec, *name, *options, *mntopts;
|
||||
int flags;
|
||||
{
|
||||
/* List of directories containing mount_xxx subcommands. */
|
||||
static const char *edirs[] = {
|
||||
_PATH_SBIN,
|
||||
_PATH_USRSBIN,
|
||||
NULL
|
||||
};
|
||||
const char *argv[100], **edir;
|
||||
char *path, *cur;
|
||||
struct statfs sf;
|
||||
pid_t pid;
|
||||
int argc, i, status;
|
||||
@ -469,25 +465,10 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
|
||||
exit(mount_ufs(argc, (char * const *) argv));
|
||||
|
||||
/* Go find an executable. */
|
||||
for (edir = edirs; *edir; edir++) {
|
||||
(void)snprintf(execname,
|
||||
sizeof(execname), "%s/mount_%s", *edir, vfstype);
|
||||
execv(execname, (char * const *)argv);
|
||||
}
|
||||
(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
|
||||
execvP(execname, _PATH_SYSPATH, (char * const *)argv);
|
||||
if (errno == ENOENT) {
|
||||
int len = 0;
|
||||
char *cp;
|
||||
for (edir = edirs; *edir; edir++)
|
||||
len += strlen(*edir) + 2; /* ", " */
|
||||
if ((cp = malloc(len)) == NULL)
|
||||
errx(1, "malloc failed");
|
||||
cp[0] = '\0';
|
||||
for (edir = edirs; *edir; edir++) {
|
||||
strcat(cp, *edir);
|
||||
if (edir[1] != NULL)
|
||||
strcat(cp, ", ");
|
||||
}
|
||||
warn("exec mount_%s not found in %s", vfstype, cp);
|
||||
warn("exec mount_%s not found in %s", vfstype, path);
|
||||
}
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
|
@ -31,8 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)pathnames.h 8.2 (Berkeley) 3/27/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define _PATH_SBIN "/sbin"
|
||||
#define _PATH_USRSBIN "/usr/sbin"
|
||||
#define _PATH_MOUNTDPID "/var/run/mountd.pid"
|
||||
|
Loading…
Reference in New Issue
Block a user