mirror of https://github.com/dnomd343/ClearDNS
				
				
			
				 7 changed files with 74 additions and 36 deletions
			
			
		| @ -1,2 +1,4 @@ | |||||
| /.idea/ | /.idea/ | ||||
|  | /bin/ | ||||
|  | /build/ | ||||
| /cmake-build-debug/ | /cmake-build-debug/ | ||||
|  | |||||
| @ -1,4 +1,6 @@ | |||||
| cmake_minimum_required(VERSION 2.8.12) | cmake_minimum_required(VERSION 2.8.12) | ||||
| project(cleardns) | project(cleardns) | ||||
| 
 | 
 | ||||
|  | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) | ||||
|  | 
 | ||||
| add_subdirectory(src) | add_subdirectory(src) | ||||
|  | |||||
| @ -0,0 +1,6 @@ | |||||
|  | #ifndef _PROCESS_H_ | ||||
|  | #define _PROCESS_H_ | ||||
|  | 
 | ||||
|  | void init_server(char *init_script, char *custom_script); | ||||
|  | 
 | ||||
|  | #endif | ||||
| @ -0,0 +1,44 @@ | |||||
|  | #include <stdio.h> | ||||
|  | #include <stdlib.h> | ||||
|  | #include <unistd.h> | ||||
|  | #include <sys/wait.h> | ||||
|  | #include <sys/prctl.h> | ||||
|  | 
 | ||||
|  | void process_exec() { | ||||
|  | 
 | ||||
|  | } | ||||
|  | 
 | ||||
|  | void init_server(char *init_script, char *custom_script) { // run init script (blocking) / custom script (non-blocking)
 | ||||
|  |     int status; | ||||
|  |     pid_t init_pid, custom_pid; | ||||
|  | 
 | ||||
|  |     if ((init_pid = fork()) < 0) { | ||||
|  |         perror("Fork error"); | ||||
|  |         exit(2); | ||||
|  |     } else if (init_pid == 0) { // child process
 | ||||
|  |         prctl(PR_SET_PDEATHSIG, SIGKILL); // child process die with father process
 | ||||
|  |         if (execlp("/bin/sh", "/bin/sh", init_script, NULL)) { | ||||
|  |             perror("Init error"); | ||||
|  |             exit(3); | ||||
|  |         } | ||||
|  |     } | ||||
|  |     wait(&status); // blocking wait
 | ||||
|  |     fprintf(stderr, "Init complete\n"); | ||||
|  | 
 | ||||
|  |     if (access(custom_script, F_OK) >= 0) { // custom script exist
 | ||||
|  |         if ((custom_pid = fork()) < 0) { | ||||
|  |             perror("Fork error"); | ||||
|  |             exit(2); | ||||
|  |         } else if (custom_pid == 0) { // child process
 | ||||
|  |             prctl(PR_SET_PDEATHSIG, SIGKILL); // child process die with father process
 | ||||
|  |             if (execlp("/bin/sh", "/bin/sh", custom_script, NULL)) { | ||||
|  |                 perror("Custom script error"); | ||||
|  |                 exit(3); | ||||
|  |             } | ||||
|  |         } | ||||
|  |     } | ||||
|  | } | ||||
|  | 
 | ||||
|  | void server_daemon() { | ||||
|  | 
 | ||||
|  | } | ||||
					Loading…
					
					
				
		Reference in new issue