On Wed, Oct 20, 2010 at 01:55:13 +0200, Denys Vlasenko wrote:
> On Wednesday 20 October 2010 01:49, Denys Vlasenko wrote:
> > On Wednesday 20 October 2010 01:23, Alexander Shishkin wrote:
> > > On Tue, Oct 19, 2010 at 11:18:43 +0200, Denys Vlasenko wrote:
> > > > On Tuesday 19 October 2010 22:33, Alexander Shishkin wrote:
> > > > > [Sorry, the previous mail seems to have been eaten by the smarthost,
> > > > > apologies if it comes twice.]
> > > > > 
> > > > > function                                             old     new   
> > > > > delta
> > > > > add_shell_main                                         -     459    
> > > > > +459
> > > > > .rodata                                            50375   50495    
> > > > > +120
> > > > > chomp                                                  -      24     
> > > > > +24
> > > > > applet_names                                         920     943     
> > > > > +23
> > > > > packed_usage                                        1640    1661     
> > > > > +21
> > > > > applet_main                                         1232    1248     
> > > > > +16
> > > > > applet_nameofs                                       308     312      
> > > > > +4
> > > > > ------------------------------------------------------------------------------
> > > > > (add/remove: 4/0 grow/shrink: 5/0 up/down: 667/0)             Total: 
> > > > > 667 bytes
> > > > > 
> > > > > Signed-off-by: Alexander Shishkin <[email protected]>
> > > > 
> > > > This seems to be trivially scriptable in sh.
> > > > 
> > > > Why do you need it? (I ask because sometimes there _is_ a valid,
> > > > but unknown to me, reason to have this or that tool in bbox).
> > > 
> > > Well, I like my busybox to be a real swiss army knife, so that I can
> > > grab it, compile it and put a single binary to where I need it and
> > > have all the tools that I need in that binary. (as opposed to dragging
> > > scripts and their dependencies around) And sometimes the only thing
> > > that you can rely on a system is a statically linked busybox.
> > > 
> > > Also, I would like to see busybox as a potential replacement for the
> > > base GNU tools in a desktop system one day. Adding applets that you
> > > don't necessarily have to compile in, but that get busybox closer to
> > > being all-in-one drop-in replacement is something worth doing, imo.
> > > 
> > > Other than that, I try to avoid shell scripting if I can help it and
> > > my script-foo is not good enough to produce a tolerably good version
> > > of add/remove-shell in 667 bytes. A C implementation is something
> > > that I'm willing to work on, though.
> > 
> > Ah, so there _are_ such tools (add-shell and remove-shell)
> > in standard Linux repertoire! I didn't know it.
> > 
> > Do you provide compatible behavior?
> > 
> > Maybe it makes sense to do
> > 
> >     default y if DESKTOP
> > 
> > (IIRC this syntax is supported in Config files)
> > to placate "true" embedded guys who undoubtedly won't like proliferation
> > of "stupid applets which should be shell scripts"?
> > 
> 
> Randonly googled up page, http://man.he.net/man8/add-shell, says:
> 
>        add-shell  copy /etc/shells to /etc/shells.tmp, add the given shells to
>        this file if they are not already present, and copy this temporary file
>        back to /etc/shells.
> 
> This seems to be much saner way to update the file atomically than
> messing with locking stuff:
> 
> +               lock.l_type = F_WRLCK;
> +               lock.l_whence = SEEK_SET;
> +               lock.l_start = 0;
> +               lock.l_len = 0;
> +               if (fcntl(fileno(orig), F_SETLK, &lock) < 0)
> +                       bb_perror_msg("warning: can't lock '%s'", orig_fn);
> +               lock.l_type = F_UNLCK;

What if another process tries to add another shell at the same time? Won't
one of them be lost without locking?

> 
> 
> Don't forget to use xmalloc_follow_symlinks, to care for people
> whose /etc/shells is a symlink. Basically:
> 
>         filename = xmalloc_follow_symlinks("/etc/shells");

Good point, thanks.

>         if (filename == NULL)
>                 BOOM;
>         fnamesfx = xasprintf("%s.tmp", filename);
>         fd = xopen(fnamesfx, O_WRONLY | O_CREAT | O_EXCL);
>         ...
>         rename(fnamesfx, filename);

Regards,
--
Alex
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to