diff options
author | Bill Nottingham <notting@redhat.com> | 2001-03-30 17:21:58 +0000 |
---|---|---|
committer | Bill Nottingham <notting@redhat.com> | 2001-03-30 17:21:58 +0000 |
commit | b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c (patch) | |
tree | f93212e8b245eab1d218ed85a11a9253b7b576dc | |
parent | 9d510f46b9d0e39e548950738100fb6b6318883b (diff) | |
download | initscripts-b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c.tar initscripts-b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c.tar.gz initscripts-b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c.tar.bz2 initscripts-b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c.tar.xz initscripts-b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c.zip |
add an alarm, so we don't wait forever for input (#23482)
wait another second
add an upper bound on how much stuff we'll keep in memory
-rw-r--r-- | src/minilogd.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/minilogd.c b/src/minilogd.c index aba5e7c5..90bce3f8 100644 --- a/src/minilogd.c +++ b/src/minilogd.c @@ -25,6 +25,14 @@ static int buflines=0; int debug; +int recvsock; + +void alarm_handler(int x) { + alarm(0); + close(recvsock); + recvsock = -1; +} + void freeBuffer() { struct sockaddr_un addr; int sock; @@ -34,7 +42,7 @@ void freeBuffer() { addr.sun_family = AF_LOCAL; strncpy(addr.sun_path,_PATH_LOG,sizeof(addr.sun_path)-1); /* wait for klogd to hit syslog */ - sleep(1); + sleep(2); sock = socket(AF_LOCAL, SOCK_DGRAM,0); conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr)); while (x<buflines) { @@ -61,7 +69,7 @@ void cleanup(int exitcode) { void runDaemon(int sock) { struct sockaddr_un addr; - int x,len,addrlen,recvsock,done=0; + int x,len,addrlen,done=0; char *message; struct stat s1,s2; struct pollfd pfds; @@ -94,19 +102,23 @@ void runDaemon(int sock) { if ( (x>0) && pfds.revents & (POLLIN | POLLPRI)) { message = calloc(8192,sizeof(char)); recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen); + alarm(2); + signal(SIGALRM, alarm_handler); len = read(recvsock,message,8192); - if (buffer) - buffer = realloc(buffer,(buflines+1)*sizeof(char *)); - else - buffer = malloc(sizeof(char *)); + alarm(0); + close(recvsock); if (len>0) { - message[strlen(message)]='\n'; - buffer[buflines]=message; - buflines++; - close(recvsock); + if (buflines < 200000) { + if (buffer) + buffer = realloc(buffer,(buflines+1)*sizeof(char *)); + else + buffer = malloc(sizeof(char *)); + message[strlen(message)]='\n'; + buffer[buflines]=message; + buflines++; + } } else { - close(recvsock); recvsock=-1; } } |