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