From: Frédéric Marchal Date: Tue, 17 Aug 2010 08:59:50 +0000 (+0000) Subject: Fix the reading of sarg-general when e-mailing the report. X-Git-Tag: v2.3.1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faf13291c2cc19a3d4c09cec099733f49cb9b6a0;p=thirdparty%2Fsarg.git Fix the reading of sarg-general when e-mailing the report. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c03f6ab..250193b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION "3.1-pre1") SET(sarg_BUILD "") -SET(sarg_BUILDDATE "Aug-15-2010") +SET(sarg_BUILDDATE "Aug-17-2010") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/email.c b/email.c index 1b8f266..4392e64 100644 --- a/email.c +++ b/email.c @@ -40,14 +40,15 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema char olduser[MAX_USER_LEN], csort[MAXLEN]; char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN], user[MAX_USER_LEN]; char strip1[MAXLEN], strip2[MAXLEN], strip3[MAXLEN], strip4[MAXLEN], strip5[MAXLEN], strip6[MAXLEN], strip7[MAXLEN]; - char buf[MAXLEN]; + char *buf; + char warea[MAXLEN]; int totuser=0; time_t t; struct tm *local; int cstatus; - char warea[MAXLEN]; struct getwordstruct gwarea; struct generalitemstruct item; + longline line; snprintf(wger,sizeof(wger),"%s/sarg-general",dirname); if((fp_in=fopen(wger,"r"))==NULL) { @@ -70,8 +71,13 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema olduser[0]='\0'; totuser=0; - while(fgets(warea,sizeof(warea),fp_in)) { - ger_read(warea,&item,wger); + if ((line=longline_create())==NULL) { + debuga(_("Not enough memory to read file %s\n"),wger); + exit(EXIT_FAILURE); + } + + while((buf=longline_read(fp_in,line))!=NULL) { + ger_read(buf,&item,wger); if(item.total) continue; if(strcmp(olduser,item.user) != 0) { @@ -97,6 +103,8 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema tnacc+=item.nacc; tnelap+=item.nelap; } + fclose(fp_in); + longline_destroy(&line); if (olduser[0] != '\0') { #if defined(__FreeBSD__) @@ -109,7 +117,6 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema ttnelap+=tnelap; } - fclose(fp_in); fclose(fp_top2); sprintf(csort,"sort -n -T \"%s\" -r -k 2,2 -o \"%s\" \"%s\"", TempDir, top1, top2); @@ -175,6 +182,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema while(fgets(warea,sizeof(warea),fp_top1)) { + fixendofline(warea); getword_start(&gwarea,warea); if (getword(user,sizeof(user),&gwarea,'\t')<0) { debuga(_("There is an invalid user ID in file %s\n"),top1); @@ -188,7 +196,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema debuga(_("There is an invalid number of access in file %s\n"),top1); exit(EXIT_FAILURE); } - if (getword_atoll(&elap,&gwarea,'\t')<0) { + if (getword_atoll(&elap,&gwarea,'\0')<0) { debuga(_("There is an invalid elapsed time in file %s\n"),top1); exit(EXIT_FAILURE); } @@ -247,14 +255,14 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema exit(EXIT_FAILURE); } - while(fgets(buf,sizeof(buf),fp_top3)!=NULL) - fputs(buf,stdout); + while(fgets(warea,sizeof(warea),fp_top3)!=NULL) + fputs(warea,stdout); } else { - snprintf(buf,sizeof(buf),"\"%s\" -s \"SARG %s, %s\" \"%s\" <\"%s\"",MailUtility,_("Report"),asctime(local),email,top3); - cstatus=system(buf); + snprintf(warea,sizeof(warea),"\"%s\" -s \"SARG %s, %s\" \"%s\" <\"%s\"",MailUtility,_("Report"),asctime(local),email,top3); + cstatus=system(warea); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { debuga(_("command return status %d\n"),WEXITSTATUS(cstatus)); - debuga(_("command: %s\n"),buf); + debuga(_("command: %s\n"),warea); exit(EXIT_FAILURE); } } diff --git a/include/info.h b/include/info.h index 633a7ed..6413520 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Aug-15-2010" +#define VERSION PACKAGE_VERSION" Aug-17-2010" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net"