Package: dchroot
Version: 0.11
Severity: normal
Tags: patch

Hi,

I wanted to be able to check if certain chroots were available,
without having to have another program parse the dchroot.conf
format correctly.

The following patch extends the command-line options to add
an optional argument to the '-l' option.  If specified, it
prints the path of the chroot, and returns 0, or prints an
error and returns 1 if the chroot does not exist.  As before,
it lists all chroots if no arguments are given.

BTW, I didn't update the help text.  The ugliness in the
option parsing is due to the fact that you aren't using
getopt(3) to parse the options.  I can send a separate
patch to add this if you like.


Regards,
Roger


--- dchroot-0.11.old/dchroot.c  2005-04-09 20:51:31.000000000 +0100
+++ dchroot-0.11/dchroot.c      2005-06-07 21:42:46.271391208 +0100
@@ -344,6 +344,19 @@
        }
 }
 
+static int list_chroot(struct chroot_map *chroots,
+                       const char        *chroot)
+{
+       while (chroots) {
+               if (strcmp(chroot, chroots->name) == 0) {
+                       printf("%s\n", chroots->newroot);
+                       return EXIT_SUCCESS;
+               }
+               chroots = chroots->next;
+       }
+       fprintf(stderr, "%s: chroot not found\n", chroot);
+       return EXIT_FAILURE;
+}
 
 static void usage(char *cmd)
 {
@@ -398,8 +411,18 @@
                case 'l':
                        if ((chroots = read_chroots(CHROOTS_CONF)) == NULL) {
                                printf("No chroots found.\n");
-                       } else {
-                               list_chroots(chroots);
+                       }
+                       if (index + 1 < argc) {
+                               opts.newroot = argv[index + 1];
+                               if (*opts.newroot == '-') {
+                                       opts.newroot = NULL;
+                                       list_chroots(chroots);
+                                       printf("\n");
+                               } else {
+                                       exit(list_chroot(chroots, 
opts.newroot));
+                               }
+                       } else { /* Special case in case it's the last option */
+                               list_chroots(chroots);
                                printf("\n");
                        }
                        exit(EXIT_SUCCESS);


-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (990, 'unstable')
Architecture: powerpc (ppc)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.11.8
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)

Versions of packages dchroot depends on:
ii  libc6                       2.3.2.ds1-22 GNU C Library: Shared libraries an

-- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to