loop-AES: passing command line arguments to init [patch]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I'd like to introduce a patch for loop-AES-v2.0d. The patch requires diet
libc [1] in order to pass linuxrc command line arguments (non-kernel boot
parameters, e.g. runlevel selection) to init. It doesn't require diet libc
to be present, everything should work as before if it isn't. The resulting
binary (linked against diet libc) is nearly 1k smaller than the one linked
with -nostartfiles.

I'd like to see this kind of functionality in loop-AES, but I'm also
willing to maintain it as a patch if it's not acceptable. There are
possibilities for future enhancements as checking for linuxrc-specific
command line arguments, e.g. to select EXTERNALGPGDEV, GPGKEYFILE, and
INITIALDELAY at runtime...

Kind regards,

Martin

[1] http://www.fefe.de/dietlibc/
diff -urN loop-AES-v2.0d.orig/build-initrd.sh loop-AES-v2.0d/build-initrd.sh
--- loop-AES-v2.0d.orig/build-initrd.sh	2003-12-26 18:25:58.000000000 +0100
+++ loop-AES-v2.0d/build-initrd.sh	2003-12-27 18:26:38.000000000 +0100
@@ -170,6 +170,11 @@
 # If enabled, rootsetup program (+libs) _must_ be manually copied to /boot.
 USEROOTSETUP=0
 
+# 1 = use diet libc to pass linuxrc arguments (e.g. runlevel) to init
+# 0 = if you don't have diet libc
+# The diet libc can be found at http://www.fefe.de/dietlibc/.
+USEDIETLIBC=0
+
 # 1 = load extra module, 0 = don't load
 # If this is enabled, module must be manually copied to
 # /boot/modules-KERNELRELEASE/ directory under name like foomatic.o
@@ -267,8 +272,11 @@
 # define HaltKernel() reboot(0xfee1dead, 672274793, 0xCDEF0123)
 #endif
 
-static char * argv_init[] = { "init", 0, };
-static char * envp_init[] = { "HOME=/", "TERM=linux", 0, };
+#define MAX_INIT_ARGS 8 /* from linux/init/main.c */
+#define MAX_INIT_ENVS 8
+
+static char * argv_init[MAX_INIT_ARGS+2] = { "init", 0, };
+static char * envp_init[MAX_INIT_ENVS+1] = { "HOME=/", "TERM=linux", 0, };
 
 void strCat(char *d, char *s)
 {
@@ -328,8 +336,19 @@
     }
 }
 
-void runInit()
+void runInit(char *argv_linuxrc[])
 {
+#if ${USEDIETLIBC}
+    int i; char **p;
+
+    for (p = argv_init, i = 0; *p != 0; p++, i++);
+    for (p = &argv_linuxrc[1]; *p != 0 && i <= MAX_INIT_ARGS;)
+        argv_init[i++] = *p++;
+    argv_init[i] = 0;
+    if (*p != 0)
+        wrStr("linuxrc: too many arguments, please contact the author\n");
+    /* Did they increase MAX_INIT_ARGS in linux/init/main.c? */
+#endif
     execve("/sbin/init", argv_init, envp_init);
     execve("/etc/init", argv_init, envp_init);
     execve("/bin/init", argv_init, envp_init);
@@ -337,8 +356,14 @@
     doHalt();
 }
 
+#if ${USEDIETLIBC}
+int main(int argc, char *argv[])
+{
+#else
 void _start()
 {
+    char **argv = NULL;
+#endif
     int x = 0;
     struct utsname un;
     char buf[300];
@@ -353,7 +378,7 @@
     if(getpid() == 1) {
         /* change_root was configured, but kernel    */
         /* has wandered off to pivot_root code path! */
-        runInit();
+        runInit(argv);
     }
 #endif
 
@@ -506,7 +531,7 @@
         goto fail1;
     }
     wrStr("Pivoting to encrypted root completed successfully\n");
-    runInit();
+    runInit(argv);
 #else
     if(mount("none", "/proc", "proc", MS_MGC_VAL, 0)) {
         wrStr("Mounting /proc failed\n");
@@ -536,7 +561,11 @@
 }
 EOF
 
-gcc -Wall -O2 -s -static -nostartfiles -pipe tmp-c-$$.c -o tmp-c-$$
+if [ ${USEDIETLIBC} == 1 ]; then
+    diet gcc -Wall -O2 -s -static -pipe tmp-c-$$.c -o tmp-c-$$
+else
+    gcc -Wall -O2 -s -static -nostartfiles -pipe tmp-c-$$.c -o tmp-c-$$
+fi
 rm -f tmp-c-$$.[co]
 
 x=`cat tmp-c-$$ | wc -c`

[Index of Archives]     [Kernel]     [Linux Crypto]     [Gnu Crypto]     [Gnu Classpath]     [Netfilter]     [Bugtraq]
  Powered by Linux