File: getkeys.c

package info (click to toggle)
lxc 1%3A1.0.6-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 4,800 kB
  • sloc: ansic: 33,735; sh: 11,868; python: 1,223; makefile: 734
file content (72 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (5)
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
/* 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 <errno.h>
#include "lxc/state.h"

#define MYNAME "lxctest1"

int main(int argc, char *argv[])
{
	struct lxc_container *c;
	int len, ret;
	char v3[2048];

	if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
		fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
		ret = 1;
		goto out;
	}

	c->set_config_item(c, "lxc.network.type", "veth");

	len = c->get_keys(c, NULL, NULL, 0);
	if (len < 0) {
		fprintf(stderr, "%d: failed to get length of all keys (%d)\n", __LINE__, len);
		ret = 1;
		goto out;
	}
	ret = c->get_keys(c, NULL, v3, len+1);
	if (ret != len) {
		fprintf(stderr, "%d: failed to get keys (%d)\n", __LINE__, ret);
		ret = 1;
		goto out;
	}
	printf("get_keys returned %d\n%s", ret, v3);

	ret = c->get_keys(c, "lxc.network.0", v3, 2000);
	if (ret < 0) {
		fprintf(stderr, "%d: failed to get nic 0 keys(%d)\n", __LINE__, ret);
		ret = 1;
		goto out;
	}
	printf("get_keys for nic 1 returned %d\n%s", ret, v3);
	ret = 0;

out:
	lxc_container_put(c);
	exit(ret);
}