Revision: 7846
          http://sourceforge.net/p/ipcop/svn/7846
Author:   owes
Date:     2015-02-01 18:35:46 +0000 (Sun, 01 Feb 2015)
Log Message:
-----------
Bundle kernel functions into new helper file.
Drop dependency on modules.pcimap and modules.usbmap

Modified Paths:
--------------
    ipcop/trunk/src/installer/Makefile
    ipcop/trunk/src/installer/arch_defs.h
    ipcop/trunk/src/installer/common.h
    ipcop/trunk/src/installer/hardware.c
    ipcop/trunk/src/installer/helper.c
    ipcop/trunk/src/installer/installer.c
    ipcop/trunk/src/installer/partition.c
    ipcop/trunk/src/installer/setup.c
    ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0

Added Paths:
-----------
    ipcop/trunk/src/installer/helper_kernel.c

Modified: ipcop/trunk/src/installer/Makefile
===================================================================
--- ipcop/trunk/src/installer/Makefile  2015-02-01 18:32:45 UTC (rev 7845)
+++ ipcop/trunk/src/installer/Makefile  2015-02-01 18:35:46 UTC (rev 7846)
@@ -6,10 +6,10 @@
 COPTS = -g -ggdb2 -Wall -DNAME='"$(NAME)"' -DSNAME='"$(SNAME)"' 
-DKVER='"$(KVER)"' -DVERSION='"$(VERSION)"'
 
 HEADERS = arch_defs.h common.h
-SRC_HELP = helper.c
-OBJS_INST = installer.o helper.o helper_backup.o helper_newt.o hardware.o 
language.o timezone.o keymap.o partition.o restore.o usbnames.o
+OBJS_INST = installer.o helper.o helper_backup.o helper_kernel.o helper_newt.o 
hardware.o language.o timezone.o \
+       keymap.o partition.o restore.o usbnames.o
 LIBS_INST = -lnewt -lslang -lpci -lusb-1.0 -lz
-OBJS_SETUP = setup.o helper.o helper_newt.o hardware.o host_domain.o keymap.o 
passwords.o timezone.o \
+OBJS_SETUP = setup.o helper.o helper_kernel.o helper_newt.o hardware.o 
host_domain.o keymap.o passwords.o timezone.o \
        networking.o net_dhcp.o net_isdn.o usbnames.o
 LIBS_SETUP = -lnewt -lslang -lpci -lusb-1.0 -lz
 
@@ -21,8 +21,8 @@
 setup: $(OBJS_SETUP) $(HEADERS)
        $(CC) $(LDFLAGS) $(CFLAGS) $(COPTS) $(OBJS_SETUP) -o $@ $(LIBS_SETUP)
 
-helper:$(SRC_HELP)
+helper: helper.c
        $(CC) $(CFLAGS) $(COPTS) -c  $< -o $@
 
-%.o : %.c
+%.o: %.c
        $(CC) $(CFLAGS) $(COPTS) -c  $< -o $@

Modified: ipcop/trunk/src/installer/arch_defs.h
===================================================================
--- ipcop/trunk/src/installer/arch_defs.h       2015-02-01 18:32:45 UTC (rev 
7845)
+++ ipcop/trunk/src/installer/arch_defs.h       2015-02-01 18:35:46 UTC (rev 
7846)
@@ -39,7 +39,7 @@
 #endif
 
 
-/* To fetch running kernel release (i.e. 2.6.27) */
+#include <stdint.h>
 #include <sys/utsname.h>
 
 
@@ -128,7 +128,23 @@
 
 #define PART_OPTIONS_USER_SIZE  0x8000
 
-/*
-    Some global variables used when installing
-*/
-extern struct utsname utsbuf;
+
+/* init uts & friends */
+int helper_kernel_init(void);
+/* retrieve kernel release, i.e. 3.4-3 */
+char *helper_kernel_release(void);
+
+/* find a kernel module for pci/usb bus depending on vendor and device id */
+char *find_modulename(char *bus, uint16_t vendor_id, uint16_t device_id);
+
+/* 
+ * Get kernel module, vendor and device ID for device using 
+ *     /sys/class/net/interface/device/driver/module
+ * and /sys/class/net/interface/device/{vendor,device}
+ */
+char *getkernelmodule(char *device);
+extern char module_buffer[STRING_SIZE];    /* to return the value out of the 
function */
+
+extern char vendorid_buffer[STRING_SIZE];  /* global variable */
+extern char deviceid_buffer[STRING_SIZE];  /* global variable */
+

Modified: ipcop/trunk/src/installer/common.h
===================================================================
--- ipcop/trunk/src/installer/common.h  2015-02-01 18:32:45 UTC (rev 7845)
+++ ipcop/trunk/src/installer/common.h  2015-02-01 18:35:46 UTC (rev 7846)
@@ -177,16 +177,6 @@
 char mac_buffer[STRING_SIZE]; /* to return the value out of the function */
 char *getmac(char *device);
 
-/* 
- * Get kernel module, vendor and device ID for device using 
- *     /sys/class/net/interface/device/driver/module
- * and /sys/class/net/interface/device/{vendor,device}
- */
-char module_buffer[STRING_SIZE];    /* to return the value out of the function 
*/
-char *getkernelmodule(char *device);
-char vendorid_buffer[STRING_SIZE];  /* global variable */
-char deviceid_buffer[STRING_SIZE];  /* global variable */
-
 /* Some useful defines, tests etc. */
 #define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 #define NUMBERS "0123456789"

Modified: ipcop/trunk/src/installer/hardware.c
===================================================================
--- ipcop/trunk/src/installer/hardware.c        2015-02-01 18:32:45 UTC (rev 
7845)
+++ ipcop/trunk/src/installer/hardware.c        2015-02-01 18:35:46 UTC (rev 
7846)
@@ -16,7 +16,7 @@
  * You should have received a copy of the GNU General Public License
  * along with IPCop.  If not, see <http://www.gnu.org/licenses/>.
  *
- * (c) 2007-2013, the IPCop team
+ * (c) 2007-2015, the IPCop team
  *
  * $Id$
  * 
@@ -372,7 +372,6 @@
     newtComponent text;
     newtComponent scale;
     char line[STRING_SIZE];
-    char modulemap[STRING_SIZE];
     int numBusses;
     int firstscan;
     supported_media_t type;
@@ -423,7 +422,7 @@
     numBusses = 0;
 
     /*
-     *  PCI scanning by using libpci, pci.ids.gz and modules.pcimap
+     *  PCI scanning by using libpci, pci.ids.gz and modules.alias
      *
      *
      */
@@ -491,21 +490,9 @@
         }
         else {
             char *module = NULL;
-            FILE *p;
 
-            snprintf(command, STRING_SIZE,
-                     "/bin/grep \"%04x 0x0000%04x\" 
/lib/modules/%s/modules.pcimap",
-                     pcidev->vendor_id, pcidev->device_id, utsbuf.release);
+            module = find_modulename("pci", pcidev->vendor_id, 
pcidev->device_id);
 
-            p = popen(command, "r");
-            if (fgets(modulemap, STRING_SIZE, p)) {
-                if ((module = strchr(modulemap, ' ')) != NULL) {
-                    *module = 0;
-                    module = modulemap;
-                }
-            }
-            pclose(p);
-
             if (module != NULL) {
                 if ((type == network) && (pcidev->device_class == 
PCI_CLASS_BRIDGE_OTHER) && (pcidev->vendor_id == 0x10de) && strcmp(module, 
"forcedeth")) {
                     /* Special case, nVidia PCI bridge_other not using 
forcedeth driver */
@@ -586,7 +573,7 @@
     sleep(1);
 
     /*
-     *  USB scanning by using libusb, pci.ids.gz and modules.usbmap
+     *  USB scanning by using libusb, pci.ids.gz and modules.alias
      *
      *
      */
@@ -653,21 +640,9 @@
         }
         else {
             char *module = NULL;
-            FILE *p;
 
-            snprintf(command, STRING_SIZE,
-                     "/bin/grep \"0x%04x   0x%04x\" 
/lib/modules/%s/modules.usbmap",
-                     descriptor.idVendor, descriptor.idProduct, 
utsbuf.release);
+            module = find_modulename("usb", descriptor.idVendor, 
descriptor.idProduct);
 
-            p = popen(command, "r");
-            if (fgets(modulemap, STRING_SIZE, p)) {
-                if ((module = strchr(modulemap, ' ')) != NULL) {
-                    *module = 0;
-                    module = modulemap;
-                }
-            }
-            pclose(p);
-
             if (module != NULL) {
                 snprintf(logline, STRING_SIZE, "  Add  %02x %04x:%04x, %s\n",
                         descriptor.bDeviceClass, descriptor.idVendor, 
descriptor.idProduct, description);

Modified: ipcop/trunk/src/installer/helper.c
===================================================================
--- ipcop/trunk/src/installer/helper.c  2015-02-01 18:32:45 UTC (rev 7845)
+++ ipcop/trunk/src/installer/helper.c  2015-02-01 18:35:46 UTC (rev 7846)
@@ -14,10 +14,9 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with IPCop; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ * along with IPCop.  If not, see <http://www.gnu.org/licenses/>.
  *
- * (c) 2007-2008, the IPCop team
+ * (c) 2007-2015, the IPCop team
  *
  * $Id$
  * 
@@ -49,6 +48,10 @@
 
 NODEKV *eth_kv = NULL;
 
+/* */
+struct utsname uts;
+
+
 /* Compare verbose level against lvl, printf if greater or equal */
 void verbose_printf(int lvl, char *fmt, ...)
 {
@@ -649,62 +652,6 @@
 }
 
 
-/* 
- * Get kernel module, vendor and device ID for device using 
- *     /sys/class/net/interface/device/driver/module
- * and /sys/class/net/interface/device/{vendor,device}
- *
- * Return module_buffer.
- * vendorid_buffer and deviceid_buffer are global variables.
- */
-char *getkernelmodule(char *device)
-{
-    char command[STRING_SIZE];
-    char line[STRING_SIZE];
-    FILE *f;
-    char *ptr;
-
-    strcpy(module_buffer, "");
-
-    snprintf(command, STRING_SIZE, "ls -l 
/sys/class/net/%s/device/driver/module", device);
-
-    f = popen(command, "r");
-    if (fgets(line, STRING_SIZE, f) != NULL) {
-        stripnl(line);
-        if ((ptr = strrchr(line, '/')) != NULL) {
-            /* ptr now points to /e100 */
-            ptr++;
-            if (*ptr) {
-                /* temporarily store driver */ 
-                strcpy(module_buffer, ptr);
-            }
-        }
-    }
-
-    pclose(f);
-
-    strcpy(vendorid_buffer, "");
-    snprintf(command, STRING_SIZE, "/sys/class/net/%s/device/vendor", device);
-    if ((f = fopen(command, "r")) != NULL) {
-        if (fgets(line, STRING_SIZE, f) != NULL) {
-            stripnl(line);
-            strcpy(vendorid_buffer, line+2);
-        }
-        fclose(f);
-    }
-
-    strcpy(deviceid_buffer, "");
-    snprintf(command, STRING_SIZE, "/sys/class/net/%s/device/device", device);
-    if ((f = fopen(command, "r")) != NULL) {
-        if (fgets(line, STRING_SIZE, f) != NULL) {
-            stripnl(line);
-            strcpy(deviceid_buffer, line+2);
-        }
-        fclose(f);
-    }
-    return module_buffer;
-}
-
 /*
     Test for valid IPv4
     Returns TRUE or FALSE

Added: ipcop/trunk/src/installer/helper_kernel.c
===================================================================
--- ipcop/trunk/src/installer/helper_kernel.c                           (rev 0)
+++ ipcop/trunk/src/installer/helper_kernel.c   2015-02-01 18:35:46 UTC (rev 
7846)
@@ -0,0 +1,169 @@
+/* 
+ * helper_kernel.c: kernel related helper functions
+ *
+ * This file is part of the IPCop Firewall.
+ *
+ * IPCop is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * IPCop is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with IPCop.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * (c) 2015, the IPCop team
+ *
+ * $Id$
+ * 
+ */
+
+ 
+#include <malloc.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include "common.h"
+#include "arch_defs.h"
+
+
+/* Used globally */
+char module_buffer[STRING_SIZE];    /* to return the value out of the function 
*/
+char vendorid_buffer[STRING_SIZE];  /* global variable */
+char deviceid_buffer[STRING_SIZE];  /* global variable */
+
+
+static int kernel_inited = -1;
+static struct utsname uts;
+static char module_find[STRING_SIZE];   /* to return the value out of the 
function */
+
+
+int helper_kernel_init(void)
+{
+    if (kernel_inited >= 0)
+        return kernel_inited;
+
+    memset(&uts, 0, sizeof(struct utsname));
+    if (uname(&uts) < 0) {
+        fprintf(fstderr, "FATAL ERROR: uname\n");
+        exit(1);
+    }
+
+    char *name = alloca(64 + strlen(uts.release));
+    if (name == NULL) {
+        fprintf(fstderr, "FATAL ERROR: alloca uts release\n");
+        exit(1);
+    }
+    sprintf(name, "/lib/modules/%s", uts.release);
+    fprintf(flog, "Kernelpath %s\n", name);
+
+    kernel_inited = 1;
+    return 1;
+}
+
+
+char *helper_kernel_release(void)
+{
+    if (kernel_inited != 1) {
+        return NULL;
+    }
+    return(uts.release);
+}
+
+
+/* find a kernel module for pci/usb bus depending on vendor and device id */
+char *find_modulename(char *bus, uint16_t vendor_id, uint16_t device_id)
+{
+    FILE *p;
+    char command[STRING_SIZE];
+    char modulemap[STRING_SIZE];
+
+    if (kernel_inited != 1) {
+        return NULL;
+    }
+
+    if (!strcmp(bus, "usb")) {
+        /* USB syntax slightly differs */
+        snprintf(command, STRING_SIZE,
+                 "/bin/grep \"%s:v%04Xp%04X\" /lib/modules/%s/modules.alias",
+                 bus, vendor_id, device_id, uts.release);
+    }
+    else {
+        snprintf(command, STRING_SIZE,
+                 "/bin/grep \"%s:v0000%04Xd0000%04X\" 
/lib/modules/%s/modules.alias",
+                 bus, vendor_id, device_id, uts.release);
+    }
+
+    p = popen(command, "r");
+    if (fgets(modulemap, STRING_SIZE, p)) {
+        char *module;
+        if ((module = strrchr(modulemap, ' ')) != NULL) {
+            strcpy(module_find, module+1);
+            stripnl(module_find);
+            return module_find;
+        }
+    }
+    pclose(p);
+    return NULL;
+}
+
+
+/* 
+ * Get kernel module, vendor and device ID for device using 
+ *     /sys/class/net/interface/device/driver/module
+ * and /sys/class/net/interface/device/{vendor,device}
+ *
+ * Return module_buffer.
+ * vendorid_buffer and deviceid_buffer are global variables.
+ */
+char *getkernelmodule(char *device)
+{
+    char command[STRING_SIZE];
+    char line[STRING_SIZE];
+    FILE *f;
+    char *ptr;
+
+    strcpy(module_buffer, "");
+
+    snprintf(command, STRING_SIZE, "ls -l 
/sys/class/net/%s/device/driver/module", device);
+
+    f = popen(command, "r");
+    if (fgets(line, STRING_SIZE, f) != NULL) {
+        stripnl(line);
+        if ((ptr = strrchr(line, '/')) != NULL) {
+            /* ptr now points to /e100 */
+            ptr++;
+            if (*ptr) {
+                /* temporarily store driver */ 
+                strcpy(module_buffer, ptr);
+            }
+        }
+    }
+
+    pclose(f);
+
+    strcpy(vendorid_buffer, "");
+    snprintf(command, STRING_SIZE, "/sys/class/net/%s/device/vendor", device);
+    if ((f = fopen(command, "r")) != NULL) {
+        if (fgets(line, STRING_SIZE, f) != NULL) {
+            stripnl(line);
+            strcpy(vendorid_buffer, line+2);
+        }
+        fclose(f);
+    }
+
+    strcpy(deviceid_buffer, "");
+    snprintf(command, STRING_SIZE, "/sys/class/net/%s/device/device", device);
+    if ((f = fopen(command, "r")) != NULL) {
+        if (fgets(line, STRING_SIZE, f) != NULL) {
+            stripnl(line);
+            strcpy(deviceid_buffer, line+2);
+        }
+        fclose(f);
+    }
+    return module_buffer;
+}


Property changes on: ipcop/trunk/src/installer/helper_kernel.c
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Modified: ipcop/trunk/src/installer/installer.c
===================================================================
--- ipcop/trunk/src/installer/installer.c       2015-02-01 18:32:45 UTC (rev 
7845)
+++ ipcop/trunk/src/installer/installer.c       2015-02-01 18:35:46 UTC (rev 
7846)
@@ -6,7 +6,7 @@
  *
  * Written by Alan Hourihane <al...@fairlite.demon.co.uk>
  *
- * (c) 2007-2013, the IPCop team
+ * (c) 2007-2015, the IPCop team
  *
  * This is the first stage installer.
  * - select language.
@@ -58,7 +58,6 @@
 supported_media_t medium_console = console;
 char network_source[STRING_SIZE];
 unsigned int memtotal = 0;                  /* Total memory in MB */
-struct utsname utsbuf;
 
 unsigned int serial_console = 0;
 unsigned int serial_bitrate = 9600;
@@ -819,8 +818,7 @@
     fprintf(flog, "Logging from installer.\n");
     fprintf(fstderr, "Error messages and more logging from installer.\n");
 
-    memset(&utsbuf, 0, sizeof(struct utsname));
-    uname(&utsbuf);
+    helper_kernel_init();
 
     /* Want our tester have a better coverage of the code path */
     read_codepath();   /* actually only force dhcp or manual path on pxe boot 
*/

Modified: ipcop/trunk/src/installer/partition.c
===================================================================
--- ipcop/trunk/src/installer/partition.c       2015-02-01 18:32:45 UTC (rev 
7845)
+++ ipcop/trunk/src/installer/partition.c       2015-02-01 18:35:46 UTC (rev 
7846)
@@ -609,7 +609,7 @@
     statuswindow(72, 5, ipcop_gettext("TR_TITLE_DISK"), 
ipcop_gettext("TR_BUILDING_INITRD"));
 
     // run depmod to have complete modules.* files on target system
-    snprintf(bigstring, STRING_SIZE, "chroot /harddisk /sbin/depmod -a %s", 
utsbuf.release);
+    snprintf(bigstring, STRING_SIZE, "chroot /harddisk /sbin/depmod -a %s", 
helper_kernel_release());
     if (mysystem(bigstring)) {
         errorbox(ipcop_gettext("TR_UNABLE_TO_BUILD_INITRD"));
         newtPopWindow();
@@ -651,7 +651,7 @@
     fclose(handle);
 
     strcat(bigstring, " --with-kernel=");
-    strcat(bigstring, utsbuf.release);
+    strcat(bigstring, helper_kernel_release());
 
     retcode = mysystem(bigstring);
     newtPopWindow();
@@ -680,7 +680,7 @@
     snprintf(device2, STRING_SIZE, "/dev/%s", dev2);
 
 #if defined (__i386__)
-    snprintf(bigstring, STRING_SIZE, "/bin/sed -i -e 's+KVER+%s+g' ", 
utsbuf.release);
+    snprintf(bigstring, STRING_SIZE, "/bin/sed -i -e 's+KVER+%s+g' ", 
helper_kernel_release());
 
     if (raid) {
         /* replace the ROOT_DEV with md0 */
@@ -786,7 +786,7 @@
         snprintf(command, STRING_SIZE, "chroot /harddisk /usr/sbin/mkofboot 
--force -b %s2", device);
         mysystem(command);
 
-        snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+KVER+%s+g' 
/harddisk/etc/yaboot.conf", utsbuf.release);
+        snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+KVER+%s+g' 
/harddisk/etc/yaboot.conf", helper_kernel_release());
         mysystem(command);
 
         /* replace the ROOT_DEV with the real device, partition 2 */
@@ -819,7 +819,7 @@
 #if defined (__sparc__) || defined (__sparc64__)
     fprintf(flog, "Installing silo\n");
 
-    snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+KVER+%s+g' 
/harddisk/etc/silo.conf", utsbuf.release);
+    snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+KVER+%s+g' 
/harddisk/etc/silo.conf", helper_kernel_release());
     mysystem(command);
 
     if (raid) {

Modified: ipcop/trunk/src/installer/setup.c
===================================================================
--- ipcop/trunk/src/installer/setup.c   2015-02-01 18:32:45 UTC (rev 7845)
+++ ipcop/trunk/src/installer/setup.c   2015-02-01 18:35:46 UTC (rev 7846)
@@ -16,7 +16,7 @@
  * You should have received a copy of the GNU General Public License
  * along with IPCop.  If not, see <http://www.gnu.org/licenses/>.
  *
- * (c) 2007-2013, the IPCop team
+ * (c) 2007-2015, the IPCop team
  *
  * Commandline options:
  *
@@ -41,7 +41,6 @@
 installer_setup_t flag_is_state = setup;
 supported_media_t medium_console = console;
 char selected_locale[STRING_SIZE];
-struct utsname utsbuf;
 
 
 char *ipcop_gettext(char *txt)
@@ -90,8 +89,7 @@
         fstderr = freopen("/dev/tty6", "w+", stderr);
     }
 
-    memset(&utsbuf, 0, sizeof(struct utsname));
-    uname(&utsbuf);
+    helper_kernel_init();
 
     newtInit();
     newtCls();

Modified: ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0
===================================================================
--- ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0      2015-02-01 18:32:45 UTC 
(rev 7845)
+++ ipcop/trunk/updates/2.2.0/ROOTFILES.i486-2.2.0      2015-02-01 18:35:46 UTC 
(rev 7846)
@@ -1,6 +1,7 @@
 ## please place IPCop files first, then packages sorted by alphabetical order
 ##
 /home/httpd/cgi-bin/updates.cgi
+/usr/local/sbin/setup
 /usr/share/locale/pt_BR/LC_MESSAGES/ipcop.mo
 ##
 ## dhcpcd-6.7.1

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


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to