Skip to contentSkip to conversation

qdev: Workaround for an issue caused by noglob option of shell for -device ?

PATCH NAK Lin Ma 3 participants 3 messages Jun 26, 2016 – Jun 27, 2016

lore
Share & tools
lore

Lin Ma

author
#0 lore raw

PATCH 1/1 qdev: Workaround for an issue caused by noglob option of shell for -device ?

If there is any filename in current path matching wildcard ?, This filename will be passed into -device ? while 'pathname expansion' isn't disabled by noglob of shell built-in option, qemu reports error in this case.

---
 qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
qdev-monitor.c +5 -0
index e19617f..f6443cd 100644
@@ -257,6 +257,11 @@ int qdev_device_help(QemuOpts *opts)
     DevicePropertyInfoList *prop;
 
     driver = qemu_opt_get(opts, "driver");
+
+    if (driver && access(driver, F_OK == 0) && strlen(driver) == 1) {
+        driver = "?";
+    }
+
     if (driver && is_help_option(driver)) {
         qdev_print_devinfos(false);
         return 1;
Signature · 1 line
2.8.1
#1 lore raw
Quoted 15 lines · Lin Ma

If there is any filename in current path matching wildcard ?, This filename will be passed into -device ? while 'pathname expansion' isn't disabled by noglob of shell built-in option, qemu reports error in this case.

---
 qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
qdev-monitor.c +0 -0
index e19617f..f6443cd 100644
@@ -257,6 +257,11 @@ int qdev_device_help(QemuOpts *opts)
     DevicePropertyInfoList *prop;

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 267

Quoted 10 lines
qdev-monitor.c +5 -0
 
     driver = qemu_opt_get(opts, "driver");
+
+    if (driver && access(driver, F_OK == 0) && strlen(driver) == 1) {
+        driver = "?";
+    }
+
     if (driver && is_help_option(driver)) {
         qdev_print_devinfos(false);
         return 1;

I'm afraid this would silently interpret any one-character driver name as a request for help when a file with this name exists. Not a good idea. Example: "-device .".

"-device ?" and similar use of "?" elsewhere is deprecated. Please use "-device help".

#2 lore raw
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Lin Ma

If there is any filename in current path matching wildcard ?, This filename will be passed into -device ? while 'pathname expansion' isn't disabled by noglob of shell built-in option, qemu reports error in this case.

And if there is more than one such file, then the glob expands to all such files, turning '-device ?' into '-device a b', which your patch does not handle. You CANNOT reliably detect if a glob was expanded, so it is pointless to try. (At one point, glibc+bash had a tentative patch that would set an environment variable according to the pre-glob command line passed through the shell, so that the child app could reverse engineer what globs had been expanded, but it was discarded YEARS ago as not worth the overhead).

Quoted 13 lines
Quoted 13 lines
---
 qdev-monitor.c | 5 +++++
 1 file changed, 5 insertions(+)
qdev-monitor.c +0 -0
index e19617f..f6443cd 100644
@@ -257,6 +257,11 @@ int qdev_device_help(QemuOpts *opts)
     DevicePropertyInfoList *prop;
 
Quoted 5 lines

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 263

Quoted 5 lines
qdev-monitor.c +4 -0
     driver = qemu_opt_get(opts, "driver");
+
+    if (driver && access(driver, F_OK == 0) && strlen(driver) == 1) {
+        driver = "?";
+    }

NACK.

Quoted 11 lines

qdev-monitor.c int qdev_device_help(QemuOpts *opts) · line 267

Quoted 4 lines
qdev-monitor.c +1 -0
+
     if (driver && is_help_option(driver)) {
         qdev_print_devinfos(false);
         return 1;

I'm afraid this would silently interpret any one-character driver name as a request for help when a file with this name exists. Not a good idea. Example: "-device .".

"-device ?" and similar use of "?" elsewhere is deprecated. Please use "-device help".

Agreed - we invented 'help' as a synonym for '?' precisely because '?' can't be worked around.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org