[Toybox] Question regarding multiple NEW_TOY
Daniel Walter
d.walter at 0x90.at
Thu Feb 23 23:49:27 PST 2012
On Thu, Feb 23, 2012 at 09:48:19AM -0600, Rob Landley wrote:
> On 02/22/2012 05:45 AM, Daniel Walter wrote:
> > hi,
> >
> > I've seen multiple NEWTOY in toysh.c and would need the same for id.c
> > to add groups and whoami, but I can't figure out how to use them.
> > make will always tell me that whoami.c and groups.c are missing.
>
> If you want to alias them to the same main() function, this is what
> OLDTOY is for. It lets you specify a second command implemented by the
> same file, calling an existing main() function.
>
> Look at toys/netcat.c for an example, aliasing "nc" to "netcat". (Since
> it generates a second entry in the command dispatch table, it needs its
> own optargs string. I'm hoping the compiler is smart enough to merge
> identical string constants...)
>
> > used code snip
> >
> > USE_ID(NEWTOY(id, "nGgru", TOYFLAG_BIN))
> > USE_ID(NEWTOY(whoami, NULL, TOYFLAG_NOFORK))
> > USE_ID(NEWTOY(groups, NULL, TOYFLAG_NOFORK))
> >
> > config GROUPS
> > bool "groups"
> > default y
> > depends on ID
> > ....
>
> It's actually the GROUPS config symbol causing you a problem. here's a
> badly wordwrapped cut and paste from scripts/make.sh:
>
> ----------------
>
> # Extract a list of toys/*.c files to compile from the data in ".config"
> with
> # sed, sort, and tr:
>
> # 1) Grab the XXX part of all CONFIG_XXX entries, removing everything
> after the
> # second underline
> # 2) Sort the list, keeping only one of each entry.
> # 3) Convert to lower case.
> # 4) Remove toybox itself from the list (as that indicates global symbols).
> # 5) Add "toys/" prefix and ".c" suffix.
>
> TOYFILES=$(cat .config | sed -nre 's/^CONFIG_(.*)=y/\1/;t
> skip;b;:skip;s/_.*//;p' | sort -u | tr A-Z a-z | grep -v '^toybox$' |
> sed 's@\(.*\)@toys/\1.c@' )
>
> --------------------
>
> Basically it's taking all the CONFIG_BLAH (and CONFIG_BLAH_*) symbols,
> chopping out the "BLAH" part, smashing it to lower case, and looking for
> a toys/*.c file with that name. (This is going to cause a problem for
> switch_root, pivot_root, nbd-client, and so on. I need to fix it up a
> bit...)
>
> What you need to do is have the config symbols be CONFIG_ID_GROUPS and
> CONFIG_ID_WHOAMI, and make them depend on CONFIG_ID. Or just _not_ give
> them their own symbols, since they're all in the same .c file and you're
> making it hard to build one without the others...
thanks that fixed it.
>
> That said, _why_ do you want to do multiple commands with separate
> main() functions in the same file? Is there an advantage to it?
I need it for groups and whoami which both are basically just
the same as id (groups is id -Gn and whoami id -un) so I do not
want to duplicate code which will not be used by other tools.
daniel
1330069767.0
More information about the Toybox
mailing list