chiark
/
gitweb
/
~mdw
/
tripe
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
cfc354f
)
Use reliable signal handling for reopening logs.
author
mdw
<mdw>
Fri, 16 Feb 2001 21:23:39 +0000
(21:23 +0000)
committer
mdw
<mdw>
Fri, 16 Feb 2001 21:23:39 +0000
(21:23 +0000)
client.c
patch
|
blob
|
blame
|
history
diff --git
a/client.c
b/client.c
index 270bbc23f7e70b717939846d53c05bf79eb08bc1..019d68f120f95a6ee9b412d48cca68b17132ea64 100644
(file)
--- a/
client.c
+++ b/
client.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-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
*
*
* Client for TrIPE
*
@@
-29,6
+29,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: client.c,v $
/*----- 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.
*
* Revision 1.4 2001/02/06 09:34:53 mdw
* Change ERR response to FAIL for consistency with other programs.
*
@@
-71,12
+74,12
@@
#include <mLib/alloc.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
#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/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"
#include <mLib/str.h>
#include "util.h"
@@
-94,8
+97,8
@@
static FILE *logfp = 0;
static unsigned f = 0;
static FILE *logfp = 0;
static unsigned f = 0;
+static const char *logname = 0;
static int fd;
static int fd;
-static volatile sig_atomic_t reopen = 0;
#define f_bogus 1u
#define f_spawn 2u
#define f_bogus 1u
#define f_spawn 2u
@@
-118,11
+121,6
@@
static void reap(int sig)
errno = e;
}
errno = e;
}
-static void sighup(int sig)
-{
- reopen = 1;
-}
-
static void writelog(const char *cat, const char *msg)
{
char buf[256];
static void writelog(const char *cat, const char *msg)
{
char buf[256];
@@
-209,6
+207,11
@@
static void logfile(const char *name)
setvbuf(logfp, 0, _IOLBF, BUFSIZ);
}
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");
static void version(FILE *fp)
{
pquis(fp, "$, TrIPE version " VERSION "\n");
@@
-258,7
+261,6
@@
int main(int argc, char *argv[])
const char *sock = "tripesock";
const char *spawnpath = "tripe";
string_v spawnopts = DA_INIT;
const char *sock = "tripesock";
const char *spawnpath = "tripe";
string_v spawnopts = DA_INIT;
- const char *logname = 0;
char *p;
ego(argv[0]);
char *p;
ego(argv[0]);
@@
-420,7
+422,7
@@
int main(int argc, char *argv[])
selbuf_init(&bu, &sel, STDIN_FILENO, uline, &bu);
selbuf_init(&bs, &sel, fd, sline, &bs);
for (;;) {
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));
}
}
die(EXIT_FAILURE, "select failed: %s", strerror(errno));
}
}
@@
-444,36
+446,23
@@
int main(int argc, char *argv[])
/* --- Pull everything else out of the box --- */
{
/* --- 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) {
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 (;;) {
}
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);
}
return (0);