initialize progname with error_set_progname()
v2 cover initialize progname with error_set_progname()
In the context of some subcommands of QEMU, error_get_progname() can be used for obtaining argv[0]. The function is useful for the commands because it is possible to detect a name of executable file and switch behavior based on the function like busybox. e.g. block drivers can switch behavior based on the name (qemu itself, qemu-img, or qemu-io).
But calling error_get_progname() in some commands causes segmentation fault because initialization, calling error_set_progname(), isn't done. This patchset adds the initialization to the commands which lacks it but linked to util/qemu-error.o (one exception is bsd-user, because I don't have an environment which can build and test it).
Currently, the missing call of error_set_progname() doesn't cause any problems because the changed commands don't use error_get_progname(). This patchset is a proactive action (but sheepdog driver will use it soon).
v2:
- pass argv[0] directly to error_set_progname() without calling basename
- add initialization to commands other than qemu-io
The thread of v1 can be found here:
http://lists.gnu.org/archive/html/qemu-devel/2014-08/msg01502.html
Hitoshi Mitake (4):
qemu-io: initialize progname with error_set_progname()
qemu-nbd: initialize progname with error_set_progname()
qga: initialize progname with error_set_progname()
linux-user: initialize progname with error_set_progname()
linux-user/main.c | 2 ++ qemu-io.c | 1 + qemu-nbd.c | 1 + qga/main.c | 1 + 4 files changed, 5 insertions(+)
Signature · 1 line
1.9.1
PATCH v2 1/4 qemu-io: initialize progname with error_set_progname()
Calling error_get_progname() in the context of qemu-io can cause segmentation fault because qemu-io doesn't initialize its progname with error_set_progname(). This patch adds the initialization.
Currently, the missing call of error_set_progname() doesn't cause any problems because qemu-io doesn't use error_get_progname(). This patch is a proactive action.
--- qemu-io.c | 1 + 1 file changed, 1 insertion(+)
v2:
- pass argv[0] directly to error_set_progname() without calling basename
qemu-io.c +1 -0
@@ -396,6 +396,7 @@ int main(int argc, char **argv) progname =basename (argv[0 ]);qemu_init_exec_dir (argv[0 ]); +error_set_progname (argv[0 ]);bdrv_init ();
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
At Thu, 22 Jan 2015 18:08:11 +0900,
Quoted 9 lines · Hitoshi Mitake
Calling
error_get_progname()in the context of qemu-io can cause segmentation fault because qemu-io doesn't initialize its progname witherror_set_progname(). This patch adds the initialization.Currently, the missing call of
error_set_progname()doesn't cause any problems because qemu-io doesn't useerror_get_progname(). This patch is a proactive action.
Quoted 7 lines
Cc Kevin Wolf <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by Hitoshi Mitake <[email protected]>--- qemu-io.c | 1 + 1 file changed, 1 insertion(+)
Hi Kevin, Stefan, could you pick this patch? sheepdog driver has a pending patch [1] which depends on it. I believe at least qemu-io should call error_set_progname() because block drivers can use the qemu-error infrastructure.
[1] https://github.com/sheepdog/qemu/commit/a95c35e606a2a189e7dbaf645277c5c306b01e4b
Thanks,
Hitoshi
Quoted 19 lines
v2:
- pass argv[0] directly toerror_set_progname()without calling basenameqemu-io.c +1
-0@@ -396,6 +396,7 @@ int main(int argc, char **argv) progname =basename (argv[0 ]);qemu_init_exec_dir (argv[0 ]); +error_set_progname (argv[0 ]);bdrv_init ();Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
Am 02.02.2015 um 10:51 hat Hitoshi Mitake geschrieben:
Quoted 19 lines
At Thu, 22 Jan 2015 18:08:11 +0900,
Quoted 9 lines · Hitoshi Mitake
Calling
error_get_progname()in the context of qemu-io can cause segmentation fault because qemu-io doesn't initialize its progname witherror_set_progname(). This patch adds the initialization.Currently, the missing call of
error_set_progname()doesn't cause any problems because qemu-io doesn't useerror_get_progname(). This patch is a proactive action.Quoted 7 lines
Cc Kevin Wolf <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by Hitoshi Mitake <[email protected]>--- qemu-io.c | 1 + 1 file changed, 1 insertion(+)
Quoted 4 lines
Hi Kevin, Stefan, could you pick this patch? sheepdog driver has a pending patch [1] which depends on it. I believe at least qemu-io should call
error_set_progname()because block drivers can use the qemu-error infrastructure.
So are you planning to get the individual patches merged on their own instead of the whole series as one?
That patch looks wrong. Nobody guarantees that qemu-io is really called qemu-io. The user can name their binaries as they want and create symlinks with any name, and indeed names for qemu-img used by some distributions include 'qemu-img-kvm' and 'kvm-img'. You need to find a different way than checking binary file names.
Kevin
Re: [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
At Mon, 2 Feb 2015 12:36:00 +0100,
Quoted 21 lines · Kevin Wolf
Am 02.02.2015 um 10:51 hat Hitoshi Mitake geschrieben:
Quoted 19 lines
At Thu, 22 Jan 2015 18:08:11 +0900,
Quoted 16 lines · Hitoshi Mitake
Calling
error_get_progname()in the context of qemu-io can cause segmentation fault because qemu-io doesn't initialize its progname witherror_set_progname(). This patch adds the initialization.Currently, the missing call of
error_set_progname()doesn't cause any problems because qemu-io doesn't useerror_get_progname(). This patch is a proactive action.Cc Kevin Wolf <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by Hitoshi Mitake <[email protected]>--- qemu-io.c | 1 + 1 file changed, 1 insertion(+)
Quoted 7 lines
Quoted 4 lines
Hi Kevin, Stefan, could you pick this patch? sheepdog driver has a pending patch [1] which depends on it. I believe at least qemu-io should call
error_set_progname()because block drivers can use the qemu-error infrastructure.So are you planning to get the individual patches merged on their own instead of the whole series as one?
I thought this patchset can be proactive fix. So I'm separating the patch for sheepdog driver from this one.
Quoted 8 lines
That patch looks wrong. Nobody guarantees that qemu-io is really called qemu-io. The user can name their binaries as they want and create symlinks with any name, and indeed names for qemu-img used by some distributions include 'qemu-img-kvm' and 'kvm-img'. You need to find a different way than checking binary file names.
I couldn't consider about the case, thanks for pointing! I'll seek other method for distinguishing binary files.
Thanks,
Hitoshi
Quoted 2 lines
Kevin
PATCH v2 2/4 qemu-nbd: initialize progname with error_set_progname()
In reply to Hitoshi MitakeCalling error_get_progname() in the context of qemu-nbd can cause segmentation fault because qemu-nbd doesn't initialize its progname with error_set_progname(). This patch adds the initialization.
Currently, the missing call of error_set_progname() doesn't cause any problems because qemu-nbd doesn't use error_get_progname(). This patch is a proactive action.
--- qemu-nbd.c | 1 + 1 file changed, 1 insertion(+)
qemu-nbd.c +1 -0
@@ -449,6 +449,7 @@ int main(int argc, char **argv) sa_sigterm.sa_handler = termsig_handler;sigaction (SIGTERM , &sa_sigterm,NULL );qemu_init_exec_dir (argv[0 ]); +error_set_progname (argv[0 ]);while ((ch =getopt_long (argc, argv, sopt, lopt, &opt_ind)) !=-1 ) {switch (ch) {
Signature · 1 line
1.9.1
PATCH v2 3/4 qga: initialize progname with error_set_progname()
In reply to Hitoshi MitakeCalling error_get_progname() in the context of qga can cause segmentation fault because qga doesn't initialize its progname with error_set_progname(). This patch adds the initialization.
Currently, the missing call of error_set_progname() doesn't cause any problems because qga doesn't use error_get_progname(). This patch is a proactive action.
--- qga/main.c | 1 + 1 file changed, 1 insertion(+)
qga/main.c +1 -0
@@ -958,6 +958,7 @@ int main(int argc, char **argv)GList *blacklist =NULL ;GAState *s; +error_set_progname (argv[0 ]);module_call_init (MODULE_INIT_QAPI );init_dfl_pathnames ();
Signature · 1 line
1.9.1
PATCH v2 4/4 linux-user: initialize progname with error_set_progname()
In reply to Hitoshi MitakeCalling error_get_progname() in the context of qemu-x86_64 can cause segmentation fault because linux-user/main.c doesn't initialize its progname with error_set_progname(). This patch adds the initialization.
Currently, the missing call of error_set_progname() doesn't cause any problems because qemu-x86_64 doesn't use error_get_progname(). This patch is a proactive action.
--- linux-user/main.c | 2 ++ 1 file changed, 2 insertions(+)
linux-user/main.c +2 -0
@@ -33,6 +33,7 @@#include "qemu/timer.h" #include "qemu/envlist.h" #include "elf.h" +#include "qemu/error-report.h" char *exec_path;
@@ -3835,6 +3836,7 @@ int main(int argc, char **argv, char **envp)int ret;int execfd; +error_set_progname (argv[0 ]);module_call_init (MODULE_INIT_QOM );if ((envlist =envlist_create ()) ==NULL ) {
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v2 4/4] linux-user: initialize progname with error_set_progname()
Quoted 8 lines · Hitoshi Mitake
Calling
error_get_progname()in the context of qemu-x86_64 can cause segmentation fault becauselinux-user/main.cdoesn't initialize its progname witherror_set_progname(). This patch adds the initialization.Currently, the missing call of
error_set_progname()doesn't cause any problems because qemu-x86_64 doesn't useerror_get_progname(). This patch is a proactive action.
I don't think this patch is right. The *-user binaries don't (and should not) use the qemu-error infrastructure (they don't have the monitor or any of the other stuff that uses). Code which tries to use error_get_progname() in *-user would be broken.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v2 4/4] linux-user: initialize progname with error_set_progname()
Hi Peter,
Sorry for my late reply.
At Thu, 22 Jan 2015 10:07:27 +0000,
Quoted 12 lines · Peter Maydell
Quoted 8 lines · Hitoshi Mitake
Calling
error_get_progname()in the context of qemu-x86_64 can cause segmentation fault becauselinux-user/main.cdoesn't initialize its progname witherror_set_progname(). This patch adds the initialization.Currently, the missing call of
error_set_progname()doesn't cause any problems because qemu-x86_64 doesn't useerror_get_progname(). This patch is a proactive action.
Quoted 5 lines
I don't think this patch is right. The *-user binaries don't (and should not) use the qemu-error infrastructure (they don't have the monitor or any of the other stuff that uses). Code which tries to use
error_get_progname()in *-user would be broken.
I just thought linux-user would be a potential user of the qemu-error infrastructure because it is liked with util/qemu-error.o. Actually, the changes of the patch (let linux-user/main.c include "qemu/error-report.h" and call error_get_progname()) didn't cause any problems.
But I'm not familiar with linux-user. If the command should never be a user of the error infrastructure, I'd like to drop this patch, of course.
Thanks,
Hitoshi
Quoted 5 lines · Hitoshi Mitake
In the context of some subcommands of QEMU,
error_get_progname()can be used for obtaining argv[0]. The function is useful for the commands because it is possible to detect a name of executable file and switch behavior based on the function like busybox. e.g. block drivers can switch behavior based on the name (qemu itself, qemu-img, or qemu-io).
Changing behavior based on argv[0] is usually a bad idea.
Current use of error_get_progname() is limited to error messages and such. That's a good idea.
Quoted 9 lines
But calling
error_get_progname()in some commands causes segmentation fault because initialization, callingerror_set_progname(), isn't done. This patchset adds the initialization to the commands which lacks it but linked toutil/qemu-error.o(one exception is bsd-user, because I don't have an environment which can build and test it).Currently, the missing call of
error_set_progname()doesn't cause any problems because the changed commands don't useerror_get_progname(). This patchset is a proactive action (but sheepdog driver will use it soon).
I'm fine with calling error_set_progname() in all programs linking with qemu-error.c.
I'm reserving judgement on its use in block drivers. Please cc me on that patch.
Series