File: groups.c

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (64 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (3)
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
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <grp.h>
#include <sys/wait.h>

#include "zdtmtst.h"

const char *test_doc = "Check that supplementary groups are supported";
const char *test_author = "Pavel Emelianov <xemul@parallels.com>";

int main(int argc, char **argv)
{
	int ng;
	unsigned int *grp, *grp2, i, max;

	test_init(argc, argv);

	ng = getgroups(0, NULL);
	if (ng < 0) {
		pr_perror("Can't get groups");
		return -1;
	}

	grp = malloc((ng + 1) * sizeof(*grp));
	ng = getgroups(ng, grp);
	if (ng < 0) {
		pr_perror("Can't get groups2");
		return -1;
	}

	max = 0;
	for (i = 0; i < ng; i++)
		if (max < grp[i])
			max = grp[i];

	grp[ng++] = max + 1;

	if (setgroups(ng, grp) < 0) {
		pr_perror("Can't set groups");
		return -1;
	}

	test_daemon();
	test_waitsig();

	grp2 = malloc(ng * sizeof(*grp2));

	if (getgroups(ng, grp2) != ng) {
		fail("Nr groups changed");
		return -1;
	}

	if (memcmp(grp, grp2, ng * sizeof(*grp))) {
		fail("Groups have changed");
		return -1;
	}

	pass();

	return 0;
}