]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/lxcpath.c
oss-fuzz: adapt options to oss-fuzz build
[mirror_lxc.git] / src / tests / lxcpath.c
CommitLineData
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 */
e49c56d6
CB
19
20#include "config.h"
21
948955a2 22#include <lxc/lxccontainer.h>
afeecbba
SH
23
24#include <unistd.h>
25#include <signal.h>
26#include <stdio.h>
27#include <sys/types.h>
28#include <sys/wait.h>
29#include <stdlib.h>
95ee490b 30#include <string.h>
afeecbba
SH
31#include <errno.h>
32
4cd72b69
EV
33#include "memory_utils.h"
34
afeecbba
SH
35#define MYNAME "lxctest1"
36
37#define TSTERR(x) do { \
ae5c8b8e 38 fprintf(stderr, "%d: %s\n", __LINE__, x); \
afeecbba
SH
39} while (0)
40
39b72573 41int main(int argc, char *argv[])
afeecbba
SH
42{
43 struct lxc_container *c;
4cd72b69
EV
44 const char *p1;
45 __do_free char *p2 = NULL;
afeecbba
SH
46 int retval = -1;
47
48 c = lxc_container_new(MYNAME, NULL);
49 if (!c) {
50 TSTERR("create using default path");
51 goto err;
52 }
915af839 53
afeecbba
SH
54 p1 = c->get_config_path(c);
55 p2 = c->config_file_name(c);
56 if (!p1 || !p2 || strncmp(p1, p2, strlen(p1))) {
57 TSTERR("Bad result for path names");
58 goto err;
59 }
60
61#define CPATH "/boo"
62#define FPATH "/boo/lxctest1/config"
63 if (!c->set_config_path(c, "/boo")) {
64 TSTERR("Error setting custom path");
65 goto err;
66 }
915af839 67
afeecbba 68 p1 = c->get_config_path(c);
4cd72b69 69 free(p2);
afeecbba
SH
70 p2 = c->config_file_name(c);
71 if (strcmp(p1, CPATH) || strcmp(p2, FPATH)) {
72 TSTERR("Bad result for path names after set_config_path()");
73 goto err;
74 }
75 lxc_container_put(c);
76
77 c = lxc_container_new(MYNAME, CPATH);
78 if (!c) {
79 TSTERR("create using custom path");
80 goto err;
81 }
82
83 p1 = c->get_config_path(c);
4cd72b69 84 free(p2);
afeecbba
SH
85 p2 = c->config_file_name(c);
86 if (strcmp(p1, CPATH) || strcmp(p2, FPATH)) {
87 TSTERR("Bad result for path names after create with custom path");
88 goto err;
89 }
90
91 retval = 0;
92
93err:
94 lxc_container_put(c);
95 return retval;
96}