home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************\
- ** **
- ** Program name: sysinfo.c (System Info) **
- ** Programmer: Lenny Tropiano UUCP: ...icus!lenny **
- ** Organization: ICUS Computer Group (c)1988 **
- ** Date: January 23, 1988 **
- ** **
- **************************************************************************
- ** **
- ** Credits: The idea of displaying the file system information **
- ** came from Scott Hazen Mueller's newmgr, the replace- **
- ** ment to the smgr. **
- ** **
- **************************************************************************
- ** **
- ** Program use: Program is run as a info process from your .profile **
- ** This program the file system and displays the **
- ** pertinent information on the bottom of the screen **
- ** where the software labels would normally be displayed. **
- ** The program also displays the uptime. **
- ** **
- **************************************************************************
- ** Permission is granted to distribute this program by any means as **
- ** long as credit is given for my work. I would also like to see **
- ** any modifications or enhancements to this program. **
- \************************************************************************/
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <signal.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/window.h>
- #include <sys/filsys.h>
- #include <utmp.h>
-
- #define MINUTE 60L
- #define HOUR (60L * 60L)
- #define DAY (24L * 60L * 60L)
- #define SLEEP 15 /* Sleep time (interval between)*/
- #define NICE 5 /* Niceness value */
-
- #define LINE_1 "%-40.40s up %2d day%1.1s %2d hour%1.1s %2d minute%1.1s"
- #define LINE_2 "Filesystem (%-5.5s) %6ld free %6ld total blocks %2d%% available %5d i-nodes"
- #define FILESYS "/dev/rfp002"
- #define FNAME "fp002"
- #ifndef TRUE
- #define TRUE 1
- #endif
-
- char *progname; /* program name */
- char mailfile[30]; /* mailbox file name */
- struct utdata utd; /* Window data structure */
- struct filsys fs; /* Filesystem superblock struct */
- time_t boottime; /* system boot time in sec */
- time_t mailtime = 0L; /* mail modification time */
- int msgs = 0;
- unsigned long days = 0L;
- unsigned long hrs = 0L;
- unsigned long mins = 0L;
-
- /************************************************************************/
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int terminate();
- char *getenv();
- struct utmp *utent, *getutent();
-
- if (fork() != 0) /* detach process-info */
- exit(0);
-
- nice(NICE); /* Be a little nice */
- signal (SIGINT, SIG_IGN);
- signal (SIGQUIT, SIG_IGN);
- signal (SIGHUP, terminate);
- signal (SIGTERM, terminate);
-
- progname = *argv;
- sprintf(mailfile,"%s",getenv("MAIL"));
-
- setutent();
- while ((utent = getutent()) != (struct utmp *)NULL) {
- if (utent->ut_type == BOOT_TIME) {
- boottime = utent->ut_time;
- break;
- }
- }
- endutent();
-
- info_process();
- terminate();
-
- }
-
- info_process()
- {
- char mailbuffer[40];
-
- while (TRUE) {
- filestatus();
- uptime();
- mailcheck(mailbuffer);
-
- utd.ut_num = WTXTSLK1;
- sprintf(utd.ut_text,LINE_1,
- mailbuffer,
- days,(days == 1) ? " " : "s",
- hrs, (hrs == 1) ? " " : "s",
- mins,(mins == 1) ? " " : "s"
- );
- ioctl(0, WIOCSETTEXT, &utd);
-
- utd.ut_num = WTXTSLK2;
- sprintf(utd.ut_text,LINE_2,
- FNAME, fs.s_tfree * 2, fs.s_fsize * 2,
- (int)((((float)fs.s_tfree / (float)fs.s_fsize) + 0.005)
- * 100.0), fs.s_tinode
- );
- ioctl(0, WIOCSETTEXT, &utd);
-
- sleep(SLEEP);
- }
- }
-
- int terminate()
- {
- utd.ut_num = WTXTSLK1; /* clear the label area */
- utd.ut_text[0] = '\0';
- ioctl(0, WIOCSETTEXT, &utd);
- utd.ut_num = WTXTSLK2;
- ioctl(0, WIOCSETTEXT, &utd);
-
- exit(0);
- }
-
- filestatus()
- {
- int fd;
-
- if ((fd = open(FILESYS, O_RDONLY)) == -1) {
- fprintf(stderr,"%s: cannot open %s for read\n",
- progname, FILESYS);
- terminate();
- }
-
- if (lseek(fd, 512, 0) == -1) {
- fprintf(stderr,"%s: cannot lseek to superblock\n", progname);
- terminate();
- }
-
- if (read(fd, &fs, sizeof(struct filsys)) == -1) {
- fprintf(stderr,"%s: cannot read the superblock\n", progname);
- terminate();
- }
-
- close(fd);
-
- }
-
- uptime()
- {
- time_t curtime, bootsec;
-
- time(&curtime);
- bootsec = curtime - boottime;
-
- days = bootsec / DAY;
- bootsec -= DAY * days;
- hrs = bootsec / HOUR;
- bootsec -= HOUR * hrs;
- mins = bootsec / MINUTE;
- bootsec -= MINUTE * mins;
- }
-
- mailcheck(buf)
- char *buf;
- {
- FILE *fp;
- char buffer[BUFSIZ];
- struct stat statbuf;
-
- if (access(mailfile,4) == 0) {
- if (stat(mailfile,&statbuf) != -1) {
- if (statbuf.st_ctime > mailtime) {
- msgs = 0;
- if ((fp = fopen(mailfile,"r")) != NULL) {
- while (fgets(buffer, BUFSIZ, fp) != NULL)
- if (strncmp(buffer,"From ",5) == 0)
- msgs++;
- }
- fclose(fp);
- mailtime = statbuf.st_ctime;
- }
- }
- }
- if (msgs)
- sprintf(buf,"%d mail message%s in your mailbox",msgs,
- (msgs == 1) ? "" : "s");
- else
- buf[0] = '\0';
- }
-