From b1ca0e293ef0a5d3d325f49dc02d4b80577dd13c Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Fri, 30 Mar 2001 17:21:58 +0000 Subject: 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 --- src/minilogd.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src') 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 (x0) && 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; } } -- cgit