src/server/daemon/main.c

Thu, 23 Feb 2012 13:10:04 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 23 Feb 2012 13:10:04 +0100
changeset 24
1a7853a4257e
parent 23
a2c8fc23c90e
child 25
5dee29c7c530
permissions
-rw-r--r--

removed some NSPR dependencies

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2011 Olaf Wintermann. All rights reserved.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <stdlib.h>
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
32 #include <unistd.h>
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
33 #include <signal.h>
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
34 #include <errno.h>
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
35 #include <pthread.h>
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
37 #include "../util/pool.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
38 #include "../public/nsapi.h"
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
39 #include "../util/plist.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "webserver.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #include "httprequest.h"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
45 #include "configmanager.h"
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
46
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
47 int std_pipe_fds[2];
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
48
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 void test() {
4
998844b5ed25 Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
50
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
53 /*
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
54 * SIGUSR1: reload the configuration files
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
55 */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
56 void sig_usr1_reload(int sig) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
57 printf("reload\n");
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
58
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
59 if(cfgmgr_load_config() != 0) {
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
60 fprintf(stderr, "Error: cannot reload configuration");
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
61 }
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 22
diff changeset
62
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
63 signal(SIGUSR1, sig_usr1_reload);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
64 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
65
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
66 /*
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
67 * SIGTERM: stop the server
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
68 */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
69 void sig_term(int sig) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
70 exit(EXIT_SUCCESS);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
71 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
72
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
73 void* log_pipe_thread(void *data) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
74 FILE *log_out = fopen("log.txt", "a");
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
75
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
76 char buf[1024];
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
77 ssize_t r;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
78 while((r = read(std_pipe_fds[0], buf, 1024)) > 0) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
79 fwrite(buf, 1, r, log_out);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
80 fflush(log_out);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
81 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
82
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
83 fclose(log_out);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
84 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
85
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 int main(int argc, char **argv) {
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
87 //test();
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
88
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
89 /* if the -c parameter is specified, we don't create a daemon */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
90 int d = 1;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
91 for(int i=0;i<argc;i++) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
92 char *p = argv[i];
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
93 if(p[0] == '-' && p[1] == 'c') {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
94 d = 0;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
95 break;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
96 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
97 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
98 if(d) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
99 /* create daemon */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
100 pid_t pid = fork();
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
101 if(pid < 0) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
102 return EXIT_FAILURE;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
103 } else if(pid > 0) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
104 return EXIT_SUCCESS;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
105 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
106
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
107 if(setsid() < 0) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
108 printf("setsid failed\n");
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
109 return EXIT_FAILURE;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
110 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
111
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
112 for(int i=0;i<3;i++) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
113 close(i);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
114 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
115
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
116 /* stdio redirection */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
117 /* create pipes */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
118 if(pipe(std_pipe_fds) != 0) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
119 perror("pipe");
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
120 return EXIT_FAILURE;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
121 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
122 //FILE *ws_out = fdopen(std_pipe_fds[1], "w");
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
123 //*stdout = *ws_out;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
124 //*stderr = *ws_out;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
125 dup2(std_pipe_fds[1], 1);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
126 dup2(std_pipe_fds[1], 2);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
127
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
128 pthread_t tid;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
129 pthread_create(&tid, NULL, log_pipe_thread, NULL);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
130 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
131
9
30e51941a673 Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
132 pool_init(NULL, NULL, NULL);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
134 /* add signal handler */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
135 signal(SIGUSR1, sig_usr1_reload);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
136 signal(SIGTERM, sig_term);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
138 /* start webserver */
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 int status;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 status = webserver_init();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 if(status != 0) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 fprintf(stderr, "Cannot initialize server!\n");
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 return EXIT_FAILURE;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 status = webserver_run();
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 if(status != 0) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 fprintf(stderr, "Cannot run server!\n");
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 return EXIT_FAILURE;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
22
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
152 /* TODO: join threads (or not?) */
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
153 while(1) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
154 if(d) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
155 fflush(stdout);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
156 fflush(stderr);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
157 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
158 sleep(10000);
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
159 if(0) {
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
160 break;
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
161 }
adb0bda54e6b Server can run as daemon
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
162 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 return EXIT_SUCCESS;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166

mercurial