1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <selinux/selinux.h>
5
main(int argc,char ** argv)6 int main(int argc, char **argv)
7 {
8 pid_t pid;
9 char *buf;
10 int rc;
11
12 if (argc != 2) {
13 fprintf(stderr, "usage: %s pid\n", argv[0]);
14 exit(1);
15 }
16
17 if (sscanf(argv[1], "%d", &pid) != 1) {
18 fprintf(stderr, "%s: invalid pid %s\n", argv[0], argv[1]);
19 exit(2);
20 }
21
22 rc = getpidcon(pid, &buf);
23 if (rc < 0) {
24 fprintf(stderr, "%s: getpidcon() failed\n", argv[0]);
25 exit(3);
26 }
27
28 printf("%s\n", buf);
29 freecon(buf);
30 exit(EXIT_SUCCESS);
31 }
32