[Commits] r632 - trunk/daemon/src

new-commit at lists.openvcp.org new-commit at lists.openvcp.org
Sun Oct 5 16:09:25 UTC 2008


Author: ftx
Date: 2008-10-05 16:09:24 +0000 (Sun, 05 Oct 2008)
New Revision: 632

Modified:
   trunk/daemon/src/bandwidth.c
   trunk/daemon/src/bandwidth.h
   trunk/daemon/src/misc.c
   trunk/daemon/src/traffic.c
Log:
fixe for segfault in case of missing /proc/modules
Closes: #227 


Modified: trunk/daemon/src/bandwidth.c
===================================================================
--- trunk/daemon/src/bandwidth.c	2008-09-15 16:17:54 UTC (rev 631)
+++ trunk/daemon/src/bandwidth.c	2008-10-05 16:09:24 UTC (rev 632)
@@ -17,13 +17,17 @@
  */
 
 
+#include <string.h>
+
 #include "main.h"
 #include "misc.h"
 #include "config.h"
 #include "request.h"
 #include "error.h"
 
+#include "fs.h"
 
+
 struct ovcp_response_st *set_bandwidth(struct ovcp_request_st *request)
 {
 	struct ovcp_response_st *response;
@@ -320,4 +324,18 @@
 
 
 
-
+int ifb_kernel_support()
+{
+	char *devsfile = file_read("/proc/net/dev");
+	int ret = 0;
+	
+	if(devsfile != NULL)
+	{
+		if(strstr(devsfile, "ifb") != NULL)
+			ret = 1;
+	}
+	
+	free(devsfile);
+	
+	return ret;
+}

Modified: trunk/daemon/src/bandwidth.h
===================================================================
--- trunk/daemon/src/bandwidth.h	2008-09-15 16:17:54 UTC (rev 631)
+++ trunk/daemon/src/bandwidth.h	2008-10-05 16:09:24 UTC (rev 632)
@@ -29,4 +29,6 @@
 	struct ovcp_response_st *get_bandwidth(struct ovcp_request_st *request);
 	struct ovcp_response_st *del_bandwidth(struct ovcp_request_st *request);
 	
+	int ifb_kernel_support();
+	
 #endif

Modified: trunk/daemon/src/misc.c
===================================================================
--- trunk/daemon/src/misc.c	2008-09-15 16:17:54 UTC (rev 631)
+++ trunk/daemon/src/misc.c	2008-10-05 16:09:24 UTC (rev 632)
@@ -746,7 +746,9 @@
         int found = 0;
 
         modfile = fopen("/proc/modules", "r");
-
+	if(modfile == NULL)
+		return 0;
+		
         while(!feof(modfile))
         {
                 fscanf(modfile, "%50s", &name);

Modified: trunk/daemon/src/traffic.c
===================================================================
--- trunk/daemon/src/traffic.c	2008-09-15 16:17:54 UTC (rev 631)
+++ trunk/daemon/src/traffic.c	2008-10-05 16:09:24 UTC (rev 632)
@@ -529,18 +529,16 @@
 	
 	sqlite3_exec(openvcp_db, "CREATE TABLE vserver_trafficlimit ('id' INTEGER PRIMARY KEY AUTOINCREMENT, 'name', 'total', 'notify', 'type', 'notified', UNIQUE(name, type))", NULL, 0, NULL);
 
-	system("modprobe ifb 2>/dev/null");	
+	execb_cmd("modprobe", "modprobe", "ifb", NULL);	
 	
-	system("modprobe ip_tables 2>/dev/null");
-	if(kernelmodule_loaded("ip_tables"))
-	{
-		ovcp_create_chains();
-		ovcp_create_tables(openvcp_db);
-	}
-	else  ovcp_log(OVCP_WARNING, "ip_tables Kernel Module not found");
+	execb_cmd("modprobe", "modprobe", "ip_tables", NULL);
+
+	ovcp_create_chains();
+	ovcp_create_tables(openvcp_db);
+
+	execb_cmd("modprobe", "modprobe", "nf_conntrack_ftp", NULL);
+
 	
-	system("modprobe nf_conntrack_ftp 2>/dev/null");
-	
 	ifaces = split_string(global_settings.ifaces, ' ', &iface_count);
 	
 	loggerdata = (struct _packetlogger **) malloc(sizeof(struct _packetlogger **) * iface_count);
@@ -603,7 +601,7 @@
 			i++;
 		}		
 		
-		if(kernelmodule_loaded("ifb"))
+		if(ifb_kernel_support())
 			ovcp_setup_trafficthrottling(openvcp_db);
 		else  ovcp_log(OVCP_WARNING, "ifb Kernel Module not found");
 		



More information about the Commits mailing list