Mercurial > archived > louis > perso > liblxcstats
comparison open.c @ 0:6ce4443e7545
Add the draft of an API to collect statistics on LXC
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Wed, 29 Dec 2010 23:28:14 +0100 |
parents | |
children | 8339ab15527d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6ce4443e7545 |
---|---|
1 #include <errno.h> | |
2 #include <stdbool.h> | |
3 #include <stdio.h> | |
4 #include <mntent.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 | |
8 #include "_lxcstats.h" | |
9 #include "lxcstats.h" | |
10 | |
11 static char * | |
12 lxcst_cgroup_mount_point(void) | |
13 { | |
14 FILE *mtab; | |
15 struct mntent mntbuf; | |
16 char strbuf[1024]; | |
17 bool found = false; | |
18 | |
19 mtab = fopen("/etc/mtab", "r"); | |
20 if (!mtab) | |
21 return (NULL); | |
22 | |
23 while (getmntent_r(mtab, &mntbuf, strbuf, sizeof(strbuf))) { | |
24 if (!strcmp(mntbuf.mnt_type, "cgroup")) { | |
25 found = true; | |
26 break ; | |
27 } | |
28 } | |
29 | |
30 fclose(mtab); | |
31 | |
32 if (found) | |
33 return (strdup(mntbuf.mnt_dir)); | |
34 | |
35 errno = ENOENT; | |
36 return (NULL); | |
37 } | |
38 | |
39 lxcst_handle *lxcst_open(void) | |
40 { | |
41 struct _lxcst_controller *c; | |
42 | |
43 c = calloc(1, sizeof(*c)); | |
44 if (!c) | |
45 return (NULL); | |
46 | |
47 c->cgroup_dir = lxcst_cgroup_mount_point(); | |
48 if (!c->cgroup_dir) | |
49 goto free_controller; | |
50 | |
51 return (c); | |
52 | |
53 free_controller: | |
54 free(c); | |
55 return (NULL); | |
56 } |