[PATCH] mesg.c: make tty variable use only dynamic memory

Tito farmatito at tiscali.it
Tue Mar 22 07:02:03 UTC 2011


On Tuesday 22 March 2011 06:52:49 Denys Vlasenko wrote:
> On Tuesday 22 March 2011 00:47, Tito wrote:
> > attached as drop in replacement file a alternative version with:
> > 1) better command line options checking (catches yx error)
> > 2) size reduction
> > 	function                                             old     new   delta
> > 	fchmod                                                 -      31     +31
> > 	__fchmod                                               -      31     +31
> > 	bb_perror_nomsg_and_die                                -       9      +9
> > 	mesg_main                                            174     158     -16
> > 	chmod                                                 31       -     -31
> > 	__chmod                                               31       -     -31
> > 	------------------------------------------------------------------------------
> > 	(add/remove: 4/2 grow/shrink: 0/1 up/down: 71/-78)             Total: -7 bytes
> > 3) better error messages
> > 4) no dynamically allocated memory
> > 
> > it is just a proof of concept and little tested but seems to work.
> > If there is interest I can make a patch.
> > Hints, critics and improvements are welcome.
> 
> Thanks, I used your idea while making USE_TTY_GROUP thing configurable.
> 

Hi,
maybe you should add also : && !argv[0][1])

to

  if (!argv[0]
         || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n') && !argv[0][1])
	) {
		bb_show_usage();
	}

to catch commandline arg errors as:

debian:~/Desktop/busybox$ ./busybox mesg yxxx
debian:~/Desktop/busybox$ ./busybox mesg nxxx

that in my opinion should error out even if real
mesg on my debian box is affected by the same
bug.

BTW: why do we use stderr?

The mesg man page states:

NOTES
       Mesg assumes that its standard input is  connected  to  your  terminal.
       That  also  means  that  if  you  are logged in multiple times, you can
       get/set the mesg status of other sessions by  using  redirection.   For
       example "mesg n < /dev/pts/46".

This kind of redirection is broken for me when we use stderr.

Example 1:

Open 2 xterms:
term 1: tty 
/dev/pts/3

term 1: mesg (real)
is n

term 2:
./busybox mesg y < /dev/pts/3

term 1: mesg (real)
is n

term 1: ./busybox/busybox mesg
is n

Example 2:
term 1: tty 
/dev/pts/3

term 1: mesg (real)
is n

term 2:
mesg y < /dev/pts/3

term 1: mesg (real)
is y

term 1:
./busybox/busybox mesg
is y

????????????

Ciao,
Tito



More information about the busybox mailing list