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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/environ.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
 
/* $Id: environ.c 427 2007-03-08 00:09:47Z steve-beattie $ */
2
 
 
3
 
/*      Copyright (C) 2002-2006 Novell/SUSE
4
 
 *
5
 
 *      This program is free software; you can redistribute it and/or
6
 
 *      modify it under the terms of the GNU General Public License as
7
 
 *      published by the Free Software Foundation, version 2 of the
8
 
 *      License.
9
 
 */
10
 
 
11
 
#include <stdio.h>
12
 
#include <stdlib.h>
13
 
#include <string.h>
14
 
#include <unistd.h>
15
 
#include <errno.h>
16
 
#include <sys/wait.h>
17
 
 
18
 
#define RET_FAILURE 0
19
 
#define RET_SUCCESS 1
20
 
#define RET_CHLD_SUCCESS 2
21
 
#define RET_CHLD_FAILURE 3
22
 
#define RET_CHLD_SIGNAL 4
23
 
 
24
 
int interp_status(int status)
25
 
{
26
 
        int rc;
27
 
 
28
 
        if (WIFEXITED(status)) {
29
 
                if (WEXITSTATUS(status) == 0) {
30
 
                        rc = RET_CHLD_SUCCESS;
31
 
                } else {
32
 
                        rc = RET_CHLD_FAILURE;
33
 
                }
34
 
        } else {
35
 
                rc = RET_CHLD_SIGNAL;
36
 
        }
37
 
 
38
 
        return rc;
39
 
}
40
 
 
41
 
int main(int argc, char *argv[])
42
 
{
43
 
        pid_t pid;
44
 
        int status;
45
 
        int retval = 1;
46
 
 
47
 
        if (argc < 3 || !strchr(argv[2], '=')) {
48
 
                fprintf(stderr, "Usage: %s program VAR=value\n", argv[0]);
49
 
                return 1;
50
 
        }
51
 
 
52
 
        putenv(strdup(argv[2]));
53
 
 
54
 
        pid = fork();
55
 
 
56
 
        if (pid > 0) {
57
 
                /* parent */
58
 
                while (wait(&status) != pid);
59
 
                        /* nothing */
60
 
 
61
 
                if (!WIFSTOPPED(status)) {
62
 
                        retval = interp_status(status);
63
 
                }
64
 
 
65
 
                if (retval == RET_CHLD_SUCCESS) {
66
 
                        printf("PASS\n");
67
 
                        retval = 0;
68
 
                }
69
 
 
70
 
        } else if (pid == 0) {
71
 
                 /* child */
72
 
                retval = execl(argv[1], argv[1], argv[2], (char *) NULL);
73
 
                return retval;
74
 
        } else {
75
 
                /* error */
76
 
                perror("FAIL: fork() failed:");
77
 
                return 1;
78
 
        }
79
 
 
80
 
        return retval;
81
 
}
82