From: Frédéric Marchal Date: Sat, 18 Sep 2010 12:36:32 +0000 (+0000) Subject: Fix the reading of sarg-general when e-mailing the report. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2cbd315d20e6c7fffe1a19eb64c6a68a4ef72ba0;p=thirdparty%2Fsarg.git Fix the reading of sarg-general when e-mailing the report. --- 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); } }