Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Feb 2001 12:55:11 -0800 (PST)
From:      Matt Dillon <dillon@earth.backplane.com>
To:        Dima Dorfman <dima@unixfreak.org>
Cc:        mi@aldan.algebra.com, deischen@FreeBSD.ORG, cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG
Subject:   Re: mdconfig config file (was: cvs commit: src/sys/i386/conf GENERI C) 
Message-ID:  <200102022055.f12KtBL98916@earth.backplane.com>
References:   <20010202203201.9DC693E02@bazooka.unixfreak.org>

next in thread | previous in thread | raw e-mail | index | archive | help
:<snip>
:> 
:>     (this whole thing is predicated on someone writing a mount_md wrapper
:>     for MD that mimics the options mount_mfs accepts, for compatibility).
:
:I'll do it.  Would it be safe to assume that it's acceptable to write
:a C program to parse the arguments, build command lines to
:appropriately invoke disklabel, newfs, maybe tunefs, and mount, then
:call system(3) to execute them?
:
:					Dima Dorfman
:					dima@unixfreak.org

    Yes, though preferably I'd fork/exec the sub-programs (and use 
    absolute paths) rather then use system(), because the mount program
    will be running during booting and its important to have it use as
    few system resources as possible in case the system is screwed up.
    We don't want it exec'ing /bin/sh.

    I've included a program below outlining what I mean.

						-Matt


/*
 * test program
 */

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

static int simple_run(char **av);

int
main(int ac, char **av)
{
    char *args[] = { "/bin/ls", "/", NULL };
    int r;

    r = simple_run(args);
    printf("return code: %d\n", r);
    return(0);
}

static int
simple_run(char **av)
{
    pid_t pid;
    int status = 0;

    if ((pid = fork()) == 0) {
	execv(av[0], av);
	_exit(1);
    }
    if (pid < 0) {
	fprintf(stderr, "fork failed: %s\n", strerror(errno));
	return(1);
    }
    while (waitpid(pid, &status, 0) != pid)
	;
    return(WEXITSTATUS(status));
}



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102022055.f12KtBL98916>