Path: blob/main/tests/sys/kern/execve/execve_helper.c
39488 views
/* $NetBSD: doexec.c,v 1.8 2003/07/26 19:38:48 salo Exp $ */12/*3* Copyright (c) 1993 Christopher G. Demetriou4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed for the17* NetBSD Project. See http://www.NetBSD.org/ for18* information about NetBSD.19* 4. The name of the author may not be used to endorse or promote products20* derived from this software without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR23* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES24* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.25* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,26* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT27* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,28* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY29* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT30* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF31* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/3334#include <err.h>35#include <errno.h>36#include <stdio.h>37#include <stdlib.h>38#include <string.h>39#include <unistd.h>4041/* Passing -n == null_argv */42static char * const null_argv[] = { NULL };4344int45main(int argc, char **argv)46{4748if (argc == 2) {49execve(argv[1], &argv[1], NULL);50} else if (argc == 3 && strcmp(argv[1], "-n") == 0) {51execve(argv[2], null_argv, NULL);52} else {53fprintf(stderr, "usage: %s [-n] <progname>\n", argv[0]);54exit(2);55}5657err(1, "execve failed");58}596061