Revision: 6433
          http://ipcop.svn.sourceforge.net/ipcop/?rev=6433&view=rev
Author:   owes
Date:     2012-02-29 07:21:24 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
Instead of waiting x seconds in CGI, better to wait in SUID helper.

Modified Paths:
--------------
    ipcop/trunk/html/cgi-bin/proxy.cgi
    ipcop/trunk/src/misc-progs/restartsquid.c
    ipcop/trunk/updates/2.1.0/ROOTFILES.i486-2.1.0

Modified: ipcop/trunk/html/cgi-bin/proxy.cgi
===================================================================
--- ipcop/trunk/html/cgi-bin/proxy.cgi  2012-02-29 07:02:37 UTC (rev 6432)
+++ ipcop/trunk/html/cgi-bin/proxy.cgi  2012-02-29 07:21:24 UTC (rev 6433)
@@ -704,17 +704,12 @@
 
             system('/usr/local/bin/restartsquid --config');
 
-            system('/usr/local/bin/restartsquid');
-            if (($proxysettings{'ENABLED_GREEN_1'} eq 'on') || 
($proxysettings{'ENABLED_BLUE_1'} eq 'on') || ($proxysettings{'ENABLED_OVPN'} 
eq 'on')) {
-                # wait a bit so proxy can start and we can display proper 
running state
-                sleep(5);
-            }
+            system('/usr/local/bin/restartsquid --waitpid');
         }
     }
 
-    if ($proxysettings{'ACTION'} eq $Lang::tr{'clear cache'})
-    {
-        system('/usr/local/bin/restartsquid','-f');
+    if ($proxysettings{'ACTION'} eq $Lang::tr{'clear cache'}) {
+        system('/usr/local/bin/restartsquid --flush --waitpid');
     }
 
 } # end of ACTION

Modified: ipcop/trunk/src/misc-progs/restartsquid.c
===================================================================
--- ipcop/trunk/src/misc-progs/restartsquid.c   2012-02-29 07:02:37 UTC (rev 
6432)
+++ ipcop/trunk/src/misc-progs/restartsquid.c   2012-02-29 07:21:24 UTC (rev 
6433)
@@ -33,6 +33,7 @@
 #include <getopt.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -50,6 +51,7 @@
     printf("  -r, --repair          repair proxy cache\n");
     printf("  -t, --test            test first, do not start if not 
running\n");
 //    printf("      --config          re-generate squid.conf from proxy 
settings\n");
+    printf("  -w, --waitpid         wait for squid started\n");
     printf("  -v, --verbose         be verbose\n");
     printf("      --help            display this help and exit\n");
     exit(exit_code);
@@ -207,12 +209,14 @@
     int flag_test = 0;
     int flag_flush = 0;
     int flag_repair = 0;
+    int flag_waitpid = 0;
     int enabled_green = 0;
     int transparent_green = 0;
     int enabled_blue = 0;
     int transparent_blue = 0;
     int enabled_ovpn = 0;
     int transparent_ovpn = 0;
+    int enabled = 0;
     struct stat st;
     NODEKV *squid_kv = NULL;
     char buffer[STRING_SIZE];
@@ -226,6 +230,7 @@
         { "repair", no_argument, 0, 'r' },
         { "test", no_argument, 0, 't' },
         { "config", no_argument, 0, 'c' },
+        { "waitpid", no_argument, 0, 'w' },
         { "verbose", no_argument, 0, 'v' },
         { "help", no_argument, 0, 'h' },
         { 0, 0, 0, 0}
@@ -236,7 +241,7 @@
     if (!(initsetuid()))
         exit(1);
 
-    while ((c = getopt_long(argc, argv, "frtv", long_options, &option_index)) 
!= -1) {
+    while ((c = getopt_long(argc, argv, "frtvw", long_options, &option_index)) 
!= -1) {
         switch (c) {
         case 't':              /* test first */
             flag_test = 1;
@@ -250,6 +255,9 @@
         case 'v':              /* verbose */
             flag_verbose++;
             break;
+        case 'w':              /* wait for PID file */
+            flag_waitpid = 1;
+            break;
         case 'c':
             config();
         case 'h':
@@ -271,12 +279,15 @@
         /* Kill running squid */
         verbose_printf(1, "Flush squid iptables chain ... \n");
         safe_system("/sbin/iptables -t nat -F SQUID");
-        verbose_printf(1, "Shutdown squid ... \n");
+        verbose_printf(1, "Shutdown squid ");
         safe_system("/usr/sbin/squid -k shutdown >/dev/null 2>/dev/null");
         c = 0;
         while ((c++ < 15) && (access("/var/run/squid.pid", F_OK) != -1)) {
+            verbose_printf(1, ".");
+            _flushlbf();
             sleep(1);
         }
+        verbose_printf(1, "\n");
 
         if (access("/var/run/squid.pid", F_OK) != -1) {
             verbose_printf(1, "Really shutdown squid ... \n");
@@ -375,6 +386,7 @@
 
 
     if (enabled_green || enabled_blue || enabled_ovpn) {
+        enabled = 1;
         /* rebuild firewall rules, proxy port may be different now */
         verbose_printf(1, "Rebuild firewall rules ... \n");
         safe_system("/usr/local/bin/setfwrules --ipcop");
@@ -510,6 +522,27 @@
         }
         safe_system(buffer);
     }
+    
+    if (enabled && flag_waitpid) {
+        c = 0;
 
+        while ((access("/var/run/squid.pid", F_OK) == -1) && (c < 15)) {
+            if (!c) {
+                verbose_printf(1, "Waiting for squid to start ");
+            }
+            verbose_printf(1, ".");
+            _flushlbf();
+            c++;
+            sleep(1);
+        }
+        
+        if (c == 15) {
+            verbose_printf(1, " [TIMEOUT]\n");
+        }
+        else if (c) {
+            verbose_printf(1, "\n");
+        }
+    }
+
     return 0;
 }

Modified: ipcop/trunk/updates/2.1.0/ROOTFILES.i486-2.1.0
===================================================================
--- ipcop/trunk/updates/2.1.0/ROOTFILES.i486-2.1.0      2012-02-29 07:02:37 UTC 
(rev 6432)
+++ ipcop/trunk/updates/2.1.0/ROOTFILES.i486-2.1.0      2012-02-29 07:21:24 UTC 
(rev 6433)
@@ -18,6 +18,7 @@
 /usr/lib/ipcop/scheduler-lib.pl
 /usr/local/bin/blacklistupdate.pl
 /usr/local/bin/puzzleFwRules.pl
+/usr/local/bin/restartsquid
 /usr/local/bin/scheduler.pl
 /usr/share/locale/af_ZA/LC_MESSAGES/ipcop.mo
 /usr/share/locale/bg_BG/LC_MESSAGES/ipcop.mo

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to