]>
Commit | Line | Data |
---|---|---|
afeecbba SH |
1 | /* liblxcapi |
2 | * | |
8cd80b50 SG |
3 | * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>. |
4 | * Copyright © 2012 Canonical Ltd. | |
afeecbba SH |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2, as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
948955a2 | 19 | #include <lxc/lxccontainer.h> |
afeecbba SH |
20 | |
21 | #include <unistd.h> | |
22 | #include <signal.h> | |
23 | #include <stdio.h> | |
24 | #include <sys/types.h> | |
25 | #include <sys/wait.h> | |
26 | #include <stdlib.h> | |
95ee490b | 27 | #include <string.h> |
afeecbba SH |
28 | #include <errno.h> |
29 | ||
4cd72b69 EV |
30 | #include "memory_utils.h" |
31 | ||
afeecbba SH |
32 | #define MYNAME "lxctest1" |
33 | ||
34 | #define TSTERR(x) do { \ | |
ae5c8b8e | 35 | fprintf(stderr, "%d: %s\n", __LINE__, x); \ |
afeecbba SH |
36 | } while (0) |
37 | ||
39b72573 | 38 | int main(int argc, char *argv[]) |
afeecbba SH |
39 | { |
40 | struct lxc_container *c; | |
4cd72b69 EV |
41 | const char *p1; |
42 | __do_free char *p2 = NULL; | |
afeecbba SH |
43 | int retval = -1; |
44 | ||
45 | c = lxc_container_new(MYNAME, NULL); | |
46 | if (!c) { | |
47 | TSTERR("create using default path"); | |
48 | goto err; | |
49 | } | |
915af839 | 50 | |
afeecbba SH |
51 | p1 = c->get_config_path(c); |
52 | p2 = c->config_file_name(c); | |
53 | if (!p1 || !p2 || strncmp(p1, p2, strlen(p1))) { | |
54 | TSTERR("Bad result for path names"); | |
55 | goto err; | |
56 | } | |
57 | ||
58 | #define CPATH "/boo" | |
59 | #define FPATH "/boo/lxctest1/config" | |
60 | if (!c->set_config_path(c, "/boo")) { | |
61 | TSTERR("Error setting custom path"); | |
62 | goto err; | |
63 | } | |
915af839 | 64 | |
afeecbba | 65 | p1 = c->get_config_path(c); |
4cd72b69 | 66 | free(p2); |
afeecbba SH |
67 | p2 = c->config_file_name(c); |
68 | if (strcmp(p1, CPATH) || strcmp(p2, FPATH)) { | |
69 | TSTERR("Bad result for path names after set_config_path()"); | |
70 | goto err; | |
71 | } | |
72 | lxc_container_put(c); | |
73 | ||
74 | c = lxc_container_new(MYNAME, CPATH); | |
75 | if (!c) { | |
76 | TSTERR("create using custom path"); | |
77 | goto err; | |
78 | } | |
79 | ||
80 | p1 = c->get_config_path(c); | |
4cd72b69 | 81 | free(p2); |
afeecbba SH |
82 | p2 = c->config_file_name(c); |
83 | if (strcmp(p1, CPATH) || strcmp(p2, FPATH)) { | |
84 | TSTERR("Bad result for path names after create with custom path"); | |
85 | goto err; | |
86 | } | |
87 | ||
88 | retval = 0; | |
89 | ||
90 | err: | |
91 | lxc_container_put(c); | |
92 | return retval; | |
93 | } |