- if (pidfile_open(pidfile) < 0) {
- syslog(LOG_CRIT, "unable to write pidfile %s", pidfile);
- return EXIT_FAILURE;
- }
-
- if (drop_privileges(RUNAS_USER, RUNAS_GROUP) < 0) {
- syslog(LOG_CRIT, "unable to drop privileges");
- return EXIT_FAILURE;
- }
-
- if (daemonize && daemon_detach() < 0) {
- syslog(LOG_CRIT, "unable to fork");
- return EXIT_FAILURE;
- }
-
- pidfile_refresh();
-
- addr.sin_port = htons(port);
- sock = tcp_listen((struct sockaddr *)&addr, sizeof(addr));
- if (sock < 0)
+ if (common_setup(pidfile, false, RUNAS_USER, RUNAS_GROUP,
+ daemonize) != EXIT_SUCCESS
+ || start_listener(port) < 0) {