+/* Dies if a *valid* pid file exists already */
+
+static void silc_server_checkpid(SilcServer silcd)
+{
+ if (silcd->config->server_info->pid_file) {
+ int oldpid;
+ char *buf;
+ SilcUInt32 buf_len;
+
+ SILC_LOG_DEBUG(("Checking for another silcd running"));
+ buf = silc_file_readfile(silcd->config->server_info->pid_file, &buf_len);
+ if (!buf)
+ return;
+ oldpid = atoi(buf);
+ silc_free(buf);
+ if (oldpid <= 0)
+ return;
+ kill(oldpid, SIGCHLD); /* this signal does nothing, check if alive */
+ if (errno != ESRCH) {
+ fprintf(stderr, "\nI detected another daemon running with the same pid file.\n");
+ fprintf(stderr, "Please change the config file, or erase the %s\n",
+ silcd->config->server_info->pid_file);
+ exit(1);
+ }
+ }
+}
+
+static void got_hup(int z)
+{
+ /* First, reset all log files (they might have been deleted) */
+ silc_log_reset_all();
+ silc_log_flush_all();
+}
+
+static void stop_server(int z)
+{
+ /* Stop scheduler, the program will stop eventually after noticing
+ that the scheduler is down. */
+ silc_schedule_stop(silcd->schedule);
+}
+