X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=udev_utils.c;h=3c5344a8f987782e23d432984f7ec2ac71ff5aa3;hb=b9a8c4821a98df33ba2cc5b18b15d7175709c376;hp=bdf0233e3ae1c5828f6cedc4acfea3463a227a58;hpb=9af5bb2f8fdbf54c064ddbd319d61092f28a4132;p=elogind.git diff --git a/udev_utils.c b/udev_utils.c index bdf0233e3..3c5344a8f 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -36,8 +37,7 @@ #include "list.h" -void udev_set_values(struct udevice *udev, const char* devpath, - const char *subsystem, const char* action) +void udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem) { memset(udev, 0x00, sizeof(struct udevice)); @@ -45,8 +45,6 @@ void udev_set_values(struct udevice *udev, const char* devpath, strfieldcpy(udev->devpath, devpath); if (subsystem) strfieldcpy(udev->subsystem, subsystem); - if (action) - strfieldcpy(udev->action, action); if (strcmp(udev->subsystem, "block") == 0) udev->type = 'b'; @@ -58,6 +56,10 @@ void udev_set_values(struct udevice *udev, const char* devpath, udev->type = 'n'; else if (strncmp(udev->devpath, "/class/", 7) == 0) udev->type = 'c'; + + udev->mode = 0660; + strcpy(udev->owner, "root"); + strcpy(udev->group, "root"); } int kernel_release_satisfactory(int version, int patchlevel, int sublevel) @@ -110,6 +112,41 @@ int create_path(const char *path) return mkdir(p, 0755); } +int parse_get_pair(char **orig_string, char **left, char **right) +{ + char *temp; + char *string = *orig_string; + + if (!string) + return -ENODEV; + + /* eat any whitespace */ + while (isspace(*string) || *string == ',') + ++string; + + /* split based on '=' */ + temp = strsep(&string, "="); + *left = temp; + if (!string) + return -ENODEV; + + /* take the right side and strip off the '"' */ + while (isspace(*string)) + ++string; + if (*string == '"') + ++string; + else + return -ENODEV; + + temp = strsep(&string, "\""); + if (!string || *temp == '\0') + return -ENODEV; + *right = temp; + *orig_string = string; + + return 0; +} + int file_map(const char *filename, char **buf, size_t *bufsize) { struct stat stats; @@ -142,11 +179,21 @@ void file_unmap(char *buf, size_t bufsize) munmap(buf, bufsize); } -size_t buf_get_line(char *buf, size_t buflen, size_t cur) +/* return number of chars until the next newline, skip escaped newline */ +size_t buf_get_line(const char *buf, size_t buflen, size_t cur) { - size_t count = 0; + int escape = 0; + size_t count; + + for (count = cur; count < buflen; count++) { + if (!escape && buf[count] == '\n') + break; - for (count = cur; count < buflen && buf[count] != '\n'; count++); + if (buf[count] == '\\') + escape = 1; + else + escape = 0; + } return count - cur; }