~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/exec.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
 
3
 
/*
4
 
 *      Copyright (C) 2002-2005 Novell/SUSE
5
 
 *
6
 
 *      This program is free software; you can redistribute it and/or
7
 
 *      modify it under the terms of the GNU General Public License as
8
 
 *      published by the Free Software Foundation, version 2 of the
9
 
 *      License.
10
 
 */
11
 
#include <unistd.h>
12
 
#include <errno.h>
13
 
#include <sys/types.h>
14
 
#include <sys/wait.h>
15
 
#include <signal.h>
16
 
 
17
 
int main(int argc, char *argv[])
18
 
{
19
 
pid_t pid;
20
 
 
21
 
extern char **environ;
22
 
 
23
 
        if (argc < 2){
24
 
                fprintf(stderr, "usage: %s program [args] \n", argv[0]);
25
 
                return 1;
26
 
        }
27
 
 
28
 
        pid=fork();
29
 
 
30
 
        if (pid){       /* parent */
31
 
                int status;
32
 
 
33
 
                while (wait(&status) != pid);
34
 
 
35
 
                if (WIFEXITED(status)){
36
 
                        printf("PASS\n");
37
 
                }else{
38
 
                        fprintf(stderr, "FAILED, child did not exit normally\n");
39
 
                }
40
 
        }else{
41
 
                /* child */
42
 
 
43
 
                (void)execve(argv[1], &argv[1], environ);
44
 
 
45
 
                /* exec failed, kill outselves to flag parent */
46
 
 
47
 
                (void)kill(getpid(), SIGKILL);
48
 
        }
49
 
 
50
 
        return 0;
51
 
}