]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Detect external commands failures and print the exact command that produced the error...
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 26 Jun 2009 11:04:22 +0000 (11:04 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 26 Jun 2009 11:04:22 +0000 (11:04 +0000)
The format of the date written in sarg-date is forced to prevent a failure if the locale is not en_US.

19 files changed:
authfail.c
dansguardian_log.c
decomp.c
email.c
grepday.c
html.c
index.c
lastlog.c
log.c
realtime.c
siteuser.c
smartfilter.c
sort.c
squidguard_log.c
topsites.c
topuser.c
totday.c
useragent.c
util.c

index e28dc5276e77038a66436246caaa4ef42d88a79b..d4a5a88f77dd1a6edfd6f61c8c296d4dc2823a1b 100644 (file)
@@ -46,6 +46,7 @@ void authfail_report()
    char *str;
    int  z=0;
    int  count=0;
+   int  cstatus;
 
    if(strlen(DataFile) > 0) return;
 
@@ -62,26 +63,30 @@ void authfail_report()
    sprintf(per,"%s/sarg-period",dirname);
    sprintf(report,"%s/authfail.html",dirname);
 
-   sprintf(csort,"sort -b -T %s -k 3,3 -k 5,5 -o '%s' '%s'", TempDir, authfail_in, tmp4);
-   system(csort);
-   unlink(tmp4);
-
    if ((fp_in = fopen(per, "r")) == 0) {
       fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],per);
       exit(1);
    }
-
    fgets(period,sizeof(period),fp_in);
    fclose(fp_in);
 
+   sprintf(csort,"sort -b -T %s -k 3,3 -k 5,5 -o '%s' '%s'", TempDir, authfail_in, tmp4);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 #if defined(HAVE_FOPEN64)
    if((fp_in=(long)fopen64(authfail_in,"r"))==NULL) {
 #else
    if((fp_in=fopen(authfail_in,"r"))==NULL) {
 #endif
-     fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in);
-     exit(1);
+      fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
    }
+   unlink(tmp4);
 
 #if defined(HAVE_FOPEN64)
    if((fp_ou=(long)fopen64(report,"w"))==NULL) {
index 6b526d8efcaade48ba025e231ba46ff385697c0f..af73f950367a9e2c721671ee1757b8c8ac260d54 100644 (file)
@@ -39,6 +39,7 @@ int dansguardian_log()
    char wdata[127];
    int  idata=0;
    int  x, y;
+   int cstatus;
 
    bzero(day, 3);
    bzero(mon, 4);
@@ -167,7 +168,12 @@ int dansguardian_log()
    }
 
    sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou);
-   system(tmp6);
+   cstatus=system(tmp6);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",tmp6);
+      exit(1);
+   }
    unlink(guard_in);
    return;
 }
index db59cf24ab229fb1cc64e6f0a7ce694e2ed483aa..a4c3bc68c70669b28ea49ee0cbf177807c4ee722 100644 (file)
--- a/decomp.c
+++ b/decomp.c
@@ -27,8 +27,8 @@
 
 void decomp(char *arq, char *zip, char *tmp)
 {
-
    char cmd[1024];
+   int cstatus;
 
    if(access(arq, R_OK) != 0) {
       sprintf(cmd,"%s: %s",text[64],arq);
@@ -40,7 +40,12 @@ void decomp(char *arq, char *zip, char *tmp)
       sprintf(cmd,"%s: %s > %s/sarg-file.in (zcat)",text[62],arq,tmp);
       debuga(cmd);
       sprintf(cmd,"zcat %s > %s/sarg-file.in",arq,tmp);
-      system(cmd);
+      cstatus=system(cmd);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: command: %s\n",cmd);
+         exit(1);
+      }
       strcpy(zip,"zcat");
       sprintf(arq,"%s/sarg-file.in",tmp);
       return;
@@ -50,7 +55,12 @@ void decomp(char *arq, char *zip, char *tmp)
       sprintf(cmd,"%s: %s > %s/sarg-file.in (bzcat)",text[62],arq,tmp);
       debuga(cmd);
       sprintf(cmd,"bzcat %s > %s/sarg-file.in",arq,tmp);
-      system(cmd);
+      cstatus=system(cmd);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: command: %s\n",cmd);
+         exit(1);
+      }
       strcpy(zip,"zcat");
       sprintf(arq,"%s/sarg-file.in",tmp);
       return;
@@ -60,7 +70,12 @@ void decomp(char *arq, char *zip, char *tmp)
       sprintf(cmd,"%s: %s (uncompress)",text[62],arq);
       debuga(cmd);
       sprintf(cmd,"uncompress %s",arq);
-      system(cmd);
+      cstatus=system(cmd);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: command: %s\n",cmd);
+         exit(1);
+      }
       arq[strlen(arq)-2]='\0';
       strcpy(zip,"compress");
    }
@@ -72,8 +87,8 @@ void decomp(char *arq, char *zip, char *tmp)
 
 void recomp(char *arq, char *zip) 
 {
-
    char cmd[1024];
+   int cstatus;
 
    if(access(arq, R_OK) != 0) {
       sprintf(cmd,"%s: %s",text[64],arq);
@@ -90,7 +105,12 @@ void recomp(char *arq, char *zip)
    if(strcmp(zip,"compress") == 0)
       sprintf(cmd,"%s %s",zip,arq);
 
-   system(cmd);
+   cstatus=system(cmd);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: command: %s\n",cmd);
+      exit(1);
+   }
    return;
 
 }
diff --git a/email.c b/email.c
index 7f5d71808b264acaae23337cabba7d65754a7799..8974ad3c25b1cbb2893b4466764bd375d7757cf6 100644 (file)
--- a/email.c
+++ b/email.c
@@ -42,6 +42,7 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, cha
    int totuser=0;
    time_t t;
    struct tm *local;
+   int cstatus;
 
    strcpy(wger,dirname);
    strcpy(top1,dirname);
@@ -150,7 +151,12 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, cha
    fclose(fp_top2);
 
    sprintf(csort,"sort -n -T %s -r -k 2,2 -o '%s' '%s'", TempDir, top1, top2);
-   system(csort);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 
    unlink(top2);
 
@@ -313,8 +319,13 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, cha
          printf("%s",buf);
     } else {
       sprintf(buf,"%s -s 'SARG %s, %s' %s <%s",MailUtility,text[55],asctime(local),email,top3);
-      system(buf);
-   }
+      cstatus=system(buf);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: command: %s\n",buf);
+         exit(1);
+      }
+    }
  
    sprintf(csort,"rm -rf %s/sarg",TempDir);
    system(csort);
index 007318703205dd214734c48397b40b6c634222ad..af67fe3749d352937342c5784c7b4d4564a945e5 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -245,6 +245,7 @@ void greport_day(char *user, int *iprel, int *ipuser)
    long long int tot;
    time_t t;
    struct tm *local;
+   int cstatus;
 #ifdef HAVE_GD
 
    if(strcmp(Graphs,"yes") != 0) {
@@ -382,7 +383,12 @@ void greport_day(char *user, int *iprel, int *ipuser)
    if(strcmp(DateFormat,"e") == 0)
       sprintf(csort,"sort -t'/' -k 1,1 -o '%s' '%s'",tmp5,wdirname);
 
-   system(csort);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 
    if((fp_in=fopen(tmp5,"r"))==NULL) {
      fprintf(stderr, "SARG: (grepday) %s: %s\n",text[8],tmp5);
diff --git a/html.c b/html.c
index 3b1fbe43806670e1def40e77d5e0032dc941301a..ac4fdf1fb12795a42a664ba8f0c1bb7a6612fabe 100644 (file)
--- a/html.c
+++ b/html.c
@@ -48,6 +48,7 @@ void htmlrel()
    float perc=0, perc2=0, ouperc=0, inperc=0;
    char *s;
    int  x, count;
+   int cstatus;
 
    if(strstr(ReportType,"users_sites") == 0) return;
 
@@ -484,7 +485,12 @@ void htmlrel()
             fclose(fp_ip2);
 
             sprintf(csort,"sort -n -T %s -k 1,1 -k 5,5 -o '%s' '%s'",TempDir,tmp3,tmp2);
-            system(csort);
+            cstatus=system(csort);
+            if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+               fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+               fprintf(stderr, "SARG: sort command: %s\n",csort);
+               exit(1);
+            }
    
 #if defined(HAVE_FOPEN64)
             if ((fp_ip = (long)fopen64(tmp3, "r")) == 0) {
diff --git a/index.c b/index.c
index 725364fadf4169f09edfa5a0e9afcf8f030c2726..57e0aeb2a8d62aead488a355ff84d64f850cd25c 100644 (file)
--- a/index.c
+++ b/index.c
@@ -48,6 +48,7 @@ void make_index()
    char ftime[128];
    char day[4], mon[4], year[6], hour[10];
    char h[3], m[3], s[3];
+   int cstatus;
 
    if(LastLog[0] != '\0') mklastlog(outdir,debug);
 
@@ -105,7 +106,12 @@ void make_index()
          sprintf(val5,"%s/images",val2);
          if(access(val5, R_OK) != 0) {
             sprintf(val5,"ln -s %simages %s/images",outdir,val2);
-            system(val5);
+            cstatus=system(val5);
+            if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+               fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+               fprintf(stderr, "SARG: command: %s\n",val5);
+               exit(1);
+            }
          }
       } else {
          if(!isdigit(direntp->d_name[0]) && !isdigit(direntp->d_name[1])) continue;
@@ -247,12 +253,18 @@ void make_index()
    if(strcmp(IndexTree,"date") == 0) {
       if(strcmp(IndexSortOrder,"A") == 0) sprintf(warea,"sort -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2);
       else sprintf(warea,"sort -r -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2);
-      system(warea);
-      unlink(wdir_tmp);
+      cstatus=system(warea);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: sort command: %s\n",warea);
+         exit(1);
+      }
       if((fp_tmp=fopen(wdir_tmp2,"r"))==NULL) {
          fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp2);
+         fprintf(stderr, "SARG: sort command: %s\n",warea);
          exit(1);
       }
+      unlink(wdir_tmp);
       if((fp_ou=fopen(wdir,"w"))==NULL) {
          fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir);
          exit(1);
@@ -283,7 +295,12 @@ void make_index()
          sprintf(wdir_tmp3,"%s%s/index.sort",outdir,tmp4);
          if(strcmp(IndexSortOrder,"A") == 0) sprintf(csort,"sort -n '%s' -o '%s'", tmp3, wdir_tmp3);
          else sprintf(csort,"sort -n -r '%s' -o '%s'", tmp3, wdir_tmp3);
-         system(csort);
+         cstatus=system(csort);
+         if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+            fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+            fprintf(stderr, "SARG: sort command: %s\n",csort);
+            exit(1);
+         }
          unlink(tmp3);
          if((fp_tmp2=fopen(wdir_tmp3,"r"))==NULL) {
             fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp3);
@@ -333,7 +350,12 @@ void make_index()
             sprintf(tmp6,"%s%s/%s/index.sort",outdir,tmp4,wwork1);
             if(strcmp(IndexSortOrder,"A") == 0) sprintf(csort,"sort -n '%s' -o '%s'", tmp5, tmp6);
             else sprintf(csort,"sort -n -r '%s' -o '%s'", tmp5, tmp6);
-            system(csort);
+            cstatus=system(csort);
+            if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+               fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+               fprintf(stderr, "SARG: sort command: %s\n",csort);
+               exit(1);
+            }
             unlink(tmp5);
             sprintf(val2,"%s%s/%s/index.html",outdir,tmp4,wwork1);
             sprintf(val3,"%s/%s",tmp4,wwork1);
@@ -370,7 +392,17 @@ void make_index()
    } else {
       if(strcmp(IndexSortOrder,"A") == 0) sprintf(warea,"sort -t';' -k 7,7 -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2);
       else sprintf(warea,"sort -r -t';' -k 7,7 -k 1,1 '%s' -o '%s'", wdir_tmp, wdir_tmp2);
-      system(warea);
+      cstatus=system(warea);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: sort command: %s\n",warea);
+         exit(1);
+      }
+      if((fp_tmp2=fopen(wdir_tmp2,"r"))==NULL) {
+         fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp2);
+         fprintf(stderr, "SARG: sort command: %s\n",warea);
+         exit(1);
+      }
       unlink(wdir_tmp);
       if((fp_ou=fopen(wdir,"w"))==NULL) {
          fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir);
@@ -378,10 +410,6 @@ void make_index()
       }
       write_html_header(fp_ou,".");
       fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[101],hbc1,text[102],hbc1,text[103],hbc1,text[93],hbc1,text[96]);
-      if((fp_tmp2=fopen(wdir_tmp2,"r"))==NULL) {
-         fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir_tmp2);
-         exit(1);
-      }
       while(fgets(buf,MAXLEN,fp_tmp2)!=NULL) {
          if (getword_multisep(period,sizeof(period),buf,';')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir_tmp2); 
index f1f6bffc52f3e59ea0f3a710d3a07e2ed1306d04..19a0c8125272ee2e6ac2e1fdf9926be08ba3cfee 100644 (file)
--- a/lastlog.c
+++ b/lastlog.c
@@ -38,6 +38,7 @@ void mklastlog()
    time_t t;
    struct tm *local;
    struct stat statb;
+   int cstatus;
 
    if(strcmp(LastLog,"0") == 0)
       return;
@@ -68,7 +69,12 @@ void mklastlog()
    fclose(fp_ou);
    
    sprintf(buf,"sort -n -k 1,1 -o '%slastlog' '%s'",outdir,temp);
-   system(buf);
+   cstatus=system(buf);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",buf);
+      exit(1);
+   }
 
    unlink(temp);
 
diff --git a/log.c b/log.c
index 84cbc74d5cca0f831e13ce23a0c59d5531b8329c..258ecc98955f86603b17afa6b75237e237cdaa80 100644 (file)
--- a/log.c
+++ b/log.c
@@ -89,7 +89,8 @@ int main(argc,argv)
    int  chm=0;
    char uagent[MAXLEN];
    char hexclude[MAXLEN];
-   char csort[MAXLEN]; 
+   char csort[MAXLEN];
+   int cstatus;
    char tbuf[128];
    char tbuf2[128];
    char zip[20];
@@ -1578,7 +1579,12 @@ int main(argc,argv)
 
       if(strcmp(ParsedOutputLogCompress,"nocompress") != 0) {
          sprintf(val1,"%s %s",ParsedOutputLogCompress,arq_log);
-         system(val1);
+         cstatus=system(val1);
+         if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+            fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+            fprintf(stderr, "SARG: command: %s\n",val1);
+            exit(1);
+         }
       }
 
       if(debug) {
@@ -1589,7 +1595,12 @@ int main(argc,argv)
 
    if(strstr(ReportType,"denied") != 0) {
       sprintf(csort,"sort -T %s -k 3,3 -k 5,5 -o '%s' '%s'",tmp,tmp5,tmp4);
-      system(csort);
+      cstatus=system(csort);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: sort command: %s\n",csort);
+         exit(1);
+      }
       unlink(tmp4);
    }
  
index 233fca54365a0987751914fb2fc888c9075d1bb5..5f0be08900a0946094cd8612acc2829c1d675841 100755 (executable)
@@ -52,6 +52,7 @@ void getlog()
    char cmd[512];
    char buf[512];
    int  fd1,fd2,nreg;
+   int cstatus;
 
    if(UserTabFile[0] != '\0') {
       if(debug) {
@@ -112,7 +113,12 @@ void getlog()
    fclose(tmp);
 
    sprintf(cmd,"sort -r -k 1,1 -k 2,2 -o %s %s",template2,template1);
-   system(cmd);
+   cstatus=system(cmd);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",cmd);
+      exit(1);
+   }
    unlink(template1);
    datashow(template2);
 }
index 9de29559ae52ca81b803dc669235be72a491eea3..c300cc927a9e70b59d2b0d74ee183c76beaf6aa2 100644 (file)
@@ -49,6 +49,7 @@ void siteuser()
    int ucount=0;
    char *users;
    long long int llbytes=0;
+   int cstatus;
 
    if(strcmp(Privacy,"yes") == 0)
       return;
@@ -69,10 +70,16 @@ void siteuser()
    fclose(fp_in);
 
    sprintf(csort,"sort -k 4,4 -k 1,1 -o '%s' '%s'",general2,general);
-   system(csort);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 
    if((fp_in=fopen(general2,"r"))==NULL) {
      fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],general2);
+     fprintf(stderr, "SARG: sort command: %s\n",csort);
      exit(1);
    }
 
index 3ac38d4c03229665fc365e0c68d422ac2983c51b..c214db4e1b2f4501168a2ec3ff7fdebb595c1f4e 100644 (file)
@@ -51,6 +51,7 @@ void smartfilter_report()
    char smartuser[MAXLEN];
    char *str;
    int  fuser=0;
+   int cstatus;
 
    ouser[0]='\0';
 
@@ -72,13 +73,18 @@ void smartfilter_report()
    fclose(fp_in);
 
    sprintf(csort,"sort -n -k 1,1 -k 2,2 -k 3,3 -o '%s' '%s'",smart_ou,smart_in);
-   system(csort);
-   unlink(smart_in);
-
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
    if((fp_in=fopen(smart_ou,"r"))==NULL) {
-     fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],smart_ou);
-     exit(1);
+      fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],smart_ou);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
    }
+   unlink(smart_in);
 
    if((fp_ou=fopen(report,"w"))==NULL) {
      fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],report);
diff --git a/sort.c b/sort.c
index 7cde7d74f83bb8004569e0e859d2f8c4c057c169..ec2a8381f454ea4924550eefcb4d143544286da9 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -30,6 +30,7 @@ void tmpsort()
 
    DIR *dirp;
    struct dirent *direntp;
+   int cstatus;
 
    char csort[MAXLEN];
    char arqou[MAXLEN], arqin[MAXLEN], wnome[MAXLEN], wnome2[MAXLEN];
@@ -101,7 +102,12 @@ void tmpsort()
         
       strcat(arqou,".txt");
       sprintf(csort,"sort -n -T %s %s -k %s -k %s -k %s -o '%s' '%s'",TempDir,order,field1,field2,field3,arqou,arqin);
-      system(csort);
+      cstatus=system(csort);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: sort command: %s\n",csort);
+         exit(1);
+      }
       unlink(arqin);
 
    }
@@ -120,6 +126,7 @@ void sort_users_log(char *tmp, int debug)
    char wtmp[MAXLEN];
    char wname2[MAXLEN];
    char wdname[MAXLEN];
+   int cstatus;
 
    if(debug) {
       sprintf(msg,"%s",text[138]);
@@ -156,7 +163,12 @@ void sort_users_log(char *tmp, int debug)
       else
          sprintf(csort,"sort -T %s -k 5,5 -k 1,1 -k 2,2 -o '%s/%s.log' '%s/%s.unsort'", 
                                        tmp, wtmp, user, wtmp, user);
-      system(csort);
+      cstatus=system(csort);
+      if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+         fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+         fprintf(stderr, "SARG: sort command: %s\n",csort);
+         exit(1);
+      }
       sprintf(wdname,"%s/%s.unsort",wtmp,user);
       unlink(wdname);
       bzero(user, MAXLEN);
index a43d158d060b6a234c2da8260095f0de41064314..2f2fcfa23ed1fed8563c996b4e8814e7e9a100a1 100644 (file)
@@ -177,6 +177,7 @@ int squidguard_log()
    char user[MAXLEN];
    char ip[30];
    int  x, y;
+   int cstatus;
 
    str2 = user;
 
@@ -295,7 +296,12 @@ int squidguard_log()
    }
 
    sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou);
-   system(tmp6);
+   cstatus=system(tmp6);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",tmp6);
+      exit(1);
+   }
 
    unlink(guard_in);
    return;
index c0077e6aec8ddc00bb8be141807b2f4934d2bcf8..cf7958585b52ee036b9d7e1a0eac72ba8dde9337 100644 (file)
@@ -54,6 +54,7 @@ void topsites()
    long long int tntime=0;
    long long int twork1=0, twork2=0, twork3=0;
    int regs=0;
+   int cstatus;
 
    if(strcmp(Privacy,"yes") == 0)
       return;
@@ -78,10 +79,16 @@ void topsites()
    fclose(fp_in);
 
    sprintf(csort,"sort -k 4,4 -o '%s' '%s'",general2,general);
-   system(csort);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 
    if((fp_in=fopen(general2,"r"))==NULL) {
      fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],general2);
+     fprintf(stderr, "SARG: sort command: %s\n",csort);
      exit(1);
    }
 
@@ -184,16 +191,21 @@ void topsites()
       strcpy(sortt,"-r");
 
    sprintf(csort,"sort %s -k %s -o '%s' '%s'",sortt,sortf,sites,general3);
-   system(csort);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
+   if((fp_in=fopen(sites,"r"))==NULL) {
+      fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],sites);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 
    unlink(general2);
    unlink(general3);
 
-   if((fp_in=fopen(sites,"r"))==NULL) {
-     fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],sites);
-     exit(1);
-   }
-
    if((fp_ou=fopen(report,"w"))==NULL) {
      fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],report);
      exit(1);
index 829c9126d7033b71612e1e8e16730d13b701c610..89a78e52f4c4b0c4f594d3a378bb7ead97bd63f0 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -47,6 +47,7 @@ int topuser()
    int  totuser=0;
    int  topcount=0;
    char *s;
+   int cstatus;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
@@ -155,14 +156,20 @@ int topuser()
       order[0]='\0';
 
    sprintf(csort,"sort -n -T %s %s -k %s -o '%s' '%s'", TempDir, order, sfield, top1, top2);
-   system(csort);
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
+   if((fp_top1=fopen(top1,"a"))==NULL) {
+      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
 
    unlink(top2);
 
-   if((fp_top1=fopen(top1,"a"))==NULL) {
-    fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
-    exit(1);
-   }
    fputs(preg,fp_top1);
    fclose(fp_top1);
 
index bb03947f8e48a057e7049e70f540e3a9bb9c9380..fb1b07968d4680997c58656ac428a701121c915c 100644 (file)
--- a/totday.c
+++ b/totday.c
@@ -46,6 +46,7 @@ void day_totalize(const char *tmp, char *user, int indexonly)
    int  regs=0;
    long long int telap=0;
    long long int tused=0;
+   int cstatus;
 
    if(indexonly) return;
    if(strstr(ReportType,"users_sites") == 0) return;
@@ -55,15 +56,20 @@ void day_totalize(const char *tmp, char *user, int indexonly)
    sprintf(sortout,"%s/%s.sort",tmp,user);
 
    sprintf(csort,"sort -k 1,1 -k 2,2 -o '%s' '%s'",sortout,wdirname);
-   system(csort);
-
-   unlink(wdirname);
-
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
    if((fp_in=fopen(sortout,"r"))==NULL) {
-     fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],sortout);
-     exit(1);
+      fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],sortout);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
    }
 
+   unlink(wdirname);
+
    if((fp_ou=fopen(arqout,"w"))==NULL) {
      fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],arqout);
      exit(1);
index a91f3ad286bd48e9d27a615fc08d55db5a3aee24..4d47da95c1f9b92f7f1264fb1a26c2ac24a7182f 100644 (file)
@@ -38,6 +38,7 @@ void useragent()
    char idate[MAXLEN], fdate[MAXLEN];
    int  agentot=0, agentot2=0, agentdif=0, cont=0;
    unsigned long totregsl=0;
+   int cstatus;
 
    ip[0]='\0';
    data[0]='\0';
@@ -123,15 +124,20 @@ void useragent()
    }
 
    sprintf(csort,"sort -n -t '\\' -k 4,4 -k 3,3 -k 2,2 -k 1,1 -o '%s' '%s'",tmp2,tmp3);
-   system(csort);
-
-   unlink(tmp3);
-
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
    if((fp_in=fopen(tmp2,"r"))==NULL) {
       fprintf(stderr, "SARG: (useragent) %s: %s\n",text[45],tmp2);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
       exit(1);
    }
 
+   unlink(tmp3);
+
    if((fp_ht=fopen(hfile,"w"))==NULL) {
       fprintf(stderr, "SARG: (useragent) %s: %s\n",text[45],hfile);
       exit(1);
@@ -208,15 +214,20 @@ void useragent()
    fclose(fp_ou);
 
    sprintf(csort,"sort -n -t '\\' -k 3,3 -o '%s' '%s'",tmp3,tmp2);
-   system(csort);
-
-   unlink(tmp2);
-
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
    if((fp_in=fopen(tmp3,"r"))==NULL) {
       fprintf(stderr, "SARG: (useragent) %s: %s\n",text[45],tmp3);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
       exit(1);
    }
 
+   unlink(tmp2);
+
    if((fp_ou=fopen(tmp2,"w"))==NULL) {
       fprintf(stderr, "SARG: (useragent) %s: %s\n",text[45],tmp2);
       exit(1);
@@ -258,15 +269,20 @@ void useragent()
    unlink(tmp3);
 
    sprintf(csort,"sort -n -r -k 1,1 -o '%s' '%s'",tmp3,tmp2);
-   system(csort);
-
-   unlink(tmp2);
-
+   cstatus=system(csort);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      exit(1);
+   }
    if((fp_in=fopen(tmp3,"r"))==NULL) {
       fprintf(stderr, "SARG: (useragent) %s: %s\n",text[45],tmp3);
+      fprintf(stderr, "SARG: sort command: %s\n",csort);
       exit(1);
    }
 
+   unlink(tmp2);
+
    if((fp_ht=fopen(hfile,"a"))==NULL) {
       fprintf(stderr, "SARG: (useragent) %s: %s\n",text[45],hfile);
       exit(1);
diff --git a/util.c b/util.c
index 15c3608fc43fc457bc8855a014895771a86a6f80..bd5200c3db49ff86d198385c3170cdbec7c0a8b9 100644 (file)
--- a/util.c
+++ b/util.c
@@ -781,6 +781,7 @@ void vrfydir(char *dir, char *per1, char *addr, char *site, char *us, char *form
    char images[512];
    DIR *dirp;
    struct dirent *direntp;
+   int cstatus;
 
    if(strcmp(IndexTree,"date") == 0) {
       bzero(y1,5);
@@ -908,8 +909,13 @@ void vrfydir(char *dir, char *per1, char *addr, char *site, char *us, char *form
    sprintf(images,"%simages",outdir);
    mkdir(images,0755);
 
-   sprintf(wdir,"date >%s/%s",dirname,"sarg-date");
-   system(wdir);
+   sprintf(wdir,"date \"+%%a %%b %%d %%H:%%M:%%S %%Z %%Y\" >%s/sarg-date",dirname);
+   cstatus=system(wdir);
+   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+      fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
+      fprintf(stderr, "SARG: command: %s\n",wdir);
+      exit(1);
+   }
 
    sprintf(per2,"%s/images",SYSCONFDIR);