diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Jenkinsfile | 3 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | main.c | 18 | ||||
-rw-r--r-- | main.h | 3 |
5 files changed, 27 insertions, 5 deletions
@@ -1,2 +1,4 @@ | |||
1 | main | 1 | main |
2 | main.debug | ||
3 | main.release | ||
2 | 4 | ||
diff --git a/Jenkinsfile b/Jenkinsfile index f452d6b..62f63cb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile | |||
@@ -9,7 +9,8 @@ pipeline { | |||
9 | } | 9 | } |
10 | stage('Build') { | 10 | stage('Build') { |
11 | steps { | 11 | steps { |
12 | sh 'make main' | 12 | sh 'make main BUILD=release' |
13 | sh 'make main BUILD=debug' | ||
13 | } | 14 | } |
14 | } | 15 | } |
15 | } | 16 | } |
@@ -12,13 +12,13 @@ CFLAGS += -I/usr/local/include | |||
12 | FILES := cgi.c http_parser.c | 12 | FILES := cgi.c http_parser.c |
13 | 13 | ||
14 | test: main | 14 | test: main |
15 | ./main | 15 | ./main.${BUILD} |
16 | 16 | ||
17 | main: clean | 17 | main: clean |
18 | $(CC) $(CFLAGS) -o $@ $(FILES) main.c $(LIBS) | 18 | $(CC) $(CFLAGS) -o $@.${BUILD} $(FILES) main.c $(LIBS) |
19 | 19 | ||
20 | clean: | 20 | clean: |
21 | rm -f ./main | 21 | rm -f ./main.${BUILD} |
22 | 22 | ||
23 | # %: | 23 | # %: |
24 | # $(CC) $(CFLAGS) -o $@ $(FILES) main.c $(LIBS) | 24 | # $(CC) $(CFLAGS) -o $@ $(FILES) main.c $(LIBS) |
@@ -80,6 +80,22 @@ static void * answer_request(size_t new_socket) { | |||
80 | return NULL; | 80 | return NULL; |
81 | } | 81 | } |
82 | 82 | ||
83 | |||
84 | int become_daemon(const char * name) { | ||
85 | if(fork()) { | ||
86 | exit(EXIT_SUCCESS); | ||
87 | } else { | ||
88 | setsid(); | ||
89 | if(fork()) { | ||
90 | exit(EXIT_SUCCESS); | ||
91 | } else { | ||
92 | syslog(0, "daemon '%s' is running with pid %d", name, getpid()); | ||
93 | return EXIT_SUCCESS; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | |||
83 | static int serve(int server_fd) | 99 | static int serve(int server_fd) |
84 | { | 100 | { |
85 | struct sockaddr_in address; | 101 | struct sockaddr_in address; |
@@ -127,6 +143,8 @@ int main(const int argc, char const * argv[]) { | |||
127 | ? err(errno, NULL) | 143 | ? err(errno, NULL) |
128 | : listen(server_fd, SOMAXCONN) | 144 | : listen(server_fd, SOMAXCONN) |
129 | ? err(errno, NULL) | 145 | ? err(errno, NULL) |
146 | : become_daemon(argv[0]) | ||
147 | ? err(errno, NULL) | ||
130 | : serve(server_fd) | 148 | : serve(server_fd) |
131 | ? err(errno, NULL) | 149 | ? err(errno, NULL) |
132 | : exit(EXIT_SUCCESS) | 150 | : exit(EXIT_SUCCESS) |
@@ -48,6 +48,7 @@ | |||
48 | #include <arpa/inet.h> | 48 | #include <arpa/inet.h> |
49 | #include <fcntl.h> | 49 | #include <fcntl.h> |
50 | #include <sys/stat.h> | 50 | #include <sys/stat.h> |
51 | #include <syslog.h> | ||
51 | // #include <pthread.h> // maybe later | 52 | // #include <pthread.h> // maybe later |
52 | // }}} | 53 | // }}} |
53 | 54 | ||
@@ -83,4 +84,4 @@ void next_part(Http_Header * http_header, const char * content, size_t content_s | |||
83 | void send_answer(Http_Header * http_header, int fd_socket); | 84 | void send_answer(Http_Header * http_header, int fd_socket); |
84 | void parse_http(size_t new_socket, char * request, size_t request_length); | 85 | void parse_http(size_t new_socket, char * request, size_t request_length); |
85 | 86 | ||
86 | // modeline for vim: shiftwidth=2 tabstop=2 number foldmethod=marker | 87 | // modeline for vim: shiftwidth=2 tabstop=2 number foldmethod=marker foldenable |