#include <atalk/server_ipc.h>
#include <atalk/errchk.h>
#include <atalk/globals.h>
+#include <atalk/netatalk_conf.h>
#include "afp_config.h"
#include "status.h"
static afp_child_t *dsi_start(AFPObj *obj, DSI *dsi, server_child *server_children);
-/* This is registered with atexit() */
-static void afp_exit(void)
+static void afp_exit(int ret)
{
- if (parent_or_child == 0)
- /* Only do this in the parent */
- server_unlock(_PATH_AFPDLOCK);
+ server_unlock(_PATH_AFPDLOCK);
+ exit(ret);
}
int ret;
/* Parse argv args and initialize default options */
- afp_options_parse_cmdline(ac, av);
- obj.argc = ac;
- obj.argv = av;
- if (afp_config_parse(&obj) != 0)
- exit(EXITERR_CONF);
+ afp_options_parse_cmdline(&obj, ac, av);
if (check_lockfile("afpd", _PATH_AFPDLOCK) != 0)
exit(EXITERR_SYS);
/* Log SIGBUS/SIGSEGV SBT */
fault_setup(NULL);
- atexit(afp_exit);
+
+ if (afp_config_parse(&obj) != 0)
+ afp_exit(EXITERR_CONF);
+
+ set_processname("afpd");
+ setuplog(obj.options.logconfig, obj.options.logfile);
/* Save the user's current umask */
obj.options.save_mask = umask(obj.options.umask);
* XXX: this should really be setup after the initial connections. */
if (!(server_children = server_child_alloc(obj.options.connections, CHILD_NFORKS))) {
LOG(log_error, logtype_afpd, "main: server_child alloc: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
memset(&sv, 0, sizeof(sv));
sigemptyset( &sv.sa_mask );
if (sigaction(SIGXFSZ, &sv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
#endif
sv.sa_flags = SA_RESTART;
if ( sigaction( SIGCHLD, &sv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
sigemptyset( &sv.sa_mask );
sv.sa_flags = SA_RESTART;
if ( sigaction( SIGUSR1, &sv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
sigemptyset( &sv.sa_mask );
sv.sa_flags = SA_RESTART;
if ( sigaction( SIGHUP, &sv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
sigemptyset( &sv.sa_mask );
sv.sa_flags = SA_RESTART;
if ( sigaction( SIGTERM, &sv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
sigemptyset( &sv.sa_mask );
sv.sa_flags = SA_RESTART;
if (sigaction(SIGQUIT, &sv, NULL ) < 0 ) {
LOG(log_error, logtype_afpd, "main: sigaction: %s", strerror(errno) );
- exit(EXITERR_SYS);
+ afp_exit(EXITERR_SYS);
}
/* afpd.conf: not in config file: lockfile, connections, configfile
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
if (configinit(&obj) != 0) {
LOG(log_error, logtype_afpd, "main: no servers configured");
- exit(EXITERR_CONF);
+ afp_exit(EXITERR_CONF);
}
pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
configfree(&obj, NULL);
if (configinit(&obj) != 0) {
LOG(log_error, logtype_afpd, "config re-read: no servers configured");
- exit(EXITERR_CONF);
+ afp_exit(EXITERR_CONF);
}
fd_set_listening_sockets(&obj);
}
/* we've forked. */
- if (parent_or_child == 1) {
+ if (child->ipc_fds[0] == -1) {
configfree(obj, dsi);
obj->ipc_fd = child->ipc_fds[1];
- close(child->ipc_fds[0]); /* Close parent IPC fd */
free(child);
afp_over_dsi(obj); /* start a session */
exit (0);