+ int error = 0;
+ char *scriptname;
+ char *s;
+ int fd;
+
+ if(netname)
+ {
+ asprintf(&s, "NETNAME=%s", netname);
+ putenv(s); /* Don't free s! see man 3 putenv */
+ }
+#ifdef HAVE_UNSETENV
+ else
+ {
+ unsetenv("NETNAME");
+ }
+#endif
+
+ if(chdir(confbase) < 0)
+ /* This cannot fail since we already read config files from this
+ directory. - Guus */
+ /* Yes this can fail, somebody could have removed this directory
+ when we didn't pay attention. - Ivo */
+ {
+ if(chdir("/") < 0)
+ /* Now if THIS fails, something wicked is going on. - Ivo */
+ syslog(LOG_ERR, _("Couldn't chdir to `/': %m"));
+
+ /* Continue anyway. */
+ }
+
+ asprintf(&scriptname, "%s/%s", confbase, name);
+
+ /* Close all file descriptors */
+ closelog();
+ fcloseall();
+
+ /* Open standard input */
+ if(open("/dev/null", O_RDONLY) < 0)
+ {
+ syslog(LOG_ERR, _("Opening `/dev/null' failed: %m"));
+ error = 1;
+ }
+
+ if(!error)
+ {
+ /* Standard output directly goes to syslog */
+ openlog(name, LOG_CONS | LOG_PID, LOG_DAEMON);
+ /* Standard error as well */
+ if(dup2(1, 2) < 0)
+ {
+ syslog(LOG_ERR, _("System call `%s' failed: %m"),
+ "dup2");
+ error = 1;
+ }
+ }
+
+ if(error && debug_lvl > 1)
+ syslog(LOG_INFO, _("This means that any output the script generates will not be shown in syslog."));
+
+ execl(scriptname, NULL);
+ /* No return on success */
+
+ if(errno != ENOENT) /* Ignore if the file does not exist */
+ syslog(LOG_WARNING, _("Error executing `%s': %m"), scriptname);
+
+ /* No need to free things */
+ exit(0);