On Sun, Jan 15, 2012 at 3:37 PM, [email protected]
<[email protected]> wrote:
> Hi guys,
> I've done more work with trying to get sh to work but to no avail. I have
> made the
> hello world test from the busybox FAQ at http://busybox.net/FAQ.html#init and
> hello world
> works.
>
> So, I decided to make an execl() program to see whether spawning /bin/sh
> directy will
> actually do anything. I put init=/bin/testit as one of the LINUX boot options.
>
> (Note: the program has been tested on UBUNTU and it does work as expected.)
> First do a
> "ls" exec() as a check
>
> testit.c
> ********************************************
> #include <stdio.h>
> #include <unistd.h>
>
> int main()
> {
> fprintf(stderr, "Launching ...\n");
> execl("/bin/ls", "/bin/ls", "-r", "-t",
> "-l", NULL);
> // execl("/bin/sh", "/bin/sh", NULL);
>
> fprintf(stderr, "Done!!!!\n");
> sleep(999999999);
> return 0;
> }
> ********************************************
> and the result is:
> ********************************************
> RAMDISK: gzip image found at block 0
>
> VFS: Mounted root (ext2 filesystem) readonly on device 1:0.
> Freeing init memory: 84K
> Launching ...
> drwxrwxr-x 3 root root 1024 Nov 30 2011 var
> drwxr-xr-x 2 root root 1024 Jan 7 2012 sys
> drwxrwxr-x 2 root root 1024 Jan 7 2012 root
> drwxrwxr-x 2 root root 1024 Jan 7 2012 proc
> drwxrwxr-x 2 root root 1024 Jan 7 2012 opt
> drwxrwxr-x 6 root root 1024 Jan 7 2012 usr
> drwxrwxrwt 3 root root 1024 Jan 7 2012 tmp
> drwxr-xr-x 3 root root 1024 Jan 7 2012 mnt
> drwxrwxr-x 4 root root 1024 Jan 7 2012 home
> drwxr-xr-x 6 root root 3072 Jan 7 2012 dev
> lrwxrwxrwx 1 root root 11 Jan 14 2012 linuxrc ->
> bin/busybox
> drwxrwxr-x 2 root root 1024 Jan 14 2012 sbin
> drwxrwxr-x 3 root root 1024 Jan 14 2012 lib
> drwxr-xr-x 5 root root 1024 Jan 14 2012 etc
> drwxrwxr-x 2 root root 2048 Jan 14 2012 bin
> drwx------ 2 root root 139264 Jan 14 2012 lost+found
>
> s3c24xx_serial_stop_rx: port=c01e8058
> Kernel panic - not syncing: Attempted to kill init!
>
> *******************************************************************
>
> Notice serial port stopping and kernel panic at the end. Why?
Because execl _replaces_ your process with exec'ed process,
it doesn't create a new one. IOW: ls will bemope
process with PID 1. As soon as PID 1 exits, kernel panics.
> Now, I try spawning /bin/sh by commenting out the /bin/ls line:
>...
> And the results are
> ****************************************************
>
> VFS: Mounted root (ext2 filesystem) readonly on device 1:0.
> Freeing init memory: 84K
> Launching ...
> s3c24xx_serial_stop_rx: port=c01e8058
> Kernel panic - not syncing: Attempted to kill init!
> s3c2410-ohci s3c2410-ohci: auto-stop root hub
>
> ******************************************************
>
> And there's no shell!
> Any pointers?
Apparently shell died at once.
Try creating a child, waiting for it and determining why it died.
Instead of "execl("/bin/sh", "/bin/sh", NULL);" line,
use
int pid = fork();
if (pid < 0) { printf("fork: %m\n"); exit(1); }
if (pid == 0) { // child
execl("/bin/sh", "/bin/sh", NULL);
// in case exec failed:
printf("exec: %m\n");
exit(1);
}
// parent: wait for child to exit, print status
printf("PID %u created\n", pid);
int status;
pid = waitpid(-1, &status, 0);
If (pid < 0) { printf("waitpid: %m\n"); exit(1); }
printf("PID %u exited\n", pid);
if (WIFSIGNALED(status))
printf("WIFSIGNALED,sig=%u\n", WTERMSIG(status));
if (WIFEXITED(status))
printf("WIFEXITED,exitcode=%u\n", WEXITSTATUS(status));
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox