bug fix - logging of shared badwidth classes, better error reporting
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 15 May 2012 12:50:17 +0000 (12:50 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 15 May 2012 12:50:17 +0000 (12:50 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@179 251d49ef-1d17-4917-a970-b30cf55b089b

prometheus.c

index b4ed05dfd83384163601ccfd75f1cbee567ea0bb..5288dfe8c8fcdc4fe1890dc1a094e284e756d8e0 100644 (file)
@@ -895,7 +895,7 @@ void parse_ip_log(int argc, char **argv)
   }\r
  }\r
  sprintf(str,"%s/%s-%s.html",html_log_dir,year,month);\r
- printf("Writing %s ...",str);\r
+ printf("Writing %s ... ",str);\r
  f=fopen(str,"w");\r
  if(f)\r
  {\r
@@ -1030,8 +1030,35 @@ void parse_ip_log(int argc, char **argv)
   fclose(f);\r
   puts(" done.");\r
  }\r
+ else\r
+ {\r
+  perror(str);\r
+ }\r
+}\r
+\r
+void append_log(struct IP *self) /*using global variables*/\r
+{\r
+ char *d, *str;\r
+ FILE *f; \r
+\r
+ date(d); /* this is typical cll1.h macro - prints current date */ \r
+ string(str,STRLEN); \r
+ sprintf(str,"%s/%s.log", log_dir, self->name);\r
+ f=fopen(str,"a");\r
+ if(f)\r
+ {\r
+  fprintf(f,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
+            time(NULL), self->name, self->traffic, self->direct, self->proxy,\r
+            self->upload, self->min, self->max, self->desired, self->lmsid, d); /* d = date*/\r
+  fclose(f);\r
+ }\r
+ else\r
+ {\r
+  perror(str);\r
+ }\r
 }\r
 \r
+\r
 /*-----------------------------------------------------------------*/\r
 /* Are you looking for int main(int argc, char **argv) ? :-))      */\r
 /*-----------------------------------------------------------------*/\r
@@ -1448,7 +1475,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  if(just_flush)\r
  {\r
   fclose(iptables_file);\r
-  if(log_file) fclose(log_file);\r
+  if(log_file)\r
+  { \r
+   fclose(log_file);\r
+  }\r
   puts("Just flushed iptables and tc classes - now exiting ...");\r
   exit(0);\r
  }\r
@@ -1592,10 +1622,11 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  }\r
  else if(!dry_run && !just_flush)\r
  {\r
+  const char *previous="/var/run/prometheus.previous";\r
   /*-----------------------------------------------------------------*/\r
-  printf("Writing data transfer database ...\n");\r
+  printf("Writing data transfer database %s ... ", previous);\r
   /*-----------------------------------------------------------------*/\r
-  f=fopen("/var/run/prometheus.previous","w");\r
+  f=fopen(previous,"w");\r
   if(f)\r
   {\r
    for_each(ip,ips)\r
@@ -1607,6 +1638,11 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     }\r
    }\r
    fclose(f);\r
+   puts(" done.");\r
+  }\r
+  else\r
+  {\r
+   perror(previous);\r
   }\r
   f=fopen(html,"w");\r
   ptr=html;\r
@@ -1684,7 +1720,6 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   unsigned long long total_traffic=0, total_direct=0, total_proxy=0, total_upload=0, tmp_sum=0;\r
   int active_classes=0;\r
   int colspan=12;\r
-  FILE *iplog;\r
   struct Sum {unsigned long long l; int i; list(Sum);} *sum,*sums=NULL;\r
   int limit_count=0, prio_count=0;\r
   int popup_button=0;\r
@@ -1815,6 +1850,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      for_each(sharedip,ips) if(eq(ip->name, sharedip->sharing))\r
      {\r
       fprintf(f,"<br />%Lu", sharedip->upload);\r
+      if(!just_preview)\r
+      {\r
+       append_log(sharedip);\r
+      }\r
      }\r
      fputs("</span>\n",f);\r
    }\r
@@ -1845,15 +1884,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
    if(!just_preview)\r
    {\r
-    sprintf(str,"%s/%s.log",log_dir,ip->name);\r
-    iplog=fopen(str,"a");\r
-    if(iplog)\r
-    {\r
-     fprintf(iplog,"%ld\t%s\t%Lu\t%Lu\t%Lu\t%Lu\t%d\t%d\t%d\t%d\t%s",\r
-                    time(NULL), ip->name, ip->traffic, ip->direct, ip->proxy,\r
-                    ip->upload, ip->min, ip->max, ip->desired, ip->lmsid, d); /* d = date*/\r
-     fclose(iplog);\r
-    }\r
+    append_log(ip);\r
    }\r
   }\r
   fprintf(f,"</tbody><thead><tr>\n\\r
@@ -1970,6 +2001,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    /* write basic ERP data to log directory */\r
    if(!just_preview)\r
    {\r
+    FILE *iplog;\r
     sprintf(str,"%s/ERP.log",log_dir);\r
     iplog=fopen(str,"a");\r
     if(iplog)\r
@@ -1979,6 +2011,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
                    active_classes, total_traffic, i, limit_count, prio_count, d); /* d = date*/\r
      fclose(iplog);\r
     }\r
+    else\r
+    {\r
+     perror(str);\r
+    }\r
    }\r
   }\r
 \r
This page took 0.155221 seconds and 4 git commands to generate.