]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - src/minilogd.c
- cleanups in sysinit + fix for shutting down bridge
[projects/rc-scripts.git] / src / minilogd.c
index b0432408d479137b7b6f5ce95cfda2d763b7e704..90bce3f8960429c7f094de509fe069d8eda78cc1 100644 (file)
@@ -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,8 +42,8 @@ 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);
-   sock = socket(AF_LOCAL, SOCK_STREAM,0);
+   sleep(2);
+   sock = socket(AF_LOCAL, SOCK_DGRAM,0);
    conn=connect(sock,(struct sockaddr *) &addr,sizeof(addr));
    while (x<buflines) {
       if (!conn) write(sock,buffer[x],strlen(buffer[x])+1);
@@ -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;
@@ -82,7 +90,8 @@ void runDaemon(int sock) {
    done = 0;
    /* Get stat info on /dev/log so we can later check to make sure we
     * still own it... */
-   stat(_PATH_LOG,&s1);
+   if (stat(_PATH_LOG,&s1) != 0)
+         memset(&s1, '\0', sizeof(struct stat));
    while (!done) {
       pfds.fd = sock;
       pfds.events = POLLIN|POLLPRI;
@@ -93,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;
         }
       }
This page took 0.04323 seconds and 4 git commands to generate.