From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO5NZ-0001YJ-0P for qemu-devel@nongnu.org; Thu, 13 Mar 2014 09:09:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WO5NR-0000zH-K8 for qemu-devel@nongnu.org; Thu, 13 Mar 2014 09:08:56 -0400 Received: from cantor2.suse.de ([195.135.220.15]:57410 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO5NR-0000z8-Av for qemu-devel@nongnu.org; Thu, 13 Mar 2014 09:08:49 -0400 Message-ID: <5321ADDE.4030703@suse.de> Date: Thu, 13 Mar 2014 14:08:46 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1392899343-5226-1-git-send-email-pbonzini@redhat.com> <1392899343-5226-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1392899343-5226-2-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PULL 01/12] util: Split out exec_dir from os_find_datadir List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org, famz@redhat.com Cc: peter.maydell@linaro.org, aliguori@amazon.com Am 20.02.2014 13:28, schrieb Paolo Bonzini: > From: Fam Zheng >=20 > With this change, main() calls qemu_init_exec_dir and uses argv[0] to > init exec_dir. The saved value can be retrieved with > qemu_get_exec_dir later. It will be reused by module loading. >=20 > Signed-off-by: Fam Zheng > Signed-off-by: Paolo Bonzini [...] > diff --git a/os-posix.c b/os-posix.c > index d39261d..6187301 100644 > --- a/os-posix.c > +++ b/os-posix.c > @@ -84,46 +84,17 @@ void os_setup_signal_handling(void) > running from the build tree this will be "$bindir/../pc-bios". */ > #define SHARE_SUFFIX "/share/qemu" > #define BUILD_SUFFIX "/pc-bios" > -char *os_find_datadir(const char *argv0) > +char *os_find_datadir(void) > { > - char *dir; > - char *p =3D NULL; > + char *dir, *exec_dir; > char *res; > - char buf[PATH_MAX]; > size_t max_len; > =20 > -#if defined(__linux__) > - { > - int len; > - len =3D readlink("/proc/self/exe", buf, sizeof(buf) - 1); > - if (len > 0) { > - buf[len] =3D 0; > - p =3D buf; > - } > - } > -#elif defined(__FreeBSD__) > - { > - static int mib[4] =3D {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME= , -1}; > - size_t len =3D sizeof(buf) - 1; > - > - *buf =3D '\0'; > - if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && > - *buf) { > - buf[sizeof(buf) - 1] =3D '\0'; > - p =3D buf; > - } > - } > -#endif > - /* If we don't have any way of figuring out the actual executable > - location then try argv[0]. */ > - if (!p) { > - p =3D realpath(argv0, buf); > - if (!p) { > - return NULL; > - } > + exec_dir =3D qemu_get_exec_dir(); > + if (exec_dir =3D=3D NULL) { > + return NULL; > } > - dir =3D dirname(p); > - dir =3D dirname(dir); > + dir =3D dirname(exec_dir); > =20 > max_len =3D strlen(dir) + > MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; > @@ -137,6 +108,7 @@ char *os_find_datadir(const char *argv0) > } > } > =20 > + g_free(exec_dir); > return res; > } > #undef SHARE_SUFFIX [...] > diff --git a/util/oslib-posix.c b/util/oslib-posix.c > index d5dca47..c2eeb4f 100644 > --- a/util/oslib-posix.c > +++ b/util/oslib-posix.c > @@ -57,6 +57,7 @@ extern int daemon(int, int); > #include "trace.h" > #include "qemu/sockets.h" > #include > +#include > =20 > #ifdef CONFIG_LINUX > #include > @@ -274,3 +275,56 @@ void qemu_set_tty_echo(int fd, bool echo) > =20 > tcsetattr(fd, TCSANOW, &tty); > } > + > +static char exec_dir[PATH_MAX]; > + > +void qemu_init_exec_dir(const char *argv0) > +{ > + char *dir; > + char *p =3D NULL; > + char buf[PATH_MAX]; > + > + assert(!exec_dir[0]); > + > +#if defined(__linux__) > + { > + int len; > + len =3D readlink("/proc/self/exe", buf, sizeof(buf) - 1); > + if (len > 0) { > + buf[len] =3D 0; > + p =3D buf; > + } > + } > +#elif defined(__FreeBSD__) > + { > + static int mib[4] =3D {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME= , -1}; This code movement broke the build on FreeBSD, CTL_KERN undeclared. :( Probably some #include missing? Regards, Andreas > + size_t len =3D sizeof(buf) - 1; > + > + *buf =3D '\0'; > + if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && > + *buf) { > + buf[sizeof(buf) - 1] =3D '\0'; > + p =3D buf; > + } > + } > +#endif > + /* If we don't have any way of figuring out the actual executable > + location then try argv[0]. */ > + if (!p) { > + if (!argv0) { > + return; > + } > + p =3D realpath(argv0, buf); > + if (!p) { > + return; > + } > + } > + dir =3D dirname(p); > + > + pstrcpy(exec_dir, sizeof(exec_dir), dir); > +} > + > +char *qemu_get_exec_dir(void) > +{ > + return g_strdup(exec_dir); > +} [snip] --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg