/* -*-c-*-
*
- * $Id: client.c,v 1.5 2001/02/16 21:23:39 mdw Exp $
+ * $Id: client.c,v 1.6 2001/02/22 09:06:08 mdw Exp $
*
* Client for TrIPE
*
/*----- Revision history --------------------------------------------------*
*
* $Log: client.c,v $
+ * Revision 1.6 2001/02/22 09:06:08 mdw
+ * Fix logfile rotation to avoid program collapse.
+ *
* Revision 1.5 2001/02/16 21:23:39 mdw
* Use reliable signal handling for reopening logs.
*
static void logfile(const char *name)
{
- if (logfp)
- fclose(logfp);
- if ((logfp = fopen(name, "a")) == 0) {
- die(EXIT_FAILURE, "error opening logfile `%s': %s",
- name, strerror(errno));
+ FILE *fp;
+
+ if ((fp = fopen(name, "a")) != 0) {
+ if (logfp)
+ fclose(logfp);
+ logfp = fp;
+ setvbuf(logfp, 0, _IOLBF, BUFSIZ);
+ } else {
+ dstr d = DSTR_INIT;
+ dstr_putf(&d, "error opening logfile `%s': %s", name, strerror(errno));
+ if (logfp)
+ writelog("error", d.buf);
+ else if (logname)
+ die(EXIT_FAILURE, d.buf);
+ if (f & f_syslog)
+ syslog(LOG_ERR, d.buf);
+ dstr_destroy(&d);
}
- setvbuf(logfp, 0, _IOLBF, BUFSIZ);
}
static void sighup(int sig, void *v)