From b23b175f8f7701e17e888b152adb57409d618d33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Wed, 25 Mar 2009 23:18:46 +0000 Subject: [PATCH] * make some pointers const... * trace whether we were shut down regular, or we crashed/were killed/... * send an aide message if we unconditionaly exit. --- citadel/msgbase.c | 4 ++-- citadel/msgbase.h | 2 +- citadel/server_main.c | 8 ++++++++ citadel/sysdep.c | 32 ++++++++++++++++++++++++++++++-- citadel/sysdep_decls.h | 1 + 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 8a1424a1b..60648431e 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -3031,8 +3031,8 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ /* * Convenience function for generating small administrative messages. */ -void quickie_message(char *from, char *fromaddr, char *to, char *room, char *text, - int format_type, char *subject) +void quickie_message(const char *from, const char *fromaddr, char *to, char *room, const char *text, + int format_type, const char *subject) { struct CtdlMessage *msg; struct recptypes *recp = NULL; diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 560977361..4d4876791 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -100,7 +100,7 @@ void cmd_dlat (char *cmdbuf); long send_message (struct CtdlMessage *); void loadtroom (void); long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, char *, int); -void quickie_message (char *, char *, char *, char *, char *, int, char *); +void quickie_message (const char *, const char *, char *, char *, const char *, int, const char *); void cmd_ent0 (char *entargs); void cmd_dele (char *delstr); void cmd_move (char *args); diff --git a/citadel/server_main.c b/citadel/server_main.c index 2d7d65717..b3d110cd8 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -310,6 +310,14 @@ int main(int argc, char **argv) start_chkpwd_daemon(); } + + /* + * check, whether we're fired up another time after a crash. + * if, post an aide message, so the admin has a chance to react. + */ + checkcrash (); + + /* * Now that we've bound the sockets, change to the Citadel user id and its * corresponding group ids diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 995742b40..359b4c33b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -896,6 +896,9 @@ void graceful_shutdown(int signum) { exit(0); } +int nFireUps = 0; +int nFireUpsNonRestart = 0; +pid_t ForkedPid = 1; /* * Start running as a daemon. @@ -951,9 +954,8 @@ void start_daemon(int unused) { } waitpid(current_child, &status, 0); } - do_restart = 0; - + nFireUpsNonRestart = nFireUps; /* Did the main process exit with an actual exit code? */ if (WIFEXITED(status)) { @@ -970,12 +972,16 @@ void start_daemon(int unused) { /* Any other exit code means we should restart. */ else { do_restart = 1; + nFireUps++; + ForkedPid = current_child; } } /* Any other type of termination (signals, etc.) should also restart. */ else { do_restart = 1; + nFireUps++; + ForkedPid = current_child; } } while (do_restart); @@ -986,6 +992,28 @@ void start_daemon(int unused) { +void checkcrash(void) +{ + if (nFireUpsNonRestart != nFireUps) + { + StrBuf *CrashMail; + + CrashMail = NewStrBuf(); + CtdlLogPrintf (CTDL_ALERT, "----------------sending crash mail\n"); + StrBufPrintf(CrashMail, + "Your CitServer is just recovering from an unexpected termination.\n" + " this maybe the result of an error in citserver or an external influence.\n" + " You can get more information on this by enabling coredumping; for more information see\n" + " http://citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n" + " If you already did, the file you're looking for most probably is %score.%d\n" + " Yours faithfully...", + ctdl_run_dir, ForkedPid); + aide_message(ChrPtr(CrashMail), "Citadel server crashed."); + FreeStrBuf(&CrashMail); + } +} + + /* * Generic routine to convert a login name to a full name (gecos) * Returns nonzero if a conversion took place diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index 8a16f7305..802ae3305 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -70,6 +70,7 @@ void sysdep_master_cleanup (void); void kill_session (int session_to_kill); void *sd_context_loop (struct CitContext *con); void start_daemon (int do_close_stdio); +void checkcrash(void); void cmd_nset (char *cmdbuf); int convert_login (char *NameToConvert); void *worker_thread (void *arg); -- 2.30.2