purpose of "open_a_console()" in get_console.c??

Robert P. J. Day rpjday at mindspring.com
Sun Mar 26 13:36:25 PST 2006


On Sun, 26 Mar 2006, Rob Landley wrote:

> On Sunday 26 March 2006 6:43 am, Robert P. J. Day wrote:
> >   from libbb/get_concole.c:
> >
> > static int open_a_console(const char *fnam)
> > {
> >     int fd;
> >
> >     fd = open(fnam, O_RDWR);           /* first, try read/write */
> >
> >     if (fd < 0 && errno == EACCES)     /* else, try readonly */
> >         fd = open(fnam, O_RDONLY);
> >
> >     if (fd < 0 && errno == EACCES)     /* else, try writeonly */
> >         fd = open(fnam, O_WRONLY);
> >
> >     return fd;
> > }
> >
> >
> >
> >   i don't see anything about that routine that is console-specific --
> > it just appears to try to open a file three different ways.  is there
> > perhaps a more general "open_file" BB routine somewhere that could be
> > used just as well so that this one could be deleted?
>
> That's kinda funky behavior.  The open is called with _no_ idea
> what's going to be made of the file, and the last two fallback
> positions are exclusive.  (Either you can only read from it, or you
> can only write to it.)
>
> Attaching a console to a tty is just about the only case where this
> behavior makes sense to me.  Can you think of another?

not offhand.  i wasn't aware that there really is no other practical
application of this exact recipe.  that's fine, then.

rday


More information about the busybox mailing list