Package: dchroot
Severity: wishlist

Hi!  I wrote a patch to dchroot to solve one of the annoyances that I
run into often.  On a biarch machine (In my case usually amd64 and
i386), I have to remember to run "linux32" to set the personality type
when doing anything that looks at the output from uname -m.  With this
patch, dchroot.conf grows a third parameter which lets someone set the
personality type.



diff -Nru /tmp/P1rFurKwQt/dchroot-0.11/dchroot.c /tmp/Y1rO0wg5Pi/dchroot-0.11ubuntu1/dchroot.c
--- /tmp/P1rFurKwQt/dchroot-0.11/dchroot.c	2005-04-09 15:51:31.000000000 -0400
+++ /tmp/Y1rO0wg5Pi/dchroot-0.11ubuntu1/dchroot.c	2005-12-31 19:48:01.000000000 -0500
@@ -28,6 +28,9 @@
 #include <string.h>
 #include <stdarg.h>
 #include <errno.h>
+#ifdef __linux__
+# include <sys/personality.h>
+#endif /* __linux__ */
 
 #define PROGNAME "dchroot"
 #define CHROOTS_CONF "/etc/dchroot.conf"
@@ -43,6 +46,7 @@
 	char name[128];
 	char newroot[PATH_MAX];
 	struct chroot_map *next;
+	int personality;
 };
 
 static struct dchroot_opts {
@@ -89,7 +93,8 @@
 /*
    Read chroot config file.  Lines starting with '#' and lines containing only 
    whilespace are ignored.  Valid input lines contain a name and a path 
-   separated by whitespace.  
+   separated by whitespace.  Optionally, there can be a third parameter
+   specifying the linux32 personality.
    
    On success return a malloc'd linked list of chroots.
    On error return NULL.
@@ -97,9 +102,10 @@
 static struct chroot_map *read_chroots(char *conffile)
 {
 	FILE *fp;
-	char buffer[BUFSIZ], *name, *newroot;
+	char buffer[BUFSIZ], *name, *newroot, *personality_name;
 	struct stat statbuf;
 	int line = 0;
+	int personality;
 	struct chroot_map *new, *chroots = NULL;
 
 	if ((fp = fopen(conffile, "r")) == NULL) {
@@ -119,6 +125,19 @@
 		else
 			continue;
 
+		if ((personality_name = strtok(NULL, WHITE_CHARS))) {
+			if (!strcmp(personality_name, "linux32")) {
+				personality = PER_LINUX32;
+			} else {
+				fprintf(stderr,
+					PROGNAME ": Invalid personality, %s.\n",
+					personality_name);
+				goto failure;
+			}
+		} else {
+			personality = PER_LINUX;
+		}
+
 		if (!newroot || strtok(NULL, WHITE_CHARS)
 		    || stat(newroot, &statbuf)
 		    || !S_ISDIR(statbuf.st_mode)) {
@@ -159,6 +178,8 @@
 				       conffile, line);
 			goto failure;
 		}
+
+		new->personality = personality;
 	}
 
 	fclose(fp);
@@ -199,6 +220,15 @@
 		return -1;
 	} else if (pid == 0) {
 
+#ifdef __linux__
+		if (chroot_to->personality == PER_LINUX32) {
+			if (personality(PER_LINUX32) < 0) {
+				fprintf(stderr, PROGNAME "Could not set personality to PER_LINUX32: %s\n", strerror(errno));
+				exit(EXIT_FAILURE);
+			}
+		}
+#endif /* __linux__ */
+		
 		if (!argv) {
 			/* Will execute a shell in the new chroot. */
 
diff -Nru /tmp/P1rFurKwQt/dchroot-0.11/debian/changelog /tmp/Y1rO0wg5Pi/dchroot-0.11ubuntu1/debian/changelog
--- /tmp/P1rFurKwQt/dchroot-0.11/debian/changelog	2005-04-09 15:51:00.000000000 -0400
+++ /tmp/Y1rO0wg5Pi/dchroot-0.11ubuntu1/debian/changelog	2005-12-31 19:07:30.000000000 -0500
@@ -1,3 +1,9 @@
+dchroot (0.11ubuntu1) unstable; urgency=low
+
+  * Add option to force personality type to PER_LINUX32.
+
+ -- Jeff Bailey <[EMAIL PROTECTED]>  Sat, 31 Dec 2005 19:07:02 -0500
+
 dchroot (0.11) unstable; urgency=low
 
   * Suggest debootstrap (closes: #274913)

Attachment: signature.asc
Description: Ceci est une partie de message numériquement signée

Reply via email to