~serge-hallyn/ubuntu/quantal/lxc/lxc-aa-custom-profile

« back to all changes in this revision

Viewing changes to src/lxc/lxc_start.c

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter, Stéphane Graber, Guido Trotter
  • Date: 2010-01-10 10:40:21 UTC
  • mfrom: (1.1.2 upstream) (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100110104021-z8rj5zw5mlvra08l
Tags: 0.6.4-1
[ Stéphane Graber ]
* Upgrade standards-version to 3.8.3
* Drop the copy of etc/* from rules as "etc" is no longer in the tarball

[ Guido Trotter ]
* New Upstream Version
* Update libcap2-dev dependency to libcap-dev
* Install upstream-built man pages via debian/lxc.manpages
* Drop unneeded docbook-utils build dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * License along with this library; if not, write to the Free Software
21
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
22
 */
 
23
#define _GNU_SOURCE
23
24
#include <stdio.h>
 
25
#undef _GNU_SOURCE
24
26
#include <libgen.h>
 
27
#include <stdlib.h>
25
28
#include <unistd.h>
26
29
#include <string.h>
27
30
#include <termios.h>
39
42
 
40
43
#include <lxc/lxc.h>
41
44
#include <lxc/log.h>
 
45
#include <lxc/utils.h>
 
46
 
42
47
#include "arguments.h"
 
48
#include "config.h"
43
49
 
44
50
lxc_log_define(lxc_start, lxc);
45
51
 
47
53
{
48
54
        switch (c) {
49
55
        case 'd': args->daemonize = 1; break;
 
56
        case 'f': args->rcfile = arg; break;
50
57
        }
51
58
        return 0;
52
59
}
53
60
 
54
61
static const struct option my_longopts[] = {
55
62
        {"daemon", no_argument, 0, 'd'},
 
63
        {"rcfile", required_argument, 0, 'f'},
56
64
        LXC_COMMON_OPTIONS
57
65
};
58
66
 
65
73
\n\
66
74
Options :\n\
67
75
  -n, --name=NAME      NAME for name of the container\n\
68
 
  -d, --daemon         daemonize the container",
 
76
  -d, --daemon         daemonize the container\n\
 
77
  -f, --rcfile=FILE    Load configuration file FILE\n",
69
78
        .options   = my_longopts,
70
79
        .parser    = my_parser,
71
80
        .checker   = NULL,
102
111
        if (!memcmp(tios, &current_tios, sizeof(*tios)))
103
112
                return 0;
104
113
 
105
 
 
106
114
        oldhandler = signal(SIGTTOU, SIG_IGN);
107
115
        ret = tcsetattr(0, TCSADRAIN, tios);
108
116
        if (ret)
123
131
                '\0',
124
132
        };
125
133
 
 
134
        char *rcfile = NULL;
 
135
 
126
136
        if (lxc_arguments_parse(&my_args, argc, argv))
127
137
                return err;
128
138
 
135
145
                         my_args.progname, my_args.quiet))
136
146
                return err;
137
147
 
 
148
        /* rcfile is specified in the cli option */
 
149
        if (my_args.rcfile)
 
150
                rcfile = (char *)my_args.rcfile;
 
151
        else {
 
152
                if (!asprintf(&rcfile, LXCPATH "/%s/config", my_args.name)) {
 
153
                        SYSERROR("failed to allocate memory");
 
154
                        return err;
 
155
                }
 
156
 
 
157
                /* container configuration does not exist */
 
158
                if (access(rcfile, F_OK)) {
 
159
                        free(rcfile);
 
160
                        rcfile = NULL;
 
161
                }
 
162
        }
 
163
 
138
164
        if (my_args.daemonize) {
139
165
 
140
166
                /* do not chdir as we want to open the log file,
157
183
                        open(my_args.log_file, O_RDONLY | O_CLOEXEC);
158
184
                        open(my_args.log_file, O_RDONLY | O_CLOEXEC);
159
185
                }
160
 
 
161
 
                chdir("/");
162
186
        }
163
187
 
164
188
        save_tty(&tios);
165
189
 
166
 
        err = lxc_start(my_args.name, args);
 
190
        err = lxc_start(my_args.name, args, rcfile);
167
191
 
168
192
        restore_tty(&tios);
169
193