SVN: rc-scripts/trunk/src/initlog.c

arekm arekm at pld-linux.org
Sat Oct 9 23:21:50 CEST 2010


Author: arekm
Date: Sat Oct  9 23:21:50 2010
New Revision: 11840

Modified:
   rc-scripts/trunk/src/initlog.c
Log:
Update initlog from initscripts.

Modified: rc-scripts/trunk/src/initlog.c
==============================================================================
--- rc-scripts/trunk/src/initlog.c	(original)
+++ rc-scripts/trunk/src/initlog.c	Sat Oct  9 23:21:50 2010
@@ -51,7 +51,7 @@
 void readConfiguration(char *fname) {
     int fd,num=0;
     struct stat sbuf;
-    char *data,*line, *d;
+    char *data,*line;
     regex_t *regexp;
     int lfac=-1,lpri=-1;
     
@@ -60,7 +60,7 @@
 	    close(fd);
 	    return;
     }
-    d = data=malloc(sbuf.st_size+1);
+    data=malloc(sbuf.st_size+1);
     if (read(fd,data,sbuf.st_size)!=sbuf.st_size) {
 	    close(fd);
 	    free(data);
@@ -110,7 +110,6 @@
     }
     if (lfac!=-1) logfacility=lfac;
     if (lpri!=-1) logpriority=lpri;
-    free(d);
 }
     
 char *getLine(char **data) {
@@ -249,10 +248,7 @@
 	) {
 	DDEBUG("starting daemon failed, pooling entry %d\n",logEntries);
 	logData=realloc(logData,(logEntries+1)*sizeof(struct logInfo));
-	logData[logEntries].fac = logEnt->fac;
-	logData[logEntries].pri = logEnt->pri;
-	logData[logEntries].cmd = strdup(logEnt->cmd);
-	logData[logEntries].line = strdup(logEnt->line);
+	logData[logEntries]= (*logEnt);
 	logEntries++;
     } else {
 	if (logEntries>0) {
@@ -283,22 +279,19 @@
 	/* insert more here */
 	NULL
     };
-    int x=0,len, rc;
+    int x=0,len;
     struct logInfo logentry;
     
     if (cmd) {
-	logentry.cmd = basename(cmd);
+	logentry.cmd = strdup(basename(cmd));
 	if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') &&
 	    ( logentry.cmd[1] >= '0' && logentry.cmd[1] <= '9' ) &&
 	    ( logentry.cmd[2] >= '0' && logentry.cmd[2] <= '9' ) )
 	  logentry.cmd+=3;
-	logentry.cmd = strdup(logentry.cmd);
     } else
       logentry.cmd = strdup(_("(none)"));
-    if (!string) {
-      string = alloca(strlen(cmd)+1);
-      strcpy(string,cmd);
-    }
+    if (!string)
+      string = strdup(cmd);
     
     while (eventtable[x] && x<eventtype) x++;
     if (!(eventtable[x])) x=0;
@@ -310,33 +303,25 @@
     logentry.pri = logpriority;
     logentry.fac = logfacility;
     
-    rc = logLine(&logentry);
-    free(logentry.line);
-    free(logentry.cmd);
-    return rc;
+    return logLine(&logentry);
 }
 
 int logString(char *cmd, char *string) {
     struct logInfo logentry;
-    int rc;
     
     if (cmd) {
-	logentry.cmd = basename(cmd);
+	logentry.cmd = strdup(basename(cmd));
 	if ((logentry.cmd[0] =='K' || logentry.cmd[0] == 'S') && 
 	    ( logentry.cmd[1] >= '0' && logentry.cmd[1] <= 0x39 ) &&
 	    ( logentry.cmd[2] >= '0' && logentry.cmd[2] <= 0x39 ) )
 	  logentry.cmd+=3;
-	logentry.cmd = strdup(logentry.cmd);
     } else
       logentry.cmd = strdup(_(""));
     logentry.line = strdup(string);
     logentry.pri = logpriority;
     logentry.fac = logfacility;
     
-    rc = logLine(&logentry);
-    free(logentry.line);
-    free(logentry.cmd);
-    return rc;
+    return logLine(&logentry);
 }
 
 int processArgs(int argc, char **argv, int silent) {


More information about the pld-cvs-commit mailing list