| Stephen Smalley | 8290d10 | 2012-01-13 08:53:56 -0500 | [diff] [blame] | 1 | #include <stdio.h> | 
 | 2 | #include <stdlib.h> | 
 | 3 | #include <string.h> | 
 | 4 | #include <unistd.h> | 
 | 5 | #include <errno.h> | 
 | 6 | #include <selinux/selinux.h> | 
 | 7 |  | 
 | 8 | int runcon_main(int argc, char **argv) | 
 | 9 | { | 
 | 10 |     int rc; | 
 | 11 |  | 
 | 12 |     if (argc < 3) { | 
 | 13 |         fprintf(stderr, "usage:  %s context program args...\n", argv[0]); | 
 | 14 |         exit(1); | 
 | 15 |     } | 
 | 16 |  | 
 | 17 |     rc = setexeccon(argv[1]); | 
 | 18 |     if (rc < 0) { | 
 | 19 |         fprintf(stderr, "Could not set context to %s:  %s\n", argv[1], strerror(errno)); | 
 | 20 |         exit(2); | 
 | 21 |     } | 
 | 22 |  | 
 | 23 |     argv += 2; | 
 | 24 |     argc -= 2; | 
 | 25 |     execvp(argv[0], argv); | 
 | 26 |     fprintf(stderr, "Could not exec %s:  %s\n", argv[0], strerror(errno)); | 
 | 27 |     exit(3); | 
 | 28 | } |