This commit is contained in:
Bandie 2018-03-17 21:18:22 +01:00
parent c856c49a92
commit a79509c974
Signed by: Bandie
GPG Key ID: C1E133BC65A822DD

View File

@ -37,19 +37,19 @@ void help(){
} }
void sig_handler(int signo){ void sig_handler(int signo){
if(signo == SIGTERM || signo == SIGINT){ if(signo == SIGTERM || signo == SIGINT){
// Unverify // Unverify
if(access(VRFFILE, F_OK) != -1){ //File exists? if(access(VRFFILE, F_OK) != -1){ //File exists?
unlink(VRFFILE); unlink(VRFFILE);
} }
exit(0); exit(0);
} }
} }
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
const char prog; const char prog;
int verbose = 0; int verbose = 0;
int statval; int statval;
// Argument handling // Argument handling
@ -62,14 +62,13 @@ int main(int argc, char *argv[]){
verbose = 1; verbose = 1;
} }
// Signal handling // Signal handling
if(signal(SIGTERM, sig_handler) == SIG_ERR || signal(SIGINT, sig_handler) == SIG_ERR) if(signal(SIGTERM, sig_handler) == SIG_ERR || signal(SIGINT, sig_handler) == SIG_ERR)
printf("ERROR: Can't catch signal!"); printf("ERROR: Can't catch signal!");
while(1){ while(1){
if(fork() == 0){
if(fork() == 0){
// Check if program is even executable // Check if program is even executable
if(!(!access(PROGRAM, F_OK) && !access(PROGRAM, R_OK) && !access(PROGRAM, X_OK))){ if(!(!access(PROGRAM, F_OK) && !access(PROGRAM, R_OK) && !access(PROGRAM, X_OK))){
@ -77,57 +76,54 @@ int main(int argc, char *argv[]){
if(access(PROGRAM, F_OK)) fprintf(stderr, "It does not exist.\n"); if(access(PROGRAM, F_OK)) fprintf(stderr, "It does not exist.\n");
else fprintf(stderr, "Access denied. (Are you root?)\n"); else fprintf(stderr, "Access denied. (Are you root?)\n");
return 1; return 1;
} }
else{ else{
// Exec program silently by default // Exec program silently by default
if(!verbose){ if(!verbose){
int fd = open("/dev/null", O_WRONLY | O_CREAT, 0666); int fd = open("/dev/null", O_WRONLY | O_CREAT, 0666);
dup2(fd, 1); dup2(fd, 1);
dup2(fd, 2); dup2(fd, 2);
execlp(PROGRAM, PROGRAM, NULL); execlp(PROGRAM, PROGRAM, NULL);
close(fd); close(fd);
} }
else else
execlp(PROGRAM, PROGRAM, NULL); execlp(PROGRAM, PROGRAM, NULL);
} }
}
else {
} if(verbose)
else { printf("Waiting for %d...\n", getpid());
if(verbose) wait(&statval);
printf("Waiting for %d...\n", getpid()); if(WIFEXITED(statval)){
if(verbose)
printf("Exit: %d\n", statval);
wait(&statval); if(statval == STATUS_OK){
if(WIFEXITED(statval)){ // If exit is STATUS_OK, write file with nothing in it
if(verbose) FILE *f = fopen(VRFFILE, "w");
printf("Exit: %d\n", statval); if(f == NULL){
printf("ERROR opening file");
if(statval == STATUS_OK){ return 1;
// If exit 0, write file with nothing in it }
FILE *f = fopen(VRFFILE, "w"); fclose(f);
if(f == NULL){ }
printf("ERROR opening file"); else if(statval == 256){
exit(1);
}
fclose(f);
}
else if(statval == 256){
return 1; return 1;
} }
else else
// If exit != 0 // If exit != 0
if(access(VRFFILE, F_OK) != -1) //File exists? if(access(VRFFILE, F_OK) != -1) //File exists?
unlink(VRFFILE); unlink(VRFFILE);
} }
} }
sleep(SLEEP); sleep(SLEEP);
} }
sig_handler(SIGTERM); sig_handler(SIGTERM);