Mercurial > dropbear
comparison svr-main.c @ 435:337c45621e81
merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee'
and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 22 Feb 2007 14:53:49 +0000 |
parents | 0aaaf68e97dc c216212001fc |
children | edbee0596531 |
comparison
equal
deleted
inserted
replaced
434:0aaaf68e97dc | 435:337c45621e81 |
---|---|
26 #include "dbutil.h" | 26 #include "dbutil.h" |
27 #include "session.h" | 27 #include "session.h" |
28 #include "buffer.h" | 28 #include "buffer.h" |
29 #include "signkey.h" | 29 #include "signkey.h" |
30 #include "runopts.h" | 30 #include "runopts.h" |
31 #include "random.h" | |
31 | 32 |
32 static size_t listensockets(int *sock, size_t sockcount, int *maxfd); | 33 static size_t listensockets(int *sock, size_t sockcount, int *maxfd); |
33 static void sigchld_handler(int dummy); | 34 static void sigchld_handler(int dummy); |
34 static void sigsegv_handler(int); | 35 static void sigsegv_handler(int); |
35 static void sigintterm_handler(int fish); | 36 static void sigintterm_handler(int fish); |
48 int main(int argc, char ** argv) | 49 int main(int argc, char ** argv) |
49 #endif | 50 #endif |
50 { | 51 { |
51 _dropbear_exit = svr_dropbear_exit; | 52 _dropbear_exit = svr_dropbear_exit; |
52 _dropbear_log = svr_dropbear_log; | 53 _dropbear_log = svr_dropbear_log; |
54 | |
55 disallow_core(); | |
53 | 56 |
54 /* get commandline options */ | 57 /* get commandline options */ |
55 svr_getopts(argc, argv); | 58 svr_getopts(argc, argv); |
56 | 59 |
57 #ifdef INETD_MODE | 60 #ifdef INETD_MODE |
120 char * preauth_addrs[MAX_UNAUTH_CLIENTS]; | 123 char * preauth_addrs[MAX_UNAUTH_CLIENTS]; |
121 | 124 |
122 int childsock; | 125 int childsock; |
123 int childpipe[2]; | 126 int childpipe[2]; |
124 | 127 |
128 /* Note: commonsetup() must happen before we daemon()ise. Otherwise | |
129 daemon() will chdir("/"), and we won't be able to find local-dir | |
130 hostkeys. */ | |
131 commonsetup(); | |
132 | |
125 /* fork */ | 133 /* fork */ |
126 if (svr_opts.forkbg) { | 134 if (svr_opts.forkbg) { |
127 int closefds = 0; | 135 int closefds = 0; |
128 #ifndef DEBUG_TRACE | 136 #ifndef DEBUG_TRACE |
129 if (!svr_opts.usingsyslog) { | 137 if (!svr_opts.usingsyslog) { |
133 if (daemon(0, closefds) < 0) { | 141 if (daemon(0, closefds) < 0) { |
134 dropbear_exit("Failed to daemonize: %s", strerror(errno)); | 142 dropbear_exit("Failed to daemonize: %s", strerror(errno)); |
135 } | 143 } |
136 } | 144 } |
137 | 145 |
138 commonsetup(); | |
139 | |
140 /* should be done after syslog is working */ | 146 /* should be done after syslog is working */ |
141 if (svr_opts.forkbg) { | 147 if (svr_opts.forkbg) { |
142 dropbear_log(LOG_INFO, "Running in background"); | 148 dropbear_log(LOG_INFO, "Running in background"); |
143 } else { | 149 } else { |
144 dropbear_log(LOG_INFO, "Not forking"); | 150 dropbear_log(LOG_INFO, "Not forking"); |
145 } | 151 } |
146 | 152 |
147 /* create a PID file so that we can be killed easily */ | 153 /* create a PID file so that we can be killed easily */ |
148 pidfile = fopen(DROPBEAR_PIDFILE, "w"); | 154 pidfile = fopen(svr_opts.pidfile, "w"); |
149 if (pidfile) { | 155 if (pidfile) { |
150 fprintf(pidfile, "%d\n", getpid()); | 156 fprintf(pidfile, "%d\n", getpid()); |
151 fclose(pidfile); | 157 fclose(pidfile); |
152 } | 158 } |
153 | 159 |
186 } | 192 } |
187 | 193 |
188 val = select(maxsock+1, &fds, NULL, NULL, &seltimeout); | 194 val = select(maxsock+1, &fds, NULL, NULL, &seltimeout); |
189 | 195 |
190 if (exitflag) { | 196 if (exitflag) { |
191 unlink(DROPBEAR_PIDFILE); | 197 unlink(svr_opts.pidfile); |
192 dropbear_exit("Terminated by signal"); | 198 dropbear_exit("Terminated by signal"); |
193 } | 199 } |
194 | 200 |
195 if (val == 0) { | 201 if (val == 0) { |
196 /* timeout reached */ | 202 /* timeout reached */ |