]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/device_add_remove.c
3 * Copyright © 2014 S.Çağlar Onur <caglar@10ur.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <lxc/lxccontainer.h>
24 #include "memory_utils.h"
31 #define NAME "device_add_remove_test"
32 #define DEVICE "/dev/loop-control"
34 int main(int argc
, char *argv
[])
36 __do_close
int fd_log
= -EBADF
;
38 struct lxc_log log
= {};
39 struct lxc_container
*c
= NULL
;
40 char template[sizeof(P_tmpdir
"/attach_XXXXXX")];
42 (void)strlcpy(template, P_tmpdir
"/attach_XXXXXX", sizeof(template));
44 fd_log
= lxc_make_tmpfile(template, false);
46 lxc_error("Failed to create temporary log file for container %s\n", NAME
);
52 log
.prefix
= "device_add_remove";
55 if (lxc_log_init(&log
))
58 c
= lxc_container_new(NAME
, NULL
);
60 fprintf(stderr
, "Unable to instantiate container (%s)...\n", NAME
);
64 if (!c
->create(c
, "busybox", NULL
, NULL
, 1, NULL
)) {
65 fprintf(stderr
, "Creating the container (%s) failed...\n", NAME
);
69 c
->want_daemonize(c
, true);
71 if (!c
->start(c
, false, NULL
)) {
72 fprintf(stderr
, "Starting the container (%s) failed...\n", NAME
);
76 if (!c
->add_device_node(c
, DEVICE
, DEVICE
)) {
77 fprintf(stderr
, "Adding %s to the container (%s) failed...\n", DEVICE
, NAME
);
81 if (!c
->remove_device_node(c
, DEVICE
, DEVICE
)) {
82 fprintf(stderr
, "Removing %s from the container (%s) failed...\n", DEVICE
, NAME
);
87 fprintf(stderr
, "Stopping the container (%s) failed...\n", NAME
);
92 fprintf(stderr
, "Destroying the container (%s) failed...\n", NAME
);
102 while ((buflen
= read(fd_log
, buf
, 1024)) > 0) {
103 buflen
= write(STDERR_FILENO
, buf
, buflen
);
108 (void)unlink(template);
111 lxc_container_put(c
);