From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HJ97o-0002mJ-1T for qemu-devel@nongnu.org; Mon, 19 Feb 2007 09:04:16 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HJ97m-0002m1-GR for qemu-devel@nongnu.org; Mon, 19 Feb 2007 09:04:15 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HJ97m-0002lx-Dg for qemu-devel@nongnu.org; Mon, 19 Feb 2007 09:04:14 -0500 Received: from partizan.velesys.com ([213.184.230.195]) by monty-python.gnu.org with esmtp (Exim 4.52) id 1HJ97k-0004yl-3z for qemu-devel@nongnu.org; Mon, 19 Feb 2007 09:04:14 -0500 Received: from localhost (partizan [10.0.0.24]) by partizan.velesys.com (paritzan.velesys.com) with ESMTP id 77906D6324A for ; Mon, 19 Feb 2007 16:06:14 +0200 (EET) Received: from partizan.velesys.com ([10.0.0.24]) by localhost (partizan.velesys.com [10.0.0.24]) (amavisd-new, port 10024) with ESMTP id 3OLtLf-3sRZq for ; Mon, 19 Feb 2007 16:06:08 +0200 (EET) Received: from localhost.localdomain (mm-110-150-57-86.adsl.mgts.by [86.57.150.110]) by partizan.velesys.com (paritzan.velesys.com) with ESMTP id 22E56D632F8 for ; Mon, 19 Feb 2007 16:06:08 +0200 (EET) Date: Mon, 19 Feb 2007 16:04:09 +0300 From: "Kirill A. Shutemov" Message-ID: <20070219130409.GD25556@localhost.localdomain> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZInfyf7laFu/Kiw7" Content-Disposition: inline Subject: [Qemu-devel] [PATCH] [REPOST] Simplily linux-user/path.c Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --ZInfyf7laFu/Kiw7 Content-Type: multipart/mixed; boundary="KdquIMZPjGJQvRdI" Content-Disposition: inline --KdquIMZPjGJQvRdI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Fixed version of the patch in the attacment. Please, comment. --KdquIMZPjGJQvRdI Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="qemu-0.8.2-alt-path.patch" Content-Transfer-Encoding: quoted-printable --- qemu-0.8.2/linux-user/path.c.orig 2006-12-21 17:16:03 +0200 +++ qemu-0.8.2/linux-user/path.c 2006-12-21 17:14:08 +0200 @@ -1,147 +1,37 @@ /* Code to mangle pathnames into those matching a given prefix. eg. open("/lib/foo.so") =3D> open("/usr/gnemul/i386-linux/lib/foo.so"); - - The assumption is that this area does not change. -*/ + */ #include -#include +#include #include -#include #include -#include #include #include "qemu.h" =20 -struct pathelem -{ - /* Name of this, eg. lib */ - char *name; - /* Full path name, eg. /usr/gnemul/x86-linux/lib. */ - char *pathname; - struct pathelem *parent; - /* Children */ - unsigned int num_entries; - struct pathelem *entries[0]; -}; - -static struct pathelem *base; - -/* First N chars of S1 match S2, and S2 is N chars long. */ -static int strneq(const char *s1, unsigned int n, const char *s2) -{ - unsigned int i; - - for (i =3D 0; i < n; i++) - if (s1[i] !=3D s2[i]) - return 0; - return s2[i] =3D=3D 0; -} - -static struct pathelem *add_entry(struct pathelem *root, const char *name); - -static struct pathelem *new_entry(const char *root, - struct pathelem *parent, - const char *name) -{ - struct pathelem *new =3D malloc(sizeof(*new)); - new->name =3D strdup(name); - asprintf(&new->pathname, "%s/%s", root, name); - new->num_entries =3D 0; - return new; -} - -#define streq(a,b) (strcmp((a), (b)) =3D=3D 0) - -static struct pathelem *add_dir_maybe(struct pathelem *path) -{ - DIR *dir; - - if ((dir =3D opendir(path->pathname)) !=3D NULL) { - struct dirent *dirent; - - while ((dirent =3D readdir(dir)) !=3D NULL) { - if (!streq(dirent->d_name,".") && !streq(dirent->d_name,"..")){ - path =3D add_entry(path, dirent->d_name); - } - } - closedir(dir); - } - return path; -} - -static struct pathelem *add_entry(struct pathelem *root, const char *name) -{ - root->num_entries++; - - root =3D realloc(root, sizeof(*root) - + sizeof(root->entries[0])*root->num_entries); - - root->entries[root->num_entries-1] =3D new_entry(root->pathname, root,= name); - root->entries[root->num_entries-1] - =3D add_dir_maybe(root->entries[root->num_entries-1]); - return root; -} - -/* This needs to be done after tree is stabalized (ie. no more reallocs!).= */ -static void set_parents(struct pathelem *child, struct pathelem *parent) -{ - unsigned int i; - - child->parent =3D parent; - for (i =3D 0; i < child->num_entries; i++) - set_parents(child->entries[i], child); -} +static char* pref; =20 void init_paths(const char *prefix) { if (prefix[0] !=3D '/' || - prefix[0] =3D=3D '\0' || - !strcmp(prefix, "/")) + prefix[0] =3D=3D '\0' || + !strcmp(prefix, "/")) return; =20 - base =3D new_entry("", NULL, prefix+1); - base =3D add_dir_maybe(base); - if (base->num_entries =3D=3D 0) { - free (base); - base =3D NULL; - } else { - set_parents(base, base); - } -} - -/* FIXME: Doesn't handle DIR/.. where DIR is not in emulated dir. */ -static const char * -follow_path(const struct pathelem *cursor, const char *name) -{ - unsigned int i, namelen; - - name +=3D strspn(name, "/"); - namelen =3D strcspn(name, "/"); - - if (namelen =3D=3D 0) - return cursor->pathname; - - if (strneq(name, namelen, "..")) - return follow_path(cursor->parent, name + namelen); - - if (strneq(name, namelen, ".")) - return follow_path(cursor, name + namelen); - - for (i =3D 0; i < cursor->num_entries; i++) - if (strneq(name, namelen, cursor->entries[i]->name)) - return follow_path(cursor->entries[i], name + namelen); - - /* Not found */ - return NULL; + pref =3D strdup(prefix); } =20 /* Look for path in emulation dir, otherwise return name. */ const char *path(const char *name) { + char *newname =3D (char *) alloca(strlen(pref)+strlen(name)+1); + struct stat buf; /* Only do absolute paths: quick and dirty, but should mostly be OK. Could do relative by tracking cwd. */ - if (!base || name[0] !=3D '/') - return name; + if (!pref || name[0] !=3D '/') + return name; + + strcpy(newname,pref); + strcat(newname,name); =20 - return follow_path(base, name) ?: name; + return stat(newname,&buf) ? name : strdup(newname); } --KdquIMZPjGJQvRdI-- --ZInfyf7laFu/Kiw7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFF2aBJbWYnhzC5v6oRAvrlAKCC20AxHfeYxMYUwmBhlFzkSRx8VQCgkbwi i9dbj3u+GxJIek1XFKZijFQ= =+AbP -----END PGP SIGNATURE----- --ZInfyf7laFu/Kiw7--