chiark / gitweb /
[PATCH] DEVPATH for netdev
[elogind.git] / udev_config.c
index 34ef82b..ba04003 100644 (file)
 #include <errno.h>
 #include <ctype.h>
 
+#include "libsysfs/sysfs/libsysfs.h"
 #include "udev.h"
+#include "udev_lib.h"
 #include "udev_version.h"
 #include "logging.h"
 #include "namedev.h"
-#include "libsysfs/libsysfs.h"
 
 /* global variables */
 char sysfs_path[SYSFS_PATH_MAX];
@@ -49,6 +50,8 @@ char default_mode_str[MODE_SIZE];
 char default_owner_str[OWNER_SIZE];
 char default_group_str[GROUP_SIZE];
 int udev_log;
+int udev_sleep;
+int udev_dev_d;
 
 
 static int string_is_true(char *str)
@@ -71,17 +74,25 @@ static void init_variables(void)
        strfieldcpy(udev_rules_filename, UDEV_RULES_FILE);
        strfieldcpy(udev_permissions_filename, UDEV_PERMISSION_FILE);
        udev_log = string_is_true(UDEV_LOG_DEFAULT);
+
+       udev_sleep = 1;
+       if (getenv("UDEV_NO_SLEEP") != NULL)
+               udev_sleep = 0;
+
+       udev_dev_d = 1;
+       if (getenv("UDEV_NO_DEVD") != NULL)
+               udev_dev_d = 0;
 }
 
 #define set_var(_name, _var)                           \
        if (strcasecmp(variable, _name) == 0) {         \
-               dbg_parse("%s = '%s'", _name, value);   \
-               strncpy(_var, value, sizeof(_var));     \
+               dbg_parse("%s='%s'", _name, value);     \
+               strfieldcpy(_var, value);\
        }
 
 #define set_bool(_name, _var)                          \
        if (strcasecmp(variable, _name) == 0) {         \
-               dbg_parse("%s = '%s'", _name, value);   \
+               dbg_parse("%s='%s'", _name, value);     \
                _var = string_is_true(value);           \
        }
 
@@ -126,12 +137,14 @@ static int parse_config_file(void)
        char *temp;
        char *variable;
        char *value;
-       FILE *fd;
-       int lineno = 0;
+       char *buf;
+       size_t bufsize;
+       size_t cur;
+       size_t count;
+       int lineno;
        int retval = 0;
-       
-       fd = fopen(udev_config_filename, "r");
-       if (fd != NULL) {
+
+       if (file_map(udev_config_filename, &buf, &bufsize) == 0) {
                dbg("reading '%s' as config file", udev_config_filename);
        } else {
                dbg("can't open '%s' as config file", udev_config_filename);
@@ -139,13 +152,20 @@ static int parse_config_file(void)
        }
 
        /* loop through the whole file */
+       lineno = 0;
+       cur = 0;
        while (1) {
-               /* get a line */
-               temp = fgets(line, sizeof(line), fd);
-               if (temp == NULL)
-                       goto exit;
+               count = buf_get_line(buf, bufsize, cur);
+
+               strncpy(line, buf + cur, count);
+               line[count] = '\0';
+               temp = line;
                lineno++;
 
+               cur += count+1;
+               if (cur > bufsize)
+                       break;
+
                dbg_parse("read '%s'", temp);
 
                /* eat the whitespace at the beginning of the line */
@@ -177,8 +197,8 @@ static int parse_config_file(void)
        }
        dbg_parse("%s:%d:%Zd: error parsing '%s'", udev_config_filename,
                  lineno, temp - line, temp);
-exit:
-       fclose(fd);
+
+       file_unmap(buf, bufsize);
        return retval;
 }