From: David CARLIER <devnexen@gmail.com>
To: Justin Hibbits <chmeeedalf@gmail.com>
Cc: qemu-trivial@nongnu.org,
"Mikhail Gusarov" <dottedmag@dottedmag.net>,
qemu-devel@nongnu.org,
"John Arbuckle" <programmingkidx@gmail.com>,
"Roman Bolshakov" <r.bolshakov@yadro.com>,
"Izik Eidus" <izik@veertu.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH] util/oslib-posix : qemu_init_exec_dir implementation for MacOS
Date: Wed, 3 Jun 2020 15:22:26 +0100 [thread overview]
Message-ID: <CA+XhMqw2ORNvkN=C+LdvMxDvrX2i25FW-9wXias6Mbu0wGjBrg@mail.gmail.com> (raw)
In-Reply-To: <20200603090921.64351a28@titan.knownspace>
Good point even tough the libproc api is here in this form since quite a time.
From d23bf60961ee036f8298794f879d1b8b9bd717dc Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Tue, 26 May 2020 21:35:27 +0100
Subject: [PATCH] util/oslib: current process full path resolution on MacOS
Using existing libproc to fill the path.
Signed-off-by: David Carlier <devnexen@gmail.com>
---
util/oslib-posix.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 062236a1ab..9dd1e1a18b 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -55,6 +55,10 @@
#include <sys/sysctl.h>
#endif
+#ifdef __APPLE__
+#include <libproc.h>
+#endif
+
#include "qemu/mmap-alloc.h"
#ifdef CONFIG_DEBUG_STACK_USAGE
@@ -366,6 +370,15 @@ void qemu_init_exec_dir(const char *argv0)
p = buf;
}
}
+#elif defined(__APPLE__)
+ {
+ int len;
+ len = proc_pidpath(getpid(), buf, sizeof(buf) - 1);
+ if (len <= 0) {
+ return;
+ }
+ p = buf;
+ }
#endif
/* If we don't have any way of figuring out the actual executable
location then try argv[0]. */
--
2.26.2
On Wed, 3 Jun 2020 at 15:09, Justin Hibbits <chmeeedalf@gmail.com> wrote:
>
> On Wed, 3 Jun 2020 08:08:42 +0200
> Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> > Cc'ing more developers.
> >
> > On 5/26/20 10:40 PM, David CARLIER wrote:
> > > From b24a6702beb2a4e2a9c1c03b69c6d1dd07d4cf08 Mon Sep 17 00:00:00
> > > 2001 From: David Carlier <devnexen@gmail.com>
> > > Date: Tue, 26 May 2020 21:35:27 +0100
> > > Subject: [PATCH] util/oslib: current process full path resolution
> > > on MacOS
> > >
> > > Using existing libproc to fill the path.
> > >
> > > Signed-off-by: David Carlier <devnexen@gmail.com>
> > > ---
> > > util/oslib-posix.c | 13 +++++++++++++
> > > 1 file changed, 13 insertions(+)
> > >
> > > diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> > > index 062236a1ab..96f0405ee6 100644
> > > --- a/util/oslib-posix.c
> > > +++ b/util/oslib-posix.c
> > > @@ -55,6 +55,10 @@
> > > #include <sys/sysctl.h>
> > > #endif
> > >
> > > +#ifdef __APPLE__
> > > +#include <libproc.h>
> > > +#endif
> > > +
> > > #include "qemu/mmap-alloc.h"
> > >
> > > #ifdef CONFIG_DEBUG_STACK_USAGE
> > > @@ -366,6 +370,15 @@ void qemu_init_exec_dir(const char *argv0)
> > > p = buf;
> > > }
> > > }
> > > +#elif defined(__APPLE__)
> > > + {
> > > + uint32_t len;
> > > + len = proc_pidpath(getpid(), buf, sizeof(buf) - 1);
> > > + if (len > 0) {
> > > + buf[len] = 0;
> > > + p = buf;
> > > + }
> > > + }
> > > #endif
> > > /* If we don't have any way of figuring out the actual
> > > executable location then try argv[0]. */
> > >
> >
>
> Apologies, I don't have context for this. Why was I CC'd on this?
>
> Does proc_pidpath() not NUL-terminate its written string? And, given
> from my quick google search, it looks like this function is private and
> subject to change, so can you guarantee that the returned length is the
> *written* length, not the full string length? If not, you could be
> overwriting other arbitrary data.
>
> - Justin
next prev parent reply other threads:[~2020-06-03 14:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-26 20:40 [PATCH] util/oslib-posix : qemu_init_exec_dir implementation for MacOS David CARLIER
2020-05-26 22:25 ` David CARLIER
2020-06-03 6:08 ` Philippe Mathieu-Daudé
2020-06-03 6:16 ` David CARLIER
2020-06-03 14:09 ` Justin Hibbits
2020-06-03 14:22 ` David CARLIER [this message]
2020-06-03 14:38 ` Philippe Mathieu-Daudé
2020-06-15 16:26 ` Peter Maydell
2020-06-03 14:36 ` Philippe Mathieu-Daudé
2020-06-03 16:08 ` Justin Hibbits
2020-06-08 6:02 ` Roman Bolshakov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+XhMqw2ORNvkN=C+LdvMxDvrX2i25FW-9wXias6Mbu0wGjBrg@mail.gmail.com' \
--to=devnexen@gmail.com \
--cc=chmeeedalf@gmail.com \
--cc=dottedmag@dottedmag.net \
--cc=izik@veertu.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=r.bolshakov@yadro.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).