|
Lines 1296-1301
server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
Link Here
|
| 1296 |
} |
1296 |
} |
| 1297 |
} |
1297 |
} |
| 1298 |
|
1298 |
|
|
|
1299 |
int |
| 1300 |
daemon_sync(int nochdir, int noclose, int *sync) |
| 1301 |
{ |
| 1302 |
int fd, child_pipe[2]; |
| 1303 |
char buf; |
| 1304 |
|
| 1305 |
if (sync == NULL) |
| 1306 |
return (-1); |
| 1307 |
|
| 1308 |
if (pipe(child_pipe) == 0) |
| 1309 |
*sync = child_pipe[1]; |
| 1310 |
else |
| 1311 |
*sync = -1; |
| 1312 |
|
| 1313 |
switch (fork()) { |
| 1314 |
case -1: |
| 1315 |
return (-1); |
| 1316 |
case 0: |
| 1317 |
break; |
| 1318 |
default: |
| 1319 |
if (*sync > -1) { |
| 1320 |
close(child_pipe[1]); |
| 1321 |
read(child_pipe[0], &buf, 1); |
| 1322 |
close(child_pipe[0]); |
| 1323 |
} |
| 1324 |
_exit(0); |
| 1325 |
} |
| 1326 |
|
| 1327 |
if (*sync > -1) |
| 1328 |
close(child_pipe[0]); |
| 1329 |
|
| 1330 |
if (setsid() == -1) |
| 1331 |
return (-1); |
| 1332 |
|
| 1333 |
if (!nochdir) |
| 1334 |
(void)chdir("/"); |
| 1335 |
|
| 1336 |
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { |
| 1337 |
(void)dup2(fd, STDIN_FILENO); |
| 1338 |
(void)dup2(fd, STDOUT_FILENO); |
| 1339 |
(void)dup2(fd, STDERR_FILENO); |
| 1340 |
if (fd > 2) |
| 1341 |
(void)close (fd); |
| 1342 |
} |
| 1343 |
return (0); |
| 1344 |
} |
| 1345 |
|
| 1299 |
|
1346 |
|
| 1300 |
/* |
1347 |
/* |
| 1301 |
* Main program for the daemon. |
1348 |
* Main program for the daemon. |
|
Lines 1311-1317
main(int ac, char **av)
Link Here
|
| 1311 |
char *test_user = NULL, *test_host = NULL, *test_addr = NULL; |
1358 |
char *test_user = NULL, *test_host = NULL, *test_addr = NULL; |
| 1312 |
int remote_port; |
1359 |
int remote_port; |
| 1313 |
char *line, *p, *cp; |
1360 |
char *line, *p, *cp; |
| 1314 |
int config_s[2] = { -1 , -1 }; |
1361 |
int sync_p = -1, config_s[2] = { -1 , -1 }; |
| 1315 |
u_int64_t ibytes, obytes; |
1362 |
u_int64_t ibytes, obytes; |
| 1316 |
mode_t new_umask; |
1363 |
mode_t new_umask; |
| 1317 |
Key *key; |
1364 |
Key *key; |
|
Lines 1758-1764
main(int ac, char **av)
Link Here
|
| 1758 |
#ifdef TIOCNOTTY |
1805 |
#ifdef TIOCNOTTY |
| 1759 |
int fd; |
1806 |
int fd; |
| 1760 |
#endif /* TIOCNOTTY */ |
1807 |
#endif /* TIOCNOTTY */ |
| 1761 |
if (daemon(0, 0) < 0) |
1808 |
if (daemon_sync(0, 0, &sync_p) < 0) |
| 1762 |
fatal("daemon() failed: %.200s", strerror(errno)); |
1809 |
fatal("daemon() failed: %.200s", strerror(errno)); |
| 1763 |
|
1810 |
|
| 1764 |
/* Disconnect from the controlling tty. */ |
1811 |
/* Disconnect from the controlling tty. */ |
|
Lines 1808-1814
main(int ac, char **av)
Link Here
|
| 1808 |
*/ |
1855 |
*/ |
| 1809 |
if (!debug_flag) { |
1856 |
if (!debug_flag) { |
| 1810 |
FILE *f = fopen(options.pid_file, "w"); |
1857 |
FILE *f = fopen(options.pid_file, "w"); |
| 1811 |
|
|
|
| 1812 |
if (f == NULL) { |
1858 |
if (f == NULL) { |
| 1813 |
error("Couldn't create pid file \"%s\": %s", |
1859 |
error("Couldn't create pid file \"%s\": %s", |
| 1814 |
options.pid_file, strerror(errno)); |
1860 |
options.pid_file, strerror(errno)); |
|
Lines 1816-1821
main(int ac, char **av)
Link Here
|
| 1816 |
fprintf(f, "%ld\n", (long) getpid()); |
1862 |
fprintf(f, "%ld\n", (long) getpid()); |
| 1817 |
fclose(f); |
1863 |
fclose(f); |
| 1818 |
} |
1864 |
} |
|
|
1865 |
if (sync_p > -1) |
| 1866 |
write(sync_p, "1", 1); |
| 1867 |
close(sync_p); |
| 1819 |
} |
1868 |
} |
| 1820 |
|
1869 |
|
| 1821 |
/* Accept a connection and return in a forked child */ |
1870 |
/* Accept a connection and return in a forked child */ |