File: get_mount_point.c

package info (click to toggle)
libcgroup 3.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,764 kB
  • sloc: ansic: 14,997; cpp: 9,957; python: 8,340; sh: 5,194; yacc: 470; makefile: 400; lex: 38
file content (50 lines) | stat: -rw-r--r-- 980 bytes parent folder | download
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
// SPDX-License-Identifier: LGPL-2.1-only
#include <libcgroup.h>

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

int main(void)
{
	char *mount_point;
	char string[100];
	int ret;

	strcpy(string, "cpu");

	ret = cgroup_init();
	if (ret) {
		printf("cgroup_init failed with %s\n", cgroup_strerror(ret));
		exit(3);
	}

	ret = cgroup_get_subsys_mount_point(string, &mount_point);
	if (ret) {
		printf("get_mount_point failed with %s\n",
		       cgroup_strerror(ret));
		exit(3);
	}

	printf("The mount point is %s\n", mount_point);
	free(mount_point);

	strcpy(string, "obviouslynonexistsubsys");

	ret = cgroup_get_subsys_mount_point(string, &mount_point);
	if (!ret) {
		printf("get_mount_point failed as it got a ");
		printf("non existent subsys\n");
		exit(3);
	}

	if (ret == ECGROUPNOTEXIST) {
		printf("get_mount_point worked as expected\n");
		return 0;
	}

	printf("get_mount_point failed with %s\n", cgroup_strerror(ret));

	return 3;
}