Subject: Re: [vserver] initscripts package in wheezy uninstallable
From: Andrew Ruthven <andrew.ruthven@catalyst.net.nz>
Date: Wed, 13 Mar 2013 09:13:06 +1300
Wed, 13 Mar 2013 09:13:06 +1300
On Tue, 2013-03-12 at 21:05 +0100, Art -kwaak- van Breemen wrote:
> On Tue, Mar 12, 2013 at 09:58:05AM +1300, Andrew Ruthven wrote:
> > The mount (and a bunch of other code) is protected by a test using the
> > binary ischroot from the debianutils package.
> 
> Ah, now I know again why it works for us: our personal debian
> maintainer fixed ischroot I think.

Ah ha.

I'm trying to file a bug in the BTS but it isn't responding to my email,
not sure why.  Attached is the patch to ischroot I cooked up last night.
If the one your guy came up with is better, then we should submit it to
Debian.

Cheers!

PS. My patch can be improved, the concept works for non-root as well,
but I haven't implemented that

-- 
Andrew Ruthven, Wellington, New Zealand
Catalyst IT Limited --> http://www.catalyst.net.nz
At work: andrew.ruthven@catalyst.net.nz
At home: andrew@etc.gen.nz
GPG fpr: 34CA 12A3 C6F8 B156 72C2  D0D7 D286 CE0C 0C62 B791



--- ischroot.c.orig	2013-03-12 22:00:36.235819225 +1300
+++ ischroot.c	2013-03-12 22:33:08.744874725 +1300
@@ -76,9 +76,31 @@
       return 2;
     /* Root can not read /proc/1/root, assume vserver or similar */
     return 0;
-  } else if ((st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino))
+  } else if ((st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino)) {
+    /* but look more closely for vserver, see if VxID != 0 */
+
+    FILE *status=fopen("/proc/self/status", "r");
+    size_t linesiz=0;
+    char* linebuf=0;
+    char* vxidline=0;
+    ssize_t linelen=0;
+    unsigned int vxid = 0;
+    while (linelen=getline(&linebuf, &linesiz, status)>0) {
+      vxidline = strstr(linebuf, "VxID:");
+      if (vxidline != NULL) {
+        sscanf(linebuf, "%*s %u", &vxid);
+
+        if (vxid == 0)
+          /* Host system */
+          return 1;
+        else
+          return 0;
+      }
+    }
+    free (linebuf);
+    fclose(status);
     return 1;
-  else
+  } else
     return 0;
 }
 

["application/pgp-signature" not shown]