[PATCH] users: new applet

Tito farmatito at tiscali.it
Tue Aug 9 06:14:33 UTC 2011


On Tuesday 09 August 2011 04:38:24 you wrote:
> On Wednesday 27 July 2011 17:12, Tito wrote:
> > On Wednesday 27 July 2011 16:43:34 Tito wrote:
> > > On Wednesday 27 July 2011 13:10:49 gotrunks at gmail.com wrote:
> > > > On Wed, Jul 27, 2011 at 10:29 AM, Tito <farmatito at tiscali.it> wrote:
> > > > > On Wednesday 27 July 2011 00:33:37 gotrunks at gmail.com wrote:
> > > > >> Hi,
> > > > >>
> > > > >> patch attached.
> > > > >>
> > > > >> Regards,
> > > > >>
> > > > >
> > > > > Hi,
> > > > > printf(ut->ut_user);  maybe adding a format string here would be a good thing.
> > > > 
> > > > Ok.
> > > > 
> > > > > BTW.: this code looks very similar to what the who applet does, couldn't
> > > > > they be merged?
> > > > >
> > > > 
> > > > That was the first thing I tried, but I don't know how to do it
> > > > without unsightly impact the who applet.
> > > > 
> > > > > Ciao,
> > > > > Tito
> > > > > _______________________________________________
> > > > > busybox mailing list
> > > > > busybox at busybox.net
> > > > > http://lists.busybox.net/mailman/listinfo/busybox
> > > > >
> > > > 
> > > > Regards,
> > > > 
> > > 
> > > Hi,
> > > attached an example patch on how who and users could be merged.
> > > Denys will love my obfuscated code ;-)
> > > 
> > > Ciao,
> > > Tito
> > > 
> > > --- coreutils/who.c.orig	2011-06-22 14:29:58.000000000 +0200
> > > +++ coreutils/who.c	2011-07-27 16:32:09.000000000 +0200
> > > @@ -18,6 +18,31 @@
> > >   */
> > >  /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'.  */
> > >  
> > > +//config:config WHO
> > > +//config:      bool "who"
> > > +//config:      default y
> > > +//config:      depends on FEATURE_UTMP
> > > +//config:      help
> > > +//config:        who is used to show who is logged on.
> > > +
> > > +//config:config USERS
> > > +//config:      bool "users"
> > > +//config:      default y
> > > +//config:      depends on FEATURE_UTMP
> > > +//config:      help
> > > +//config:        Print users currently logged on.
> > > +
> > > +//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users))
> > > +//applet:IF_WHO(  APPLET(  who, BB_DIR_USR_BIN, BB_SUID_DROP))
> > > +
> > > +//kbuild:lib-$(CONFIG_USERS) += who.o
> > > +//kbuild:lib-$(CONFIG_WHO) += who.o
> > > +
> > > +//usage:#define users_trivial_usage
> > > +//usage:       ""
> > > +//usage:#define users_full_usage "\n\n"
> > > +//usage:       "Print the users currently logged on"
> > > +
> > >  //usage:#define who_trivial_usage
> > >  //usage:       "[-a]"
> > >  //usage:#define who_full_usage "\n\n"
> > > @@ -49,9 +74,10 @@
> > >  {
> > >  	struct utmp *ut;
> > >  	unsigned opt;
> > > +	int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
> > >  
> > >  	opt_complementary = "=0";
> > > -	opt = getopt32(argv, "aH");
> > > +	opt = getopt32(argv, do_users ? "" : "aH");
> > >  	if (opt & 2) // -H
> > >  		printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
> > >  
> > > @@ -60,6 +86,7 @@
> > >  		if (ut->ut_user[0]
> > >  		 && ((opt & 1) || ut->ut_type == USER_PROCESS)
> > >  		) {
> > > +		if (!do_users) {
> > >  			char str6[6];
> > >  			char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
> > >  			struct stat st;
> > > @@ -88,8 +115,15 @@
> > >  					ctime(&seconds) + 4,
> > >  					(int)sizeof(ut->ut_host), ut->ut_host
> > >  			);
> > > +			} else {
> > > +				/* use opt as flag for first time */
> > > +				printf(" %s" + !opt, ut->ut_user);
> > > +				opt = 1;
> > 				/* we don't want to trigger (opt & 1) */
> > 				opt = 2;
> > > +			}
> > >  		}
> > >  	}
> > > +	if (do_users)
> > > +		bb_putchar('\n');
> > >  	if (ENABLE_FEATURE_CLEAN_UP)
> > >  		endutent();
> > >  	return EXIT_SUCCESS;
> > > 
> > 
> > Hi,
> > minor fix on previous patch. We probably don't want set opt = 1, so let us use 2 instead.
> 
> Applied, thanks!
> 
Hi,
maybe we need also to:
--- coreutils/Kbuild.src.original       2011-06-20 22:48:27.000000000 +0200
+++ coreutils/Kbuild.src        2011-07-27 16:35:42.000000000 +0200
@@ -83,6 +82,5 @@
 lib-$(CONFIG_UUDECODE)  += uudecode.o
 lib-$(CONFIG_UUENCODE)  += uuencode.o
 lib-$(CONFIG_WC)        += wc.o
-lib-$(CONFIG_WHO)       += who.o
 lib-$(CONFIG_WHOAMI)    += whoami.o
 lib-$(CONFIG_YES)       += yes.o



Ciao,
Tito


More information about the busybox mailing list