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