[klibc] Re: [PATCH] kinit/kinit.c

Thayne Harbaugh tharbaugh at lnxi.com
Wed Jan 5 15:13:21 PST 2005


On Wed, 2005-01-05 at 14:58 -0700, Thayne Harbaugh wrote:
> A patch for a few more hiccups and trivialities in kinit.c:

this is an *update* of the patch in the parent email.

> 
> * The check_path() calls check for "/root" and "/old_root" - I believe
> that should be "/root" and "/root/old_root".
> 
> * chdir("/") is recommended after pivot_root()
> 
> * init_argv[0] isn't set properly to the basename pointed to by char *s
> - this fix also eliminates six lines of unecessary code and improves
> readability by using get_arg().

The get_arg() simplification causes "int i" to be unused.

--- klibc-0.194/kinit/kinit.c.orig	2005-01-05 15:40:15.468305608 -0700
+++ klibc-0.194/kinit/kinit.c	2005-01-05 15:57:48.860165704 -0700
@@ -202,7 +203,6 @@
 	int ret = 0;
 	int cmdc;
 	int fd;
-	int i;
 
 	/* Default parameters for anything init-like we execute */
 	init_argc = argc;
@@ -246,8 +250,9 @@
 	do_ipconfig(cmdc, cmdv);
 
 	check_path("/root");
-	check_path("/old_root");
 	do_mounts(cmdc, cmdv);
+	/* do_mounts cd's to /root so below tests /root/old_root */
+	check_path("old_root");
 
 #ifndef INI_DEBUG
 	if (pivot_root(".", "old_root") == -1) {
@@ -255,6 +260,8 @@
 		ret = 2;
 		goto bail;
 	}
+	/* the below chdir() is recommended after a pivot_root() */
+	chdir("/");
 
 	if (mnt_procfs == 1)
 		umount2("/proc", 0);
@@ -262,18 +269,12 @@
 	if (mnt_sysfs == 1)
 		umount2("/sys", 0);
 
-	for (i = 1; i < cmdc; i++) {
-		if (strncmp(cmdv[i], "kinit=", 6) == 0) {
-			kinit = cmdv[i] + 6;
-		}
-	}
-	
-	if (kinit) {
+	if ((kinit = get_arg(cmdc, cmdv, "kinit="))) {
 		char *s = strrchr(kinit, '/');
 		if (s) {
 			s++;
 		}
-		init_argv[0] = kinit;
+		init_argv[0] = s;
 		execv(kinit, init_argv);
 	}
 	init_argv[0] = "init";


-- 
Thayne Harbaugh
Linux Networx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.zytor.com/pipermail/klibc/attachments/20050105/90c70a97/attachment.bin


More information about the klibc mailing list