All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname()
@ 2015-01-22  9:08 Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 1/4] qemu-io: " Hitoshi Mitake
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Hitoshi Mitake @ 2015-01-22  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, mitake.hitoshi, Hitoshi Mitake, riku.voipio, armbru,
	mdroth, stefanha, pbonzini

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(+)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
  2015-01-22  9:08 [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname() Hitoshi Mitake
@ 2015-01-22  9:08 ` Hitoshi Mitake
  2015-02-02  9:51   ` Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 2/4] qemu-nbd: " Hitoshi Mitake
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Hitoshi Mitake @ 2015-01-22  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Hitoshi Mitake, Kevin Wolf, Stefan Hajnoczi, mitake.hitoshi,
	Markus Armbruster

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.

Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
---
 qemu-io.c | 1 +
 1 file changed, 1 insertion(+)

v2:
 - pass argv[0] directly to error_set_progname() without calling basename

diff --git a/qemu-io.c b/qemu-io.c
index 91a445a..0e7d7d4 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -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();
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH v2 2/4] qemu-nbd: initialize progname with error_set_progname()
  2015-01-22  9:08 [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname() Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 1/4] qemu-io: " Hitoshi Mitake
@ 2015-01-22  9:08 ` Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 3/4] qga: " Hitoshi Mitake
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Hitoshi Mitake @ 2015-01-22  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Hitoshi Mitake, Paolo Bonzini, Markus Armbruster, mitake.hitoshi

Calling 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.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
---
 qemu-nbd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index d222512..fad5634 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -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) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH v2 3/4] qga: initialize progname with error_set_progname()
  2015-01-22  9:08 [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname() Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 1/4] qemu-io: " Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 2/4] qemu-nbd: " Hitoshi Mitake
@ 2015-01-22  9:08 ` Hitoshi Mitake
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 4/4] linux-user: " Hitoshi Mitake
  2015-01-22  9:47 ` [Qemu-devel] [PATCH v2 0/4] " Markus Armbruster
  4 siblings, 0 replies; 11+ messages in thread
From: Hitoshi Mitake @ 2015-01-22  9:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: Hitoshi Mitake, Michael Roth, mitake.hitoshi, Markus Armbruster

Calling 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.

Cc: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
---
 qga/main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/qga/main.c b/qga/main.c
index 9939a2b..0885fc6 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -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();
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Qemu-devel] [PATCH v2 4/4] linux-user: initialize progname with error_set_progname()
  2015-01-22  9:08 [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname() Hitoshi Mitake
                   ` (2 preceding siblings ...)
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 3/4] qga: " Hitoshi Mitake
@ 2015-01-22  9:08 ` Hitoshi Mitake
  2015-01-22 10:07   ` Peter Maydell
  2015-01-22  9:47 ` [Qemu-devel] [PATCH v2 0/4] " Markus Armbruster
  4 siblings, 1 reply; 11+ messages in thread
From: Hitoshi Mitake @ 2015-01-22  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hitoshi Mitake, Riku Voipio, Markus Armbruster, mitake.hitoshi

Calling 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.

Cc: Riku Voipio <riku.voipio@iki.fi>
Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
---
 linux-user/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/main.c b/linux-user/main.c
index 8c70be4..4610b20 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -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) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname()
  2015-01-22  9:08 [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname() Hitoshi Mitake
                   ` (3 preceding siblings ...)
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 4/4] linux-user: " Hitoshi Mitake
@ 2015-01-22  9:47 ` Markus Armbruster
  4 siblings, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2015-01-22  9:47 UTC (permalink / raw)
  To: Hitoshi Mitake
  Cc: kwolf, mitake.hitoshi, riku.voipio, qemu-devel, mdroth, stefanha,
	pbonzini

Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp> writes:

> 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.

> 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).

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
Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH v2 4/4] linux-user: initialize progname with error_set_progname()
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 4/4] linux-user: " Hitoshi Mitake
@ 2015-01-22 10:07   ` Peter Maydell
  2015-02-02  9:47     ` Hitoshi Mitake
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Maydell @ 2015-01-22 10:07 UTC (permalink / raw)
  To: Hitoshi Mitake
  Cc: Riku Voipio, QEMU Developers, mitake.hitoshi, Markus Armbruster

On 22 January 2015 at 09:08, Hitoshi Mitake
<mitake.hitoshi@lab.ntt.co.jp> wrote:
> Calling 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.

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH v2 4/4] linux-user: initialize progname with error_set_progname()
  2015-01-22 10:07   ` Peter Maydell
@ 2015-02-02  9:47     ` Hitoshi Mitake
  0 siblings, 0 replies; 11+ messages in thread
From: Hitoshi Mitake @ 2015-02-02  9:47 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Hitoshi Mitake, Riku Voipio, QEMU Developers, mitake.hitoshi,
	Markus Armbruster


Hi Peter,
Sorry for my late reply.

At Thu, 22 Jan 2015 10:07:27 +0000,
Peter Maydell wrote:
> 
> On 22 January 2015 at 09:08, Hitoshi Mitake
> <mitake.hitoshi@lab.ntt.co.jp> wrote:
> > Calling 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.
> 
> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
  2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 1/4] qemu-io: " Hitoshi Mitake
@ 2015-02-02  9:51   ` Hitoshi Mitake
  2015-02-02 11:36     ` Kevin Wolf
  0 siblings, 1 reply; 11+ messages in thread
From: Hitoshi Mitake @ 2015-02-02  9:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: Hitoshi Mitake, Kevin Wolf, Stefan Hajnoczi, mitake.hitoshi,
	Markus Armbruster

At Thu, 22 Jan 2015 18:08:11 +0900,
Hitoshi Mitake wrote:
> 
> 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.
> 
> Cc: Kevin Wolf <kwolf@redhat.com>
> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> Cc: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
> ---
>  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

> 
> v2:
>  - pass argv[0] directly to error_set_progname() without calling basename
> 
> diff --git a/qemu-io.c b/qemu-io.c
> index 91a445a..0e7d7d4 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -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();
>  
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
  2015-02-02  9:51   ` Hitoshi Mitake
@ 2015-02-02 11:36     ` Kevin Wolf
  2015-02-02 14:04       ` Hitoshi Mitake
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Wolf @ 2015-02-02 11:36 UTC (permalink / raw)
  To: Hitoshi Mitake
  Cc: Stefan Hajnoczi, qemu-devel, mitake.hitoshi, Markus Armbruster

Am 02.02.2015 um 10:51 hat Hitoshi Mitake geschrieben:
> At Thu, 22 Jan 2015 18:08:11 +0900,
> Hitoshi Mitake wrote:
> > 
> > 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.
> > 
> > Cc: Kevin Wolf <kwolf@redhat.com>
> > Cc: Stefan Hajnoczi <stefanha@redhat.com>
> > Cc: Markus Armbruster <armbru@redhat.com>
> > Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
> > ---
> >  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.

So are you planning to get the individual patches merged on their own
instead of the whole series as one?

> [1] https://github.com/sheepdog/qemu/commit/a95c35e606a2a189e7dbaf645277c5c306b01e4b

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/4] qemu-io: initialize progname with error_set_progname()
  2015-02-02 11:36     ` Kevin Wolf
@ 2015-02-02 14:04       ` Hitoshi Mitake
  0 siblings, 0 replies; 11+ messages in thread
From: Hitoshi Mitake @ 2015-02-02 14:04 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: Hitoshi Mitake, Stefan Hajnoczi, qemu-devel, mitake.hitoshi,
	Markus Armbruster

At Mon, 2 Feb 2015 12:36:00 +0100,
Kevin Wolf wrote:
> 
> Am 02.02.2015 um 10:51 hat Hitoshi Mitake geschrieben:
> > At Thu, 22 Jan 2015 18:08:11 +0900,
> > Hitoshi Mitake wrote:
> > > 
> > > 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.
> > > 
> > > Cc: Kevin Wolf <kwolf@redhat.com>
> > > Cc: Stefan Hajnoczi <stefanha@redhat.com>
> > > Cc: Markus Armbruster <armbru@redhat.com>
> > > Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
> > > ---
> > >  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.
> 
> 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.

> 
> > [1] https://github.com/sheepdog/qemu/commit/a95c35e606a2a189e7dbaf645277c5c306b01e4b
> 
> 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

> 
> Kevin

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-02-02 14:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-22  9:08 [Qemu-devel] [PATCH v2 0/4] initialize progname with error_set_progname() Hitoshi Mitake
2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 1/4] qemu-io: " Hitoshi Mitake
2015-02-02  9:51   ` Hitoshi Mitake
2015-02-02 11:36     ` Kevin Wolf
2015-02-02 14:04       ` Hitoshi Mitake
2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 2/4] qemu-nbd: " Hitoshi Mitake
2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 3/4] qga: " Hitoshi Mitake
2015-01-22  9:08 ` [Qemu-devel] [PATCH v2 4/4] linux-user: " Hitoshi Mitake
2015-01-22 10:07   ` Peter Maydell
2015-02-02  9:47     ` Hitoshi Mitake
2015-01-22  9:47 ` [Qemu-devel] [PATCH v2 0/4] " Markus Armbruster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.