]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc_attach.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2010
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
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.
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.
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
29 #include <sys/param.h>
30 #include <sys/types.h>
34 #include "arguments.h"
35 #include "namespace.h"
38 lxc_log_define(lxc_attach_ui
, lxc
);
40 static const struct option my_longopts
[] = {
44 static struct lxc_arguments my_args
= {
45 .progname
= "lxc-attach",
49 Execute the specified command - enter the container NAME\n\
52 -n, --name=NAME NAME for name of the container\n",
53 .options
= my_longopts
,
58 int main(int argc
, char *argv
[], char *envp
[])
62 struct passwd
*passwd
;
66 ret
= lxc_arguments_parse(&my_args
, argc
, argv
);
70 ret
= lxc_log_init(my_args
.log_file
, my_args
.log_priority
,
71 my_args
.progname
, my_args
.quiet
);
75 pid
= get_init_pid(my_args
.name
);
77 ERROR("failed to get the init pid");
81 curdir
= get_current_dir_name();
83 ret
= lxc_attach(pid
);
85 ERROR("failed to enter the namespace");
89 if (curdir
&& chdir(curdir
))
90 WARN("could not change directory to '%s'", curdir
);
97 SYSERROR("failed to fork");
105 if (waitpid(pid
, &status
, 0) < 0) {
108 SYSERROR("failed to wait '%d'", pid
);
112 if (WIFEXITED(status
))
113 return WEXITSTATUS(status
);
121 execve(my_args
.argv
[0], my_args
.argv
, envp
);
122 SYSERROR("failed to exec '%s'", my_args
.argv
[0]);
128 passwd
= getpwuid(uid
);
130 SYSERROR("failed to get passwd " \
131 "entry for uid '%d'", uid
);
136 char *const args
[] = {
141 execve(args
[0], args
, envp
);
142 SYSERROR("failed to exec '%s'", args
[0]);