Hilko Bengen
2011-May-31 22:43 UTC
[Libguestfs] [PATCH 1/4] febootstrap: Look for insmod.static, mke2fs in /sbin
--- configure.ac | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index da03c9f..7606bca 100644 --- a/configure.ac +++ b/configure.ac @@ -68,7 +68,8 @@ dnl For ArchLinux handler. AC_CHECK_PROG(PACMAN,[pacman],[pacman],[no]) dnl Required programs, libraries. -AC_PATH_PROG([INSMODSTATIC],[insmod.static],[no]) +AC_PATH_PROG([INSMODSTATIC],[insmod.static],[no], + [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) if test "x$INSMODSTATIC" = "xno" ; then AC_MSG_FAILURE([insmod.static program not found @@ -82,9 +83,10 @@ fi AC_DEFINE_UNQUOTED([INSMODSTATIC],["$INSMODSTATIC"], [Full path to the insmod.static program.]) -AC_PATH_PROG([MKE2FS],[mke2fs],[no]) +AC_PATH_PROG([MKE2FS],[mke2fs],[no], + [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) if test "x$MKE2FS" = "xno" ; then - AC_MSG_FAILURE([mke2fs program not found (is /sbin in your current path?)]) + AC_MSG_FAILURE([mke2fs program not found]) fi AC_DEFINE_UNQUOTED([MKE2FS],["$MKE2FS"], [Full path to the mke2fs program.]) -- 1.7.5.3
Hilko Bengen
2011-May-31 22:43 UTC
[Libguestfs] [PATCH 2/4] febootstrap: Cope with non-existing insmod.static
Add module loading functionality into init.c, make copying insmod.static to initrd optional. --- configure.ac | 14 +++++--------- helper/ext2initrd.c | 2 ++ helper/init.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 7606bca..382e270 100644 --- a/configure.ac +++ b/configure.ac @@ -71,17 +71,13 @@ dnl Required programs, libraries. AC_PATH_PROG([INSMODSTATIC],[insmod.static],[no], [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) if test "x$INSMODSTATIC" = "xno" ; then - AC_MSG_FAILURE([insmod.static program not found - -Is /sbin in your current path? - -Note that Debian/Ubuntu do not package this file from module-init-tools. -Sorry, please fix your distribution. In the meantime you can copy -/sbin/insmod.static from a Fedora machine. + AC_MSG_WARN([insmod.static program not found +Compiling insmod functionality directly into init program. ]) +else + AC_DEFINE_UNQUOTED([INSMODSTATIC],["$INSMODSTATIC"], + [Full path to the insmod.static program.]) fi -AC_DEFINE_UNQUOTED([INSMODSTATIC],["$INSMODSTATIC"], - [Full path to the insmod.static program.]) AC_PATH_PROG([MKE2FS],[mke2fs],[no], [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) diff --git a/helper/ext2initrd.c b/helper/ext2initrd.c index 3d765ca..c65ecf8 100644 --- a/helper/ext2initrd.c +++ b/helper/ext2initrd.c @@ -155,6 +155,7 @@ ext2_make_initrd (const char *modpath, const char *initrd) free (cmd); free_module_deps (); +#ifdef INSMODSTATIC /* Copy in insmod static binary. */ cmd = xasprintf ("cp %s %s", INSMODSTATIC, dir); if (verbose >= 2) fprintf (stderr, "%s\n", cmd); @@ -163,6 +164,7 @@ ext2_make_initrd (const char *modpath, const char *initrd) error (EXIT_FAILURE, 0, "ext2_make_initrd: copy %s failed", INSMODSTATIC); free (cmd); +#endif /* Copy in the init program, linked into this program as a data blob. */ char *init = xasprintf ("%s/init", dir); diff --git a/helper/init.c b/helper/init.c index 7b6b94e..ac71018 100644 --- a/helper/init.c +++ b/helper/init.c @@ -36,6 +36,12 @@ #include <sys/stat.h> #include <sys/wait.h> +#ifndef INSMODSTATIC +#include <fcntl.h> +#include <asm/unistd.h> +extern long init_module(void *, unsigned long, const char *); +#endif + /* Leave this enabled for now. When we get more confident in the boot * process we can turn this off or make it configurable. */ @@ -70,7 +76,9 @@ main () * executable. Just make it executable. It's easier than fixing * everyone's distro. */ +#ifdef INSMODSTATIC chmod ("/sbin/insmod.static", 0755); +#endif FILE *fp = fopen ("/modules", "r"); if (fp == NULL) { @@ -184,9 +192,38 @@ insmod (const char *filename) } if (pid == 0) { /* Child. */ +#ifdef INSMODSTATIC execl ("/insmod.static", "insmod.static", filename, NULL); perror ("insmod: execl"); _exit (EXIT_FAILURE); +#else + int fd = open (filename, O_RDONLY); + if (fd == -1) { + fprintf (stderr, "insmod: open: %s: %s\n", filename, strerror(errno)); + _exit (EXIT_FAILURE); + } + struct stat st; + if (fstat (fd, &st) == -1) { + perror ("insmod: fstat"); + _exit (EXIT_FAILURE); + } + char buf[st.st_size]; + long offset = 0; + do { + long rc = read (fd, buf + offset, st.st_size - offset); + if (rc == -1) { + perror ("insmod: read"); + _exit (EXIT_FAILURE); + } + offset += rc; + } while (offset < st.st_size); + if (init_module (buf, st.st_size, "") != 0) { + fprintf (stderr, "insmod: init_module: %s: %s\n", filename, strerror(errno)); + _exit (EXIT_FAILURE); + } + close (fd); + _exit (EXIT_SUCCESS); +#endif } /* Parent. */ -- 1.7.5.3
Hilko Bengen
2011-May-31 22:43 UTC
[Libguestfs] [PATCH 3/4] febootstrap/helper/init: Fix wait() error handling
--- helper/init.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/helper/init.c b/helper/init.c index ac71018..40f0e43 100644 --- a/helper/init.c +++ b/helper/init.c @@ -228,10 +228,11 @@ insmod (const char *filename) /* Parent. */ int status; - if (wait (&status) == -1 || - WEXITSTATUS (status) != 0) + if (wait (&status) == -1) perror ("insmod: wait"); + else if (WEXITSTATUS (status) != 0) /* but ignore the error, some will be because the device is not found */ + fprintf (stderr, "insmod %s failed\n", filename); } /* Print contents of /proc/uptime. */ -- 1.7.5.3
Hilko Bengen
2011-May-31 22:43 UTC
[Libguestfs] [PATCH 4/4] febootstrap/helper/init: Mount /proc if not already present.
--- helper/init.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/helper/init.c b/helper/init.c index 40f0e43..a7f55cd 100644 --- a/helper/init.c +++ b/helper/init.c @@ -56,6 +56,17 @@ static char line[1024]; int main () { + struct stat s; + if ( (stat ("/proc/uptime", &s) == -1) && (errno == ENOENT) ) { + mkdir("/proc", 0755); + if (verbose) + fprintf (stderr, "febootstrap: mounting /proc\n"); + if (mount ("proc", "/proc", "proc", 0, "") == -1) { + perror ("mount: /proc"); + exit (EXIT_FAILURE); + } + } + print_uptime (); fprintf (stderr, "febootstrap: ext2 mini initrd starting up\n"); -- 1.7.5.3
Richard W.M. Jones
2011-Jun-01 08:39 UTC
[Libguestfs] [PATCH 1/4] febootstrap: Look for insmod.static, mke2fs in /sbin
On Wed, Jun 01, 2011 at 12:43:09AM +0200, Hilko Bengen wrote:> --- > configure.ac | 8 +++++--- > 1 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/configure.ac b/configure.ac > index da03c9f..7606bca 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -68,7 +68,8 @@ dnl For ArchLinux handler. > AC_CHECK_PROG(PACMAN,[pacman],[pacman],[no]) > > dnl Required programs, libraries. > -AC_PATH_PROG([INSMODSTATIC],[insmod.static],[no]) > +AC_PATH_PROG([INSMODSTATIC],[insmod.static],[no], > + [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) > if test "x$INSMODSTATIC" = "xno" ; then > AC_MSG_FAILURE([insmod.static program not found > > @@ -82,9 +83,10 @@ fi > AC_DEFINE_UNQUOTED([INSMODSTATIC],["$INSMODSTATIC"], > [Full path to the insmod.static program.]) > > -AC_PATH_PROG([MKE2FS],[mke2fs],[no]) > +AC_PATH_PROG([MKE2FS],[mke2fs],[no], > + [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) > if test "x$MKE2FS" = "xno" ; then > - AC_MSG_FAILURE([mke2fs program not found (is /sbin in your current path?)]) > + AC_MSG_FAILURE([mke2fs program not found]) > fi > AC_DEFINE_UNQUOTED([MKE2FS],["$MKE2FS"], > [Full path to the mke2fs program.])ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Richard W.M. Jones
2011-Jun-01 08:41 UTC
[Libguestfs] [PATCH 2/4] febootstrap: Cope with non-existing insmod.static
On Wed, Jun 01, 2011 at 12:43:10AM +0200, Hilko Bengen wrote:> Add module loading functionality into init.c, make copying insmod.static to initrd optional. > --- > configure.ac | 14 +++++--------- > helper/ext2initrd.c | 2 ++ > helper/init.c | 37 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 44 insertions(+), 9 deletions(-) > > diff --git a/configure.ac b/configure.ac > index 7606bca..382e270 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -71,17 +71,13 @@ dnl Required programs, libraries. > AC_PATH_PROG([INSMODSTATIC],[insmod.static],[no], > [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) > if test "x$INSMODSTATIC" = "xno" ; then > - AC_MSG_FAILURE([insmod.static program not found > - > -Is /sbin in your current path? > - > -Note that Debian/Ubuntu do not package this file from module-init-tools. > -Sorry, please fix your distribution. In the meantime you can copy > -/sbin/insmod.static from a Fedora machine. > + AC_MSG_WARN([insmod.static program not found > +Compiling insmod functionality directly into init program. > ]) > +else > + AC_DEFINE_UNQUOTED([INSMODSTATIC],["$INSMODSTATIC"], > + [Full path to the insmod.static program.]) > fi > -AC_DEFINE_UNQUOTED([INSMODSTATIC],["$INSMODSTATIC"], > - [Full path to the insmod.static program.]) > > AC_PATH_PROG([MKE2FS],[mke2fs],[no], > [$PATH$PATH_SEPARATOR/sbin$PATH_SEPARATOR]) > diff --git a/helper/ext2initrd.c b/helper/ext2initrd.c > index 3d765ca..c65ecf8 100644 > --- a/helper/ext2initrd.c > +++ b/helper/ext2initrd.c > @@ -155,6 +155,7 @@ ext2_make_initrd (const char *modpath, const char *initrd) > free (cmd); > free_module_deps (); > > +#ifdef INSMODSTATIC > /* Copy in insmod static binary. */ > cmd = xasprintf ("cp %s %s", INSMODSTATIC, dir); > if (verbose >= 2) fprintf (stderr, "%s\n", cmd); > @@ -163,6 +164,7 @@ ext2_make_initrd (const char *modpath, const char *initrd) > error (EXIT_FAILURE, 0, > "ext2_make_initrd: copy %s failed", INSMODSTATIC); > free (cmd); > +#endif > > /* Copy in the init program, linked into this program as a data blob. */ > char *init = xasprintf ("%s/init", dir); > diff --git a/helper/init.c b/helper/init.c > index 7b6b94e..ac71018 100644 > --- a/helper/init.c > +++ b/helper/init.c > @@ -36,6 +36,12 @@ > #include <sys/stat.h> > #include <sys/wait.h> > > +#ifndef INSMODSTATIC > +#include <fcntl.h> > +#include <asm/unistd.h> > +extern long init_module(void *, unsigned long, const char *); > +#endif > + > /* Leave this enabled for now. When we get more confident in the boot > * process we can turn this off or make it configurable. > */ > @@ -70,7 +76,9 @@ main () > * executable. Just make it executable. It's easier than fixing > * everyone's distro. > */ > +#ifdef INSMODSTATIC > chmod ("/sbin/insmod.static", 0755); > +#endif > > FILE *fp = fopen ("/modules", "r"); > if (fp == NULL) { > @@ -184,9 +192,38 @@ insmod (const char *filename) > } > > if (pid == 0) { /* Child. */ > +#ifdef INSMODSTATIC > execl ("/insmod.static", "insmod.static", filename, NULL); > perror ("insmod: execl"); > _exit (EXIT_FAILURE); > +#else > + int fd = open (filename, O_RDONLY); > + if (fd == -1) { > + fprintf (stderr, "insmod: open: %s: %s\n", filename, strerror(errno)); > + _exit (EXIT_FAILURE); > + } > + struct stat st; > + if (fstat (fd, &st) == -1) { > + perror ("insmod: fstat"); > + _exit (EXIT_FAILURE); > + } > + char buf[st.st_size]; > + long offset = 0; > + do { > + long rc = read (fd, buf + offset, st.st_size - offset); > + if (rc == -1) { > + perror ("insmod: read"); > + _exit (EXIT_FAILURE); > + } > + offset += rc; > + } while (offset < st.st_size); > + if (init_module (buf, st.st_size, "") != 0) { > + fprintf (stderr, "insmod: init_module: %s: %s\n", filename, strerror(errno)); > + _exit (EXIT_FAILURE); > + } > + close (fd); > + _exit (EXIT_SUCCESS); > +#endif > } > > /* Parent. */ > --ACK, but once I properly test it I think I'll just make !INSMODSTATIC the default and only choice. It doesn't seem like there's any reason to call out to an external program when it's so easy to do this way. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Richard W.M. Jones
2011-Jun-01 08:44 UTC
[Libguestfs] [PATCH 4/4] febootstrap/helper/init: Mount /proc if not already present.
On Wed, Jun 01, 2011 at 12:43:12AM +0200, Hilko Bengen wrote:> --- > helper/init.c | 11 +++++++++++ > 1 files changed, 11 insertions(+), 0 deletions(-) > > diff --git a/helper/init.c b/helper/init.c > index 40f0e43..a7f55cd 100644 > --- a/helper/init.c > +++ b/helper/init.c > @@ -56,6 +56,17 @@ static char line[1024]; > int > main () > { > + struct stat s; > + if ( (stat ("/proc/uptime", &s) == -1) && (errno == ENOENT) ) { > + mkdir("/proc", 0755); > + if (verbose) > + fprintf (stderr, "febootstrap: mounting /proc\n"); > + if (mount ("proc", "/proc", "proc", 0, "") == -1) { > + perror ("mount: /proc"); > + exit (EXIT_FAILURE); > + } > + } > + > print_uptime (); > fprintf (stderr, "febootstrap: ext2 mini initrd starting up\n");ACK, but I'll adjust this patch before I apply it to make the error non-fatal. Thanks for your contributions! I'll post an updated patch series here for review before I apply anything. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Possibly Parallel Threads
- [PATCH 1/3] febootstrap/helper/init: make sure /proc is mounted into chroot.
- plug leaks in febootstrap
- [PATCH 00/16] Refactoring of configure.ac and guestfs.pod
- [PATCH] configure.ac: Add mandoc as valid formatter
- [PATCH supermin] supermin: update out-dated comments