chiark / gitweb /
[PATCH] Add initial SELinux support for udev
[elogind.git] / namedev.c
index bc407dd103a614ec90b3c3bfb77115df706a20db..7c07e3b10423f9185cea3f1af40c23f9800d23f8 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -228,7 +228,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
        pos = string;
 
        while (1) {
-               pos = strchr(pos, '%');
+               pos = strchr(string, '%');
                if (pos != NULL) {
                        pos[0] = '\0';
                        tail = pos+1;
@@ -247,19 +247,19 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
                case 'b':
                        if (strlen(udev->bus_id) == 0)
                                break;
-                       strnfieldcat(pos, udev->bus_id, maxsize);
+                       strnfieldcat(string, udev->bus_id, maxsize);
                        dbg("substitute bus_id '%s'", udev->bus_id);
                        break;
                case 'k':
                        if (strlen(udev->kernel_name) == 0)
                                break;
-                       strnfieldcat(pos, udev->kernel_name, maxsize);
+                       strnfieldcat(string, udev->kernel_name, maxsize);
                        dbg("substitute kernel name '%s'", udev->kernel_name);
                        break;
                case 'n':
                        if (strlen(udev->kernel_number) == 0)
                                break;
-                       strnfieldcat(pos, udev->kernel_number, maxsize);
+                       strnfieldcat(string, udev->kernel_number, maxsize);
                        dbg("substitute kernel number '%s'", udev->kernel_number);
                                break;
                case 'm':
@@ -289,11 +289,11 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
                                        }
                                }
                                if (pos3) {
-                                       strnfieldcat(pos, pos3, maxsize);
+                                       strnfieldcat(string, pos3, maxsize);
                                        dbg("substitute part of result string '%s'", pos3);
                                }
                        } else {
-                               strnfieldcat(pos, udev->program_result, maxsize);
+                               strnfieldcat(string, udev->program_result, maxsize);
                                dbg("substitute result string '%s'", udev->program_result);
                        }
                        break;
@@ -304,20 +304,20 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
                                        dbg("sysfa attribute '%s' not found", attr);
                                        break;
                                }
-                               strnfieldcpy(pos, tmpattr->value, maxsize);
+                               strnfieldcat(string, tmpattr->value, maxsize);
                                dbg("substitute sysfs value '%s'", tmpattr->value);
                        } else {
                                dbg("missing attribute");
                        }
                        break;
                case '%':
-                       strnfieldcat(pos, "%", maxsize);
+                       strnfieldcat(string, "%", maxsize);
                        break;
                default:
                        dbg("unknown substitution type '%%%c'", c);
                        break;
                }
-               strnfieldcat(pos, tail, maxsize);
+               strnfieldcat(string, tail, maxsize);
        }
 }
 
@@ -421,7 +421,13 @@ static int execute_program(char *path, char *value, int len)
        case 0:
                /* child */
                close(STDOUT_FILENO);
-               dup(fds[1]);    /* dup write side of pipe to STDOUT */
+
+               /* dup write side of pipe to STDOUT */
+               dup(fds[1]);
+
+               /* copy off our path to use incase we have too many args */
+               strnfieldcpy(buffer, path, sizeof(buffer));
+
                if (strchr(path, ' ')) {
                        /* exec with arguments */
                        pos = path;
@@ -431,14 +437,16 @@ static int execute_program(char *path, char *value, int len)
                                        break;
                        }
                        if (args[i]) {
-                               dbg("too many args - %d", i);
-                               args[i] = NULL;
+                               dbg("too many args - %d, using subshell instead '%s'", i, buffer);
+                               retval = execl("/bin/sh", "sh", "-c", buffer, NULL);
+                       } else {
+                               dbg("execute program '%s'", path);
+                               retval = execv(args[0], args);
                        }
-                       retval = execv(args[0], args);
                } else {
                        retval = execv(path, main_argv);
                }
-               dbg("child execve failed");
+               info(FIELD_PROGRAM " execution of '%s' failed", path);
                exit(1);
        case -1:
                dbg("fork failed");