/* -*-c-*-
*
- * $Id: client.c,v 1.4 2001/02/06 09:34:53 mdw Exp $
+ * $Id: client.c,v 1.5 2001/02/16 21:23:39 mdw Exp $
*
* Client for TrIPE
*
/*----- Revision history --------------------------------------------------*
*
* $Log: client.c,v $
+ * Revision 1.5 2001/02/16 21:23:39 mdw
+ * Use reliable signal handling for reopening logs.
+ *
* Revision 1.4 2001/02/06 09:34:53 mdw
* Change ERR response to FAIL for consistency with other programs.
*
#include <mLib/alloc.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
-#include <mLib/lbuf.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
#include <mLib/sel.h>
#include <mLib/selbuf.h>
+#include <mLib/sig.h>
#include <mLib/str.h>
#include "util.h"
static FILE *logfp = 0;
static unsigned f = 0;
+static const char *logname = 0;
static int fd;
-static volatile sig_atomic_t reopen = 0;
#define f_bogus 1u
#define f_spawn 2u
errno = e;
}
-static void sighup(int sig)
-{
- reopen = 1;
-}
-
static void writelog(const char *cat, const char *msg)
{
char buf[256];
setvbuf(logfp, 0, _IOLBF, BUFSIZ);
}
+static void sighup(int sig, void *v)
+{
+ logfile(logname);
+}
+
static void version(FILE *fp)
{
pquis(fp, "$, TrIPE version " VERSION "\n");
const char *sock = "tripesock";
const char *spawnpath = "tripe";
string_v spawnopts = DA_INIT;
- const char *logname = 0;
char *p;
ego(argv[0]);
selbuf_init(&bu, &sel, STDIN_FILENO, uline, &bu);
selbuf_init(&bs, &sel, fd, sline, &bs);
for (;;) {
- if (sel_select(&sel))
+ if (sel_select(&sel) && errno != EINTR && errno != EAGAIN)
die(EXIT_FAILURE, "select failed: %s", strerror(errno));
}
}
/* --- Pull everything else out of the box --- */
{
- lbuf b;
- lbuf_init(&b, cline, 0);
+ sel_state sel;
+ selbuf b;
+ sig hup;
+
+ sel_init(&sel);
+ selbuf_init(&b, &sel, fd, cline, 0);
+
if (f & f_syslog)
openlog(QUIS, 0, LOG_DAEMON);
if (logfp) {
- struct sigaction sa;
- sa.sa_handler = sighup;
- sa.sa_flags = 0;
- sigemptyset(&sa.sa_mask);
- sigaction(SIGHUP, &sa, 0);
+ sig_init(&sel);
+ sig_add(&hup, SIGHUP, sighup, 0);
}
for (;;) {
- size_t sz;
- ssize_t n;
- if (reopen) {
- logfile(logname);
- reopen = 0;
- }
- sz = lbuf_free(&b, &p);
- n = read(fd, p, sz);
- if (n < 0) {
- if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
- continue;
- die(EXIT_FAILURE, "read failed: %s", strerror(errno));
- }
- if (n == 0)
- break;
- lbuf_flush(&b, p, n);
+ if (sel_select(&sel) && errno != EINTR && errno != EAGAIN)
+ die(EXIT_FAILURE, "select failed: %s", strerror(errno));
}
- lbuf_close(&b);
}
return (0);