mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Cc: toybox@lists.landley.net
Subject: Re: toybox: Rough edges in pending
Date: Tue, 19 Mar 2013 12:09:39 +0100	[thread overview]
Message-ID: <20130319110939.GJ19010@port70.net> (raw)
In-Reply-To: <20130319094225.GI19010@port70.net>

* Szabolcs Nagy <nsz@port70.net> [2013-03-19 10:42:25 +0100]:
> * Isaac Dunham <idunham@lavabit.com> [2013-03-18 23:50:43 -0700]:
> > execve("./toybox-musl", ["./toybox-musl", "sh", "-c", "ls"], [/* 22 vars */]) = 0
> ...
> > ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B9600 opost isig icanon echo ...}) = 0
> > vfork(Config.in README    kconfig scripts     toybox_unstripped toys.h 
> > LICENSE   configure lib     toybox      toynet.h          www    
> > Makefile  generated main.c  toybox-musl toys              
> > )                                 = 27832
> > --- SIGCHLD (Child exited) @ 0 (0) ---
> > wait4(27832, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 27832
> > pause(^C <unfinished ...>
> 
> exit tries to flush some stdio buffers but it is locked
> 
> maybe an issue around the way vfork is used by the shell


this is what toybox sh does:

    cmd->pid = vfork();
    if (!cmd->pid) xexec(cmd->argv);
    else waitpid(cmd->pid, &status, 0);


it's an incorrect use of vfork

either exec or _exit should be called after vfork but
xexec calls toy_exec that runs ls in-place then calls
exit (so the exit lock gets locked hence the
deadlock when the parent tries to exit)


void xexec(char **argv)
{
  toy_exec(argv);
  execvp(argv[0], argv);

  perror_exit("exec %s", argv[0]);
}

void toy_exec(char *argv[])
{
  struct toy_list *which;

  which = toy_find(argv[0]);
  if (!which) return;
  toy_init(which, argv);
  toys.which->toy_main();
  if (fflush(NULL) || ferror(stdout)) perror_exit("write");
  exit(toys.exitval);
}



  reply	other threads:[~2013-03-19 11:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-19  6:50 Isaac Dunham
2013-03-19  9:42 ` Szabolcs Nagy
2013-03-19 11:09   ` Szabolcs Nagy [this message]
     [not found]     ` <20130319110939.GJ19010-4P1ElwuDYu6sTnJN9+BGXg@public.gmane.org>
2013-03-19 17:33       ` [musl] " Rob Landley
2013-03-19 17:20 ` [Toybox] " Rob Landley
2013-03-19 19:32   ` [musl] " Isaac Dunham
2013-03-20  6:22     ` [Toybox] " Rob Landley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130319110939.GJ19010@port70.net \
    --to=nsz@port70.net \
    --cc=musl@lists.openwall.com \
    --cc=toybox@lists.landley.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).