lear@NET.BIO.NET (Eliot Lear) (08/05/89)
Written for SunOS 4.0. Should run under most 4.2 and 4.3 systems.
Probably not under System V. Run this when you are hungary and
looking for fellow hackers. Use -S in case of emergancy!
static char *Id="$Header: /bionet/bio0/staff/lear/src/RCS/foodp.c,v 1.2 89/08/05 00:48:46 lear Exp $";
/* Foodp! A program made out of necessity!
*
* Usage: foodp [ -sSf ]
* to turn on, use no arguments, to turn off use the -s, which
* stands for SATIATED. Use -S for starving, and -f for full
* (same as -s).
*
*/
/*
* $Log: foodp.c,v $
* Revision 1.2 89/08/05 00:48:46 lear
* added -f and -S options.
*
* Revision 1.1 89/08/04 10:29:17 lear
* Initial revision
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
#include <fcntl.h>
#include <utmp.h>
#include <lastlog.h>
main(argc,argv)
int argc;
char *argv[];
{
struct utmp u;
char *myname;
int c;
int ufd;
int k=0;
int sflag=0;
int Sflag=0;
while ((c = getopt(argc,argv,"sSf")) != -1)
if ( c == 's' || c == 'f' )
sflag++;
else
{
if ( c == 'S' )
Sflag++;
else
{
fprintf(stderr,"Usage: %s [ -s ]\n",argv[0]);
exit(1);
}
}
if ( (myname=getlogin()) == NULL )
{
fprintf(stderr,"No name found in utmp file.\n");
exit(0);
}
if ( (ufd= open("/etc/utmp",O_RDWR)) == -1 )
{
perror("open");
exit(1);
}
while ( read(ufd,&u,sizeof(struct utmp)) == sizeof(struct utmp) )
{
if ( ! strncmp(u.ut_name,myname,8))
{
lseek(ufd,-sizeof(struct utmp),L_INCR);
if ( sflag )
strcpy(u.ut_host,"Not hungry");
else
{
if ( ! Sflag )
strcpy(u.ut_host,"FOODP!");
else
strcpy(u.ut_host,"STARVING!");
}
write(ufd,&u,sizeof(struct utmp));
}
}
close(ufd);
}