From 1103284645f1c7505d7bce42ab878885602e8da3 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 10 Nov 2011 11:52:48 -0500 Subject: [PATCH] parallel-debian: Support being run as non-root --- parallel-debian/.gitignore | 1 - parallel-debian/Makefile | 6 +- parallel-debian/chroot_break.c | 117 ------------------ parallel-debian/debian-setup.sh | 29 ++--- ...eos-make-image.sh => gnomeos-make-base.sh} | 15 +-- 5 files changed, 15 insertions(+), 153 deletions(-) delete mode 100644 parallel-debian/chroot_break.c rename parallel-debian/{gnomeos-make-image.sh => gnomeos-make-base.sh} (95%) diff --git a/parallel-debian/.gitignore b/parallel-debian/.gitignore index 95bdbbed..d42173ae 100644 --- a/parallel-debian/.gitignore +++ b/parallel-debian/.gitignore @@ -1,2 +1 @@ -chroot_break ostree_switch_root diff --git a/parallel-debian/Makefile b/parallel-debian/Makefile index 97ec6c00..a00e6110 100644 --- a/parallel-debian/Makefile +++ b/parallel-debian/Makefile @@ -1,8 +1,4 @@ - -all: ostree_switch_root chroot_break +all: ostree_switch_root ostree_switch_root: ostree_switch_root.c Makefile gcc -Wall -o $@ $< - -chroot_break: chroot_break.c Makefile - gcc -Wall -o $@ $< diff --git a/parallel-debian/chroot_break.c b/parallel-debian/chroot_break.c deleted file mode 100644 index 2a34716b..00000000 --- a/parallel-debian/chroot_break.c +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * chroot_break: Exit out of active chroot(2) if any. Requires root privileges. - * - * Copyright (C) 2011 Colin Walters - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include - -int -usage (const char *self, - int ecode) -{ - fprintf (stderr, "usage: %s PROGRAM [ARGS...]\n", self); - - return ecode; -} - -int -main (int argc, - char **argv) -{ - const char *template = "/tmp/chroot.XXXXXX"; - char *tmpdir; - DIR *tmp; - struct stat current; - struct stat up; - - if (argc < 2) - return usage (argv[0], 1); - - tmpdir = strdup (template); - if (!mkdtemp (tmpdir)) - { - perror ("mkdtemp"); - return 1; - } - - tmp = opendir ("/tmp"); - if (!tmp) - { - perror ("opening /tmp"); - return 1; - } - - if (chroot (tmpdir) < 0) - { - perror ("chroot into tempdir"); - return 1; - } - - do - { - if (stat (".", ¤t) < 0) - { - perror ("stat"); - return 1; - } - if (stat ("..", &up) < 0) - { - perror ("stat"); - return 1; - } - if (current.st_dev == up.st_dev - && current.st_ino == up.st_ino) - break; - if (chdir ("..") < 0) - { - perror ("chdir"); - return 1; - } - } while (1); - - if (chroot (".") < 0) - { - perror ("chroot into real root"); - return 1; - } - - if (unlinkat (dirfd (tmp), strrchr (tmpdir, '/') + 1, AT_REMOVEDIR) < 0) - { - perror ("cleaning up tmpdir"); - return 1; - } - - closedir (tmp); - - if (execv (argv[1], &argv[1]) < 0) - { - perror ("Running child process"); - return 1; - } - /* Should not be reached */ - return 1; -} diff --git a/parallel-debian/debian-setup.sh b/parallel-debian/debian-setup.sh index c5aabb73..732a3837 100755 --- a/parallel-debian/debian-setup.sh +++ b/parallel-debian/debian-setup.sh @@ -5,31 +5,31 @@ set -e set -x -echo gnomeos > /etc/hostname +echo gnomeos >./etc/hostname -cat > /etc/default/locale <./etc/default/locale </etc/pam.d/common-account <./etc/pam.d/common-account </etc/pam.d/common-auth <./etc/pam.d/common-auth </etc/pam.d/common-password <./etc/pam.d/common-password </etc/pam.d/common-session <./etc/pam.d/common-session <