1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 00:20:08 +00:00

makedevs: Fix issue when rootdir of / is given

Treating rootdir "/" as "" leads an error in parse_devtable(). Preserve
it as it is given and use a separate variable for path name prepending.
Another minor fix is to add a return statement at the end of
convert2guid() to avoid an error with -Werror=return-type.

(From OE-Core rev: 4d52e6276c687a8950bde21850072ddf14893fb2)

Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Jaeyoon Jung
2024-08-07 03:44:37 +09:00
committed by Richard Purdie
parent 0043986334
commit 454fcf36c7
@@ -36,6 +36,7 @@ static const char *const app_name = "makedevs";
static const char *const memory_exhausted = "memory exhausted"; static const char *const memory_exhausted = "memory exhausted";
static char default_rootdir[]="."; static char default_rootdir[]=".";
static char *rootdir = default_rootdir; static char *rootdir = default_rootdir;
static char *rootdir_prepend = default_rootdir;
static int trace = 0; static int trace = 0;
struct name_id { struct name_id {
@@ -217,6 +218,9 @@ static unsigned long convert2guid(char *id_buf, struct name_id *search_list)
} }
error_msg_and_die("No entry for %s in search list", id_buf); error_msg_and_die("No entry for %s in search list", id_buf);
} }
// Unreachable, but avoid an error with -Werror=return-type
return 0;
} }
static void free_list(struct name_id *list) static void free_list(struct name_id *list)
@@ -379,8 +383,8 @@ static int interpret_table_entry(char *line)
error_msg_and_die("Device table entries require absolute paths"); error_msg_and_die("Device table entries require absolute paths");
} }
name = xstrdup(path + 1); name = xstrdup(path + 1);
/* prefix path with rootdir */ /* prefix path with rootdir_prepend */
sprintf(path, "%s/%s", rootdir, name); sprintf(path, "%s/%s", rootdir_prepend, name);
/* XXX Why is name passed into all of the add_new_*() routines? */ /* XXX Why is name passed into all of the add_new_*() routines? */
switch (type) { switch (type) {
@@ -406,11 +410,11 @@ static int interpret_table_entry(char *line)
for (i = start; i < start + count; i++) { for (i = start; i < start + count; i++) {
sprintf(buf, "%s%d", name, i); sprintf(buf, "%s%d", name, i);
sprintf(path, "%s/%s%d", rootdir, name, i); sprintf(path, "%s/%s%d", rootdir_prepend, name, i);
/* FIXME: MKDEV uses illicit insider knowledge of kernel /* FIXME: MKDEV uses illicit insider knowledge of kernel
* major/minor representation... */ * major/minor representation... */
rdev = MKDEV(major, minor + (i - start) * increment); rdev = MKDEV(major, minor + (i - start) * increment);
sprintf(path, "%s/%s\0", rootdir, buf); sprintf(path, "%s/%s\0", rootdir_prepend, buf);
add_new_device(buf, path, uid, gid, mode, rdev); add_new_device(buf, path, uid, gid, mode, rdev);
} }
} else { } else {
@@ -541,12 +545,11 @@ int main(int argc, char **argv)
} else { } else {
closedir(dir); closedir(dir);
} }
/* If "/" is specified, use "" because rootdir is always prepended to a rootdir = xstrdup(optarg);
* string that starts with "/" */ if (0 == strcmp(rootdir, "/"))
if (0 == strcmp(optarg, "/")) rootdir_prepend = xstrdup("");
rootdir = xstrdup("");
else else
rootdir = xstrdup(optarg); rootdir_prepend = xstrdup(rootdir);
break; break;
case 't': case 't':