]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move the default vendor string to a global variable.
authorRoy Marples <roy@marples.name>
Tue, 9 Oct 2012 13:20:50 +0000 (13:20 +0000)
committerRoy Marples <roy@marples.name>
Tue, 9 Oct 2012 13:20:50 +0000 (13:20 +0000)
When an interface starts, it assigns this by default instead of
generating it each time.

dhcpcd.c
dhcpcd.h
if-options.c

index bd1d93536314ec71ff86cd1c8e2c5f5e95fe65e0..6933b9faabace86d531c33d081646356682e530c 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -33,6 +33,7 @@ const char copyright[] = "Copyright (c) 2006-2012 Roy Marples";
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/uio.h>
+#include <sys/utsname.h>
 
 #include <arpa/inet.h>
 #include <net/route.h>
@@ -82,6 +83,7 @@ const char copyright[] = "Copyright (c) 2006-2012 Roy Marples";
 #define RELEASE_DELAY_S                0
 #define RELEASE_DELAY_NS       10000000
 
+char vendor[VENDORCLASSID_MAX_LEN];
 int pidfd = -1;
 struct interface *ifaces = NULL;
 int ifac = 0;
@@ -1773,6 +1775,8 @@ main(int argc, char **argv)
        size_t len;
        pid_t pid;
        struct timespec ts;
+       struct utsname utn;
+       const char *platform;
 
        closefrom(3);
        openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON);
@@ -1789,6 +1793,16 @@ main(int argc, char **argv)
                }
        }
 
+       platform = hardware_platform();
+       if (uname(&utn) == 0)
+               snprintf(vendor, VENDORCLASSID_MAX_LEN,
+                   "%s-%s:%s-%s:%s%s%s", PACKAGE, VERSION,
+                   utn.sysname, utn.release, utn.machine,
+                   platform ? ":" : "", platform ? platform : "");
+       else
+               snprintf(vendor, VENDORCLASSID_MAX_LEN,
+                   "%s-%s", PACKAGE, VERSION);
+
        i = 0;
        while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1)
        {
index 008eb475c9fe45c7aaf6975741ab67bf4eb920a0..a04b7a8186332c90a78a19c75f18697cef045da2 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -119,6 +119,7 @@ struct interface {
        struct interface *next;
 };
 
+extern char vendor[VENDORCLASSID_MAX_LEN];
 extern int pidfd;
 extern int ifac;
 extern char **ifav;
index 36e996589806dfd592629d1414631aa3d3dd3984..5b517979ae508423b083ca1ddb561d4077749cde 100644 (file)
@@ -26,7 +26,6 @@
  */
 
 #include <sys/types.h>
-#include <sys/utsname.h>
 
 #include <arpa/inet.h>
 
@@ -804,9 +803,8 @@ read_config(const char *file,
 {
        struct if_options *ifo;
        FILE *f;
-       char *line, *option, *p, *platform;
+       char *line, *option, *p;
        int skip = 0, have_profile = 0;
-       struct utsname utn;
 
        /* Seed our default options */
        ifo = xzalloc(sizeof(*ifo));
@@ -824,16 +822,8 @@ read_config(const char *file,
            strcmp(ifo->hostname, "localhost") == 0)
                ifo->hostname[0] = '\0';
 
-       platform = hardware_platform();
-       if (uname(&utn) == 0)
-               ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,
-                   VENDORCLASSID_MAX_LEN,
-                   "%s-%s:%s-%s:%s%s%s", PACKAGE, VERSION,
-                   utn.sysname, utn.release, utn.machine,
-                   platform ? ":" : "", platform ? platform : "");
-       else
-               ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,
-                   VENDORCLASSID_MAX_LEN, "%s-%s", PACKAGE, VERSION);
+       ifo->vendorclassid[0] = strlen(vendor);
+       memcpy(ifo->vendorclassid + 1, vendor, ifo->vendorclassid[0]);
 
        /* Parse our options file */
        f = fopen(file ? file : CONFIG, "r");