| 1544 | } |
| 1545 | |
| 1546 | int daemon_main(void) |
| 1547 | { |
| 1548 | if (is_a_socket(STDIN_FILENO)) { |
| 1549 | int i; |
| 1550 | |
| 1551 | /* we are running via inetd - close off stdout and |
| 1552 | * stderr so that library functions (and getopt) don't |
| 1553 | * try to use them. Redirect them to /dev/null */ |
| 1554 | for (i = 1; i < 3; i++) { |
| 1555 | close(i); |
| 1556 | open("/dev/null", O_RDWR); |
| 1557 | } |
| 1558 | |
| 1559 | return start_daemon(STDIN_FILENO, STDIN_FILENO); |
| 1560 | } |
| 1561 | |
| 1562 | if (!load_config(1)) { |
| 1563 | fprintf(stderr, "Failed to parse config file: %s\n", config_file); |
| 1564 | exit_cleanup(RERR_SYNTAX); |
| 1565 | } |
| 1566 | set_dparams(0); |
| 1567 | |
| 1568 | if (no_detach) |
| 1569 | create_pid_file(); |
| 1570 | else |
| 1571 | become_daemon(); |
| 1572 | |
| 1573 | if (rsync_port == 0 && (rsync_port = lp_rsync_port()) == 0) |
| 1574 | rsync_port = RSYNC_PORT; |
| 1575 | if (bind_address == NULL && *lp_bind_address()) |
| 1576 | bind_address = lp_bind_address(); |
| 1577 | |
| 1578 | log_init(0); |
| 1579 | |
| 1580 | rprintf(FLOG, "rsyncd version %s starting, listening on port %d\n", |
| 1581 | rsync_version(), rsync_port); |
| 1582 | /* TODO: If listening on a particular address, then show that |
| 1583 | * address too. In fact, why not just do getnameinfo on the |
| 1584 | * local address??? */ |
| 1585 | |
| 1586 | start_accept_loop(rsync_port, start_daemon); |
| 1587 | return -1; |
| 1588 | } |
no test coverage detected