~serge-hallyn/ubuntu/quantal/lxc/lxc-oracle

« back to all changes in this revision

Viewing changes to src/lxc/lxc_init.c

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2009-04-29 17:49:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090429174913-jvahs1ykizqtodje
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * lxc: linux Container library
 
3
 *
 
4
 * (C) Copyright IBM Corp. 2007, 2008
 
5
 *
 
6
 * Authors:
 
7
 * Daniel Lezcano <dlezcano at fr.ibm.com>
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Lesser General Public
 
11
 * License as published by the Free Software Foundation; either
 
12
 * version 2.1 of the License, or (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with this library; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
22
 */
 
23
 
 
24
#include <stdio.h>
 
25
#include <unistd.h>
 
26
#include <stdlib.h>
 
27
#include <errno.h>
 
28
#include <signal.h>
 
29
#include <sys/types.h>
 
30
#include <sys/wait.h>
 
31
#include <sys/mount.h>
 
32
#define _GNU_SOURCE
 
33
#include <getopt.h>
 
34
 
 
35
static int mount_sysfs;
 
36
static int mount_procfs;
 
37
 
 
38
static struct option options[] = {
 
39
        { "mount-sysfs", no_argument, &mount_sysfs, 1 },
 
40
        { "mount-procfs", no_argument, &mount_procfs, 1 },
 
41
};
 
42
 
 
43
int main(int argc, char *argv[])
 
44
{
 
45
        pid_t pid;
 
46
        int nbargs = 0;
 
47
        char **aargv;
 
48
 
 
49
        while (1) {
 
50
                int ret = getopt_long_only(argc, argv, "", options, NULL);
 
51
                if (ret == -1)
 
52
                        break;
 
53
                if (ret == '?')
 
54
                        exit(1);
 
55
                nbargs++;
 
56
        }
 
57
 
 
58
        if (!argv[optind]) {
 
59
                fprintf(stderr, "missing command to launch\n");
 
60
                exit(1);
 
61
        }
 
62
 
 
63
        aargv = &argv[optind];
 
64
        argc -= nbargs;
 
65
 
 
66
        pid = fork();
 
67
        
 
68
        if (pid < 0)
 
69
                exit(1);
 
70
 
 
71
        if (!pid) {
 
72
                
 
73
                if (mount_sysfs && mount("sysfs", "/sys", "sysfs", 0, NULL)) {
 
74
                        fprintf(stderr, "failed to mount '/sys'\n");
 
75
                        exit(1);
 
76
                }
 
77
                
 
78
                if (mount_procfs && mount("proc", "/proc", "proc", 0, NULL)) {
 
79
                        fprintf(stderr, "failed to mount '/proc'\n");
 
80
                        exit(1);
 
81
                }
 
82
 
 
83
                execvp(aargv[0], aargv);
 
84
                fprintf(stderr, "failed to exec: %s\n", aargv[0]);
 
85
                exit(1);
 
86
        }
 
87
 
 
88
        
 
89
 
 
90
        for (;;) {
 
91
                int status;
 
92
                if (wait(&status) < 0) {
 
93
                        if (errno == ECHILD)
 
94
                                exit(0);
 
95
                        if (errno == EINTR)
 
96
                                continue;
 
97
                        fprintf(stderr, "failed to wait child\n");
 
98
                        return 1;
 
99
                }
 
100
        }
 
101
 
 
102
        return 0;
 
103
}