int enable_syslog = 0;
extern int running_as_daemon;
+void DestroyWorkerList(void);
+
/*
* lprintf() ... Write logging information
*/
master_cleanup(signum);
}
-
/*
* Some initialization stuff...
*/
* native TCP buffering (Linux & *BSD), use that; otherwise, emulate it with
* user-space buffering.
*/
+#ifndef HAVE_DARWIN
#ifdef TCP_CORK
# define HAVE_TCP_BUFFERING
#else
# define HAVE_TCP_BUFFERING
# define TCP_CORK TCP_NOPUSH
# endif
-#endif
-
+#endif /* TCP_CORK */
+#endif /* HAVE_DARWIN */
#ifdef HAVE_TCP_BUFFERING
static unsigned on = 1, off = 0;
setsockopt(ctx->client_socket, IPPROTO_TCP, TCP_CORK, &off, 4);
setsockopt(ctx->client_socket, IPPROTO_TCP, TCP_CORK, &on, 4);
}
+#elif HAVE_DARWIN
+/* Stub functions for Darwin/OS X where TCP buffering isn't liked at all */
+void buffer_output(void) {
+CC->buffering = 0;
+}
+void unbuffer_output(void) {
+CC->buffering = 0;
+}
+void flush_output(void) {
+}
#else
void buffer_output(void) {
if (CC->buffering == 0) {
unlink(serviceptr->sockpath);
}
}
+#ifdef HAVE_OPENSSL
+ destruct_ssl();
+#endif
+ CtdlDestroyProtoHooks();
+ CtdlDestroyDeleteHooks();
+ CtdlDestroyXmsgHooks();
+ CtdlDestroyNetprocHooks();
+ CtdlDestroyUserHooks();
+ CtdlDestroyMessageHook();
+ CtdlDestroyCleanupHooks();
+ CtdlDestroyFixedOutputHooks();
+ CtdlDestroySessionHooks();
+ CtdlDestroyServiceHook();
+ DestroyWorkerList();
}
+
+
/*
* Terminate another session.
* (This could justifiably be moved out of sysdep.c because it
int status = 0;
pid_t child = 0;
FILE *fp;
+ int do_restart = 0;
current_child = 0;
child = fork();
if (child != 0) {
- fp = fopen(file_pid_file, "w");
- if (fp != NULL) {
- fprintf(fp, "%d\n", child);
- fclose(fp);
- }
exit(0);
}
signal(SIGQUIT, SIG_IGN);
setsid();
-// umask(0);
+ umask(0);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
else {
+ fp = fopen(file_pid_file, "w");
+ if (fp != NULL) {
+ fprintf(fp, "%d\n", child);
+ fclose(fp);
+ }
waitpid(current_child, &status, 0);
}
- } while (status != 0);
+ do_restart = 0;
- unlink(file_pid_file);
- exit(0);
+ /* Did the main process exit with an actual exit code? */
+ if (WIFEXITED(status)) {
+ /* Exit code 0 means the watcher should exit */
+ if (WEXITSTATUS(status) == 0) {
+ do_restart = 0;
+ }
+
+ /* Exit code 101-109 means the watcher should exit */
+ else if ( (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109) ) {
+ do_restart = 0;
+ }
+
+ /* Any other exit code means we should restart. */
+ else {
+ do_restart = 1;
+ }
+ }
+
+ /* Any other type of termination (signals, etc.) should also restart. */
+ else {
+ do_restart = 1;
+ }
+
+ } while (do_restart);
+
+ unlink(file_pid_file);
+ exit(WEXITSTATUS(status));
}
pthread_attr_destroy(&attr);
}
+void DestroyWorkerList(void)
+{
+ struct worker_node *cur, *p;
+ cur = worker_list;
+ while (cur != NULL)
+ {
+ p = cur->next;
+ free (cur);
+ cur = p;
+ }
+ worker_list = NULL;
+}
/*
* Create the indexer thread and begin its operation.
do_housekeeping();
check_sched_shutdown();
}
-
+ if (con != NULL) free (con);//// TODO: could this harm other threads?
/* If control reaches this point, the server is shutting down */
return(NULL);
}