Daemonize after transports are created and listening sockets are bound to appropriate ports. This allows to exit with nozero exit code when the binding fails.
git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@17313 06827809-a52a-0410-b366-d66718629ded
diff --git a/agent/snmpd.c b/agent/snmpd.c
index f786369..da38aec 100644
--- a/agent/snmpd.c
+++ b/agent/snmpd.c
@@ -903,19 +903,6 @@
#ifdef BUFSIZ
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
#endif
- /*
- * Initialize the world. Detach from the shell. Create initial user.
- */
- if(!dont_fork) {
- int quit = ! netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
- NETSNMP_DS_AGENT_QUIT_IMMEDIATELY);
- ret = netsnmp_daemonize(quit, snmp_stderrlog_status());
- /*
- * xxx-rks: do we care if fork fails? I think we should...
- */
- if(ret != 0)
- Exit(1); /* Exit logs exit val for us */
- }
SOCK_STARTUP;
init_agent(app_name); /* do what we need to do first. */
@@ -933,6 +920,20 @@
Exit(1); /* Exit logs exit val for us */
}
+ /*
+ * Initialize the world. Detach from the shell. Create initial user.
+ */
+ if(!dont_fork) {
+ int quit = ! netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+ NETSNMP_DS_AGENT_QUIT_IMMEDIATELY);
+ ret = netsnmp_daemonize(quit, snmp_stderrlog_status());
+ /*
+ * xxx-rks: do we care if fork fails? I think we should...
+ */
+ if(ret != 0)
+ Exit(1); /* Exit logs exit val for us */
+ }
+
#if HAVE_GETPID
if (pid_file != NULL) {
/*