fprintf(stderr, "pipe failed: %s", strerror(errno));
fprintf(stderr, "pipe failed: %s\n", strerror(errno));
static void setup(struct config *config, int *sockfdp) {    int ret, sockfd;    pid_t logger_pid = -1;    struct sigaction sa;    /* server socket stuff */    sockfd = socket(PF_INET, SOCK_STREAM, 0);    if (sockfd < 0) {        fprintf(stderr, "failed to create socket: %s\n",                strerror(errno));        exit(1);    }    ret = bind(sockfd, config->bind_address->ai_addr,               config->bind_address->ai_addrlen);    if (ret < 0) {        fprintf(stderr, "failed to bind: %s\n",                strerror(errno));        exit(1);    }    ret = listen(sockfd, 4);    if (ret < 0) {        fprintf(stderr, "listen failed: %s\n",                strerror(errno));        exit(1);    }    *sockfdp = sockfd;    /* daemonize */    if (!config->no_daemon && getppid() != 1) {        pid_t pid = fork();        if (pid < 0) {            fprintf(stderr, "fork failed: %s", strerror(errno));            exit(1);        }        if (pid > 0)            exit(0);        setsid();        close(0);        signal(SIGTSTP, SIG_IGN);        signal(SIGTTOU, SIG_IGN);        signal(SIGTTIN, SIG_IGN);        if (verbose >= 3)            printf("daemonized as pid %d\n", getpid());    }    /* write PID file */    if (config->pidfile != NULL) {        FILE *file;        file = fopen(config->pidfile, "w");        if (file == NULL) {            fprintf(stderr, "failed to create '%s': %s\n",                    config->pidfile, strerror(errno));            exit(1);        }        fprintf(file, "%d\n", getpid());        fclose(file);    }    /* start logger process */    if (config->logger != NULL) {        int fds[2];        if (verbose >= 3)            printf("starting logger '%s'\n", config->logger);        ret = pipe(fds);        if (ret < 0) {            fprintf(stderr, "pipe failed: %s", strerror(errno));            exit(1);        }        logger_pid = fork();        if (logger_pid < 0) {            fprintf(stderr, "fork failed: %s", strerror(errno));            exit(1);        } else if (logger_pid == 0) {            if (fds[0] != 0) {                dup2(fds[0], 0);                close(fds[0]);            }            close(fds[1]);            close(1);            close(2);            close(sockfd);            execl("/bin/sh", "sh", "-c", config->logger, NULL);            exit(1);        }        if (verbose >= 2)            printf("logger started as pid %d\n", logger_pid);        dup2(fds[1], 1);        dup2(fds[1], 2);        close(fds[0]);        close(fds[1]);        if (verbose >= 3)            printf("logger connected\n");    }    /* chroot */    if (config->chroot_dir != NULL) {        ret = chroot(config->chroot_dir);        if (ret < 0) {            fprintf(stderr, "chroot '%s' failed: %s",                    config->chroot_dir, strerror(errno));            getchar();            exit(1);        }        chdir("/");    }    /* setuid */    if (config->uid > 0) {        ret = setgroups(0, NULL);        if (ret < 0) {            fprintf(stderr, "setgroups failed: %s", strerror(errno));            exit(1);        }        ret = setregid(config->gid, config->gid);        if (ret < 0) {            fprintf(stderr, "setgid failed: %s", strerror(errno));            exit(1);        }        ret = setreuid(config->uid, config->uid);        if (ret < 0) {            fprintf(stderr, "setuid failed: %s", strerror(errno));            exit(1);        }    }    /* signals */    memset(&sa, 0, sizeof(sa));    sa.sa_handler = exit_signal_handler;    sigaction(SIGHUP, &sa, NULL);    sigaction(SIGTERM, &sa, NULL);    sigaction(SIGINT, &sa, NULL);    sigaction(SIGQUIT, &sa, NULL);    sa.sa_handler = SIG_IGN;    sigaction(SIGUSR1, &sa, NULL);    sigaction(SIGUSR2, &sa, NULL);}