On Mon, Oct 20, 2014 at 01:17:44PM +1100, scsijon wrote:
> I was wondering if toybox 'could / would be able to' have an auto tool built
> into it. I'm not a coder, so can't do it, but....
> 
> Along the line of:
> --
> If toybox had the command 'siliswap' built into it, but it's inbuilt
> siliswap was a subset of the full 'siliswap' command and it's complete set
> of switches, as for most people and programs it doesn't need the others.
> 
> If at a later stage, the user needs to install the full 'siliswap' package
> because they need to use switches that are not built into toybox's
> 'siliswap' then toybox's 'siliswap' knows to pass the request onto the full
> siliswap instead of dealing with it itself.
> --
> Not sure if it could be added without a shell file though and i'd prefer not
> to add to the default set. ?or could these be created automatically when
> toybox is first run, against all inbuilt packages, or manually with a toybox
> -cfg command).
> 
> And of course, toybox doesn't have or needs siliswap (it's a very old IBM
> Mainframe silo interface command), i'm not sure it is even used anymore.


1. Rob keeps talking about simplicity...this doesn't sound very simple.
It also doesn't sound small--which defeats the point of implementing a
subset.

2. Depending on a special file seems completely wrong.

3. My understanding is that the simpler version of this would basically
be "search $PATH for a command that doesn't point to toybox if we don't
handle all the options" (called from get_optflags()?).
This means that for each element in $PATH, we look for an executable file
named like $0, check for hard and soft links to the running binary,
and soft links to a "toybox..." binary.
Which could be done, theoretically...
at the cost of at least two struct stats, a buffer for storing link names,
and probably less than 1k of code.

So here's partial implementation of the theory (C-ish code, assuming
some changes to toybox; not robust):

/* toybox.st is a struct stat initialized with roughly:
 *  fstat(open("/proc/self/exe"), &toybox.st);
 */

/* callback for loopfiles-like function that instead loops through PATH
 * and calls this with a dirfd for each path entry
 */
void execnotself(int dfd, char *name)
{
  struct stat st;
  //only needed if we check for links to any "toybox" binary
  char linkpath[PATH_MAX + 1], *base;
  
  // check for hard links, symlinks to argv[0]
  if (fstatat(dfd, toys.which, &st, 0)) return;
  if (st.st_dev == toybox.st && st.st_ino == toybox.st_ino)
    return;

  // optional: check for symlinks to other toybox binaries
  if (fstatat(dfd, toys.which, &st, AT_SYMLINK_NOFOLLOW)) return;
  bzero(linkpath, sizeof(linkpath));
  if (S_ISLNK(st.st_mode)) 
    readlinkat(dfd, toys.which, linkpath, sizeof(linkpath)-1);
  if (*linkpath) {
    base = basename(linkpath);
    if (!strncmp("toybox", base, 6)) return;
  }
  //EWOULDBENICE: there's no execvat(), but you get the drift
  execvat(dfd, toys.which, argv);
}

//call execnotself() if we hit an error in get_optflags().
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to