* \param ch the char to search
* \return the position inside of st
*/
-int haschar(char *st,char ch)
+int haschar(const char *st,char ch)
{
- int a, b, len;
+ const char *ptr;
+ int b;
b = 0;
- len = strlen(st);
- for (a = 0; a < len; ++a)
- if (st[a] == ch)
+ ptr = st;
+ while (!IsEmptyStr(ptr))
+ if (*ptr == ch)
++b;
return (b);
}
int len = 0; /**< tally our own length to avoid strlen() delays */
ptr = start;
- memset(buf, 0, maxlen);
-
while (1) {
ch = *ptr++;
if ((len + 1 < (maxlen)) && (ch != 13) && (ch != 10)) {
buf[len++] = ch;
- buf[len] = 0;
}
if ((ch == 10) || (ch == 0)) {
+ buf[len] = 0;
return ptr;
}
}
void dump_vars(void);
void embed_main_menu(void);
void serv_read(char *buf, int bytes);
-int haschar(char *, char);
+int haschar(const char *, char);
void readloop(char *oper);
void read_message(long msgnum, int printable_view, char *section);
void embed_message(char *msgnum_as_string);
int is_https = 0; /**< Nonzero if I am an HTTPS service */
int follow_xff = 0; /**< Follow X-Forwarded-For: header */
int home_specified = 0; /**< did the user specify a homedir? */
+int time_to_die = 0; /**< shold we shut down? */
extern void *context_loop(int);
extern void *housekeeping_loop(void);
extern pthread_mutex_t SessionListMutex;
* param signum the signal we want to forward
*/
pid_t current_child;
-void graceful_shutdown(int signum) {
+void graceful_shutdown_watcher(int signum) {
+ lprintf (1, "bye; shutting down watcher.");
kill(current_child, signum);
exit(0);
}
+/**
+ * \brief shut us down the regular way.
+ * param signum the signal we want to forward
+ */
+pid_t current_child;
+void graceful_shutdown(int signum) {
+// kill(current_child, signum);
+ lprintf (1, "bye going down gracefull.");
+ time_to_die = 1;
+ exit(0);
+}
+
/**
* \brief Start running as a daemon.
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
+ signal(SIGTERM, graceful_shutdown_watcher);
do {
current_child = fork();
else if (current_child == 0) {
signal(SIGTERM, graceful_shutdown);
- return; /* continue starting citadel. */
+ return; /* continue starting webcit. */
}
else {
if (running_as_daemon) {
start_daemon(pidfile);
}
+ else {
+ signal(SIGTERM, graceful_shutdown);
+ }
/** Tell 'em who's in da house */
lprintf(1, SERVER "\n");
{
int ssock;
int i = 0;
- int time_to_die = 0;
int fail_this_transaction = 0;
do {
} while (!time_to_die);
+ lprintf (1, "bye");
pthread_exit(NULL);
}