diff -ur notifyme-1.4.1-org/AUTHORS notifyme-1.4.1-SunOS/AUTHORS --- notifyme-1.4.1-org/AUTHORS Sat Mar 11 17:11:44 2000 +++ notifyme-1.4.1-SunOS/AUTHORS Sat Jul 14 10:02:43 2001 @@ -1,2 +1,5 @@ Michal Suszycki http://wizard.ae.krakow.pl/~mike + +Alpha SunOS support added by Srijith.K +http://www.srijith.net diff -ur notifyme-1.4.1-org/ChangeLog notifyme-1.4.1-SunOS/ChangeLog --- notifyme-1.4.1-org/ChangeLog Tue Jan 9 11:02:16 2001 +++ notifyme-1.4.1-SunOS/ChangeLog Sat Jul 14 10:03:52 2001 @@ -1,3 +1,6 @@ +13 Jul 2001: + Added some basic SunOS ports for it to work on few SUN + machines in my Univ network - Srijith 8 Jan 2001: Almost full rewrite, added lot of directives to config file 7 Apr 2000: diff -ur notifyme-1.4.1-org/README notifyme-1.4.1-SunOS/README --- notifyme-1.4.1-org/README Wed Feb 28 17:33:22 2001 +++ notifyme-1.4.1-SunOS/README Sat Jul 14 10:04:17 2001 @@ -19,6 +19,7 @@ -C always print messages in the center of the screen -l don't report logouts -q quiet - no beep with message + -w report present online user and exits - Added by SK -h help Rest of the arguments are usernames to watch (extended regular expressions diff -ur notifyme-1.4.1-org/config_file.c notifyme-1.4.1-SunOS/config_file.c --- notifyme-1.4.1-org/config_file.c Wed Feb 28 18:05:35 2001 +++ notifyme-1.4.1-SunOS/config_file.c Sat Jul 14 10:10:37 2001 @@ -1,3 +1,4 @@ +#include #include "config_file.h" #include "notifyme.h" @@ -43,7 +44,11 @@ if(p == s++) return 1; *val = realloc(*val, (p - s) * sizeof (char) + 1); - if(!*val) errx(1, __FUNCTION__ ": cannot allocate memory. Exiting."); + //if(!*val) errx(1, __FUNCTION__ ": cannot allocate memory. Exiting."); + if (!val) { + printf("Cannot allocate memory. Exiting"); + exit(-1); + } bzero(*val, p - s + 1); strncpy(*val, s, p - s); return 0; @@ -118,7 +123,9 @@ err = regcomp(&t->reg, t->key, REG_EXTENDED); if (err) { regerror(err, &t->reg, erbuf, sizeof erbuf); - errx(1, "Invalid regex around %d line: %s", line, erbuf); + //errx(1, "Invalid regex around %d line: %s", line,erbuf); + printf("Invalid regex around %d line: %s",line,erbuf); + exit(-1); } } @@ -160,7 +167,11 @@ else if(config[i].val_type == INT) error = int_val(p, int_type); else error = token(p, msg); - if(error) errx(1, "Syntax error in line %d", line); + //if(error) errx(1, "Syntax error in line %d", line); + if(error) { + printf("Syntax error in line %d",line); + exit(-1); + } break; } return found; @@ -173,8 +184,11 @@ while (**s && !valid_sep(**s) && **s != '\n') (*s)++; t = calloc(1, sizeof *t); - if(!t) errx(1, __FUNCTION__": Cannot allocate memory. Exiting."); - + //if(!t) errx(1, __FUNCTION__": Cannot allocate memory. Exiting."); + if(!t) { + printf("Cannot allocate memory. Exiting."); + exit(-1); + } /* for compatibility with older config file */ if(type == GLOBAL_TYPE) globals[type-1].flags = ~0; t->type = type==GLOBAL_TYPE?USER_TYPE:type; @@ -208,9 +222,17 @@ break; } if (read_option(p, type, t, *n)) continue; - else errx(1, "Missing } in line %d", *n); + //else errx(1, "Missing } in line %d", *n); + else { + printf("Missing } in line %d",*n); + exit(-1); + } + } + //if(!end) errx(1, "Missing } in line %d", *n); + if(!end) { + printf("Missing } in line %d",*n); + exit(-1); } - if(!end) errx(1, "Missing } in line %d", *n); } /* @@ -234,7 +256,11 @@ if (read_option(p, type, t, n)) goto NEXT; if (*p == '{') { if(t) read_options(f, t, type, &n); - else errx(1, "{ without previous identifier in line %d", n); + //else errx(1, "{ without previous identifier in line %d", n); + else { + printf("{ without previous identifier in line %d",n); + exit(-1); + } continue; } t = new_entry(&p, type, n); @@ -284,11 +310,11 @@ show_options(globals[USER_TYPE-1].flags); for_each(t, entry_l) { if(t->type != prev_type) { - printf("\nWatched %s\n", groups[t->type-1].s); +//SK: printf("\nWatched %s\n", groups[t->type-1].s); prev_type = t->type; } - printf("\t--%s, %d, 0x%x, %s, %s, %d\n", - t->key, t->type, t->flags, t->msg[0], t->msg[1], t->hold); +//SK: printf("\t--%s, %d, 0x%x, %s, %s, %d\n", +//SK: t->key, t->type, t->flags, t->msg[0], t->msg[1], t->hold); // show_options(t->flags); } printf("\n"); diff -ur notifyme-1.4.1-org/config_file.h notifyme-1.4.1-SunOS/config_file.h --- notifyme-1.4.1-org/config_file.h Mon Feb 5 07:03:36 2001 +++ notifyme-1.4.1-SunOS/config_file.h Sat Jul 14 09:58:52 2001 @@ -1,4 +1,4 @@ -#include +//#include #include #include #include diff -ur notifyme-1.4.1-org/configure notifyme-1.4.1-SunOS/configure --- notifyme-1.4.1-org/configure Tue Jan 9 10:29:25 2001 +++ notifyme-1.4.1-SunOS/configure Sat Jul 14 09:58:52 2001 @@ -1066,7 +1066,7 @@ #line 1067 "configure" #include "confdefs.h" -#include +#include int main() { int i=USER_PROCESS; @@ -1075,7 +1075,7 @@ if { (eval echo configure:1076: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 - cat >> confdefs.h <<\EOF + cat >> confdefs.h <<\EOF #define HAVE_USER_PROCESS 1 EOF diff -ur notifyme-1.4.1-org/configure.in notifyme-1.4.1-SunOS/configure.in --- notifyme-1.4.1-org/configure.in Tue Jan 9 10:29:12 2001 +++ notifyme-1.4.1-SunOS/configure.in Sat Jul 14 09:58:52 2001 @@ -19,7 +19,7 @@ dnl Checks for typedefs, structures, and compiler characteristics. AC_MSG_CHECKING([whether utmp has USER_PROCESS type]) AC_TRY_COMPILE([ -#include +#include ], [int i=USER_PROCESS;],[AC_MSG_RESULT(yes) AC_DEFINE(HAVE_USER_PROCESS)], AC_MSG_RESULT(no)) diff -ur notifyme-1.4.1-org/notifyme.c notifyme-1.4.1-SunOS/notifyme.c --- notifyme-1.4.1-org/notifyme.c Wed Feb 28 18:14:34 2001 +++ notifyme-1.4.1-SunOS/notifyme.c Sat Jul 14 09:58:53 2001 @@ -1,5 +1,8 @@ -#include +//#include #include +#include +#include +#include #include #include #include @@ -14,28 +17,45 @@ #define MIN(a,b) ( (a) < (b) ? (a) : (b)) -#ifndef UTMP_FILE -#define UTMP_FILE "/var/run/utmp" +#ifndef UTMPX_FILE +#define UTMPX_FILE "/var/adm/utmpx" #endif -#ifndef WTMP_FILE -#define WTMP_FILE "/var/log/wtmp" +#ifndef WTMPX_FILE +#define WTMPX_FILE "/var/adm/wtmpx" +#endif + +#ifdef USER_PROCESS +#define HAVE_USER_PROCESS 1 #endif #ifndef UT_NAMESIZE -#define UT_NAMESIZE 8 +#define UT_NAMESIZE 32 +#endif + +#ifndef UT_LINESIZE +#define UT_LINESIZE 32 #endif #define IN 1 #define OUT 2 +#ifndef ut_name +#define ut_name ut_user +#endif + +#ifndef ut_user #define ut_user ut_name +#endif char *resfile; static int lflag = 1; /* should I report logouts? */ static int qflag = 1; /* sound */ static int center_flag; /* whether message should be centered */ +static int who_flag =0; /* Added by SK: Should notifyme exit + after showing who is online now and not + keep on monitoring */ struct list_head entry_l = { &entry_l, &entry_l }; struct list_head tty_l = { &tty_l, &tty_l }; @@ -54,11 +74,12 @@ void usage() { - printf("\nnotifyme [-c conf] [-C] [-l] [-q] [-h] [USERNAME]...\n"); + printf("\nnotifyme [-c conf] [-C] [-l] [-q] [-w] [-h] [USERNAME]...\n"); printf("-c conf\t\tspecify alternate configuration\n"); printf("-C\t\tforce to print messages in the center of the screen\n"); printf("-l\t\tdon't report logouts\n"); printf("-q\t\tquiet - no beep with message\n"); + printf("-w\t\texit after printing current users. No monitoring\n"); printf("-h\t\thelp - this message\n"); printf("Rest of the arguments are usernames to watch.\n\n"); printf("USR1 signal can be used to re-read resource file.\n\n"); @@ -68,7 +89,10 @@ { struct stat st; char buf[32]; + /* Removed as sparc doesnt support it snprintf(buf,sizeof buf, "/dev/%s",tty); + */ + sprintf(buf,"/dev/%s",tty); if (stat(buf,&st) == -1) return -1; return (time(0) - st.st_atime); } @@ -101,16 +125,18 @@ if(!s) return 0; len = strlen(s) + 1; d = calloc(1, len); - if(!d) errx(1, "Cannot allocate memory."); + //if(!d) errx(1, "Cannot allocate memory."); + if(!d) {printf("Cannot allocate memory.");exit(-1);} strncpy(d, s, len); return d; } -struct tty_t *new_tty(struct utmp *u, struct entry_t *e) +struct tty_t *new_tty(struct utmpx *u, struct entry_t *e) { struct tty_t *t; t = calloc(1, sizeof *t); - if(!t) errx(1, "Cannot allocate memory. Exiting."); + //if(!t) errx(1, "Cannot allocate memory. Exiting."); + if(!t) { printf("Cannot Allocate memory. Exiting.");exit(-1);} t->name = cp_string(u->ut_user); t->tty = cp_string(u->ut_line); t->host = cp_string(u->ut_host); @@ -128,7 +154,7 @@ return !err; } -static int match_entry(struct entry_t *e, struct utmp *u) +static int match_entry(struct entry_t *e, struct utmpx *u) { char *s = 0; int len; @@ -155,13 +181,15 @@ void read_utmp() { int fd; - struct utmp ent; + struct utmpx ent; struct entry_t *e; struct tty_t *t; time_t idle; + setutxent(); - if (!(fd = open(UTMP_FILE,O_RDONLY))) - errx(1, "Cannot open " UTMP_FILE ". Exiting."); + if (!(fd = open(UTMPX_FILE,O_RDONLY))) + //errx(1, "Cannot open " UTMPX_FILE ". Exiting."); + {printf("Cannot open UTMPX_FILE. Exiting.");exit(-1);} while(read(fd, &ent, sizeof ent) > 0){ #ifdef HAVE_USER_PROCESS if(ent.ut_type != USER_PROCESS) continue; @@ -266,8 +294,11 @@ for(x = 0; x < sizeof fmts/sizeof(struct fmt); x++) { int len; if(s[i] != fmts[x].c) continue; + /* Removed as sparc doesnt define snprintf len = snprintf(buf+z, sizeof buf - z, "%s", fmts[x].s); + */ + len = sprintf(buf+z,"%s",fmts[x].s); if(len != strlen(fmts[x].s)) return buf; z += len; } @@ -284,6 +315,8 @@ tty_l.prev = &tty_l; read_conf(resfile); read_utmp(); + //SK Change + report_users(); } static void free_tty_t(struct tty_t *t) @@ -305,7 +338,7 @@ } } -static void check_logout(struct utmp *ut) +static void check_logout(struct utmpx *ut) { char *msg; int msg_type = OUT_MSG, found = 0; @@ -320,7 +353,7 @@ if(!(t->entry->flags & OUT_REPORT) || !lflag) break; if(!t->entry->count) msg_type = LAST_MSG; - msg = prepare_msg(t, choose_msg(t->entry, msg_type)); + msg = prepare_msg(t, choose_msg(t->entry,msg_type)); print_msg(msg, t->entry->flags & OUT_BEEP, t->entry->flags & CENTER_MSG); hold_mark(t->entry, msg); break; @@ -330,7 +363,7 @@ free_tty_t(t); } -static void check_login(struct utmp *ut) +static void check_login(struct utmpx *ut) { struct entry_t *e; char *msg; @@ -360,14 +393,14 @@ sleep(3); return; } - for(i = 0; i < 6; i++) { + for(i = 0; i < 3; i++) { if(!hold_remain) { hold_msg = 0; return; } if(!tmp) hold_remain--; print_msg(hold_msg, 0, center_hold); - usleep(500000); + sleep(1); tmp ^= 1; } } @@ -377,11 +410,11 @@ { int f, c, v, argcount = 1; int prnt; - struct utmp ut; + struct utmpx ut; char *env; char rcfile[256]; - while((c = getopt(argc, argv, "Cc:hlq")) != -1) { + while((c = getopt(argc, argv, "Cc:hlqw")) != -1) { switch(c) { case 'q': /* to beep or not to beep */ qflag = 0; @@ -399,6 +432,10 @@ lflag = 0; argcount++; break; + case 'w': + who_flag=1; + argcount++; + break; case 'h': usage(); exit(0); @@ -415,34 +452,46 @@ argcount++; } if (!isatty(1)) exit(0); - if ((f = open(WTMP_FILE,O_RDONLY)) < 0){ - printf ("Cannot open " WTMP_FILE "\n"); + if ((f = open(WTMPX_FILE,O_RDONLY)) < 0){ + printf ("Cannot open " WTMPX_FILE "\n"); exit (0); } bzero(rcfile, sizeof rcfile); if(!resfile && !(env = getenv("HOME"))) - errx(1, "HOME is not set"); - + //errx(1, "HOME is not set"); + {printf("Home is not set. Exiting.");exit(-1);} if(!resfile) { + /* Remove as sparc doesnt support snprintf snprintf(rcfile, sizeof rcfile - 1, "%s/.notifyrc",env); + */ + sprintf(rcfile,"%s/.notifyrc",env); resfile = rcfile; } if (!read_conf(resfile) && IS_EMPTY(&entry_l)) - errx(1, "No configuration file and usernames in command line. Exiting.\n"); + //errx(1, "No configuration file and usernames in command line. Exiting.\n"); + {printf("No config file and usernames in command line. Exiting");exit(-1);} #ifdef DEBUG show_conf(); #endif read_utmp(); if(lseek(f, 0, SEEK_END) == -1) - errx(1,"Cannot lseek " WTMP_FILE); + //errx(1,"Cannot lseek " WTMPX_FILE); + {printf("Cannot lseek WTMPX_FILE.Exiting.");exit(-1);} report_users(); + if(who_flag) { +#ifdef DEBUG + printf("Exiting after showing current users. 'w' option supplied"); +#endif + exit(-1); + } prnt = getppid(); #ifndef DEBUG switch(v = fork()){ case -1: - errx(1, "Cannot fork."); + //errx(1, "Cannot fork."); + {printf("Cannot fork");exit(-1);} case 0 : setpgid(getpid(), prnt); break; @@ -469,6 +518,7 @@ check_logout(&ut); continue; } + /* user just logged in */ check_login(&ut); } diff -ur notifyme-1.4.1-org/notifyme.h notifyme-1.4.1-SunOS/notifyme.h --- notifyme-1.4.1-org/notifyme.h Wed Feb 28 18:04:46 2001 +++ notifyme-1.4.1-SunOS/notifyme.h Sat Jul 14 09:58:53 2001 @@ -1,8 +1,10 @@ #include -#include +//#include +#include #include #include "config.h" +//#define DEBUG 1 #define for_each(e,l) for((e)=(l).next; (e)!=(void *) &(l); (e)=(e)->next) #define addto_list(e,l) {(e)->prev=(l).prev; \ (e)->prev->next=(e); \ diff -ur notifyme-1.4.1-org/screen.c notifyme-1.4.1-SunOS/screen.c --- notifyme-1.4.1-org/screen.c Wed Feb 28 17:59:53 2001 +++ notifyme-1.4.1-SunOS/screen.c Sat Jul 14 09:58:53 2001 @@ -6,6 +6,7 @@ #define SAVE ESC "7" /* save current state */ #define BOLD ESC "[1m" +#define LIGHTRED ESC "[1;31m" /*BLUE COLOR..SK*/ #define RESET ESC "[0m" /* reset attr to their defaults */ /* restore most recently saved state */ @@ -17,14 +18,20 @@ static inline void goto_col(int x) { char buf[16]; + /* Rrmoved as sparc doesnthave snprintf snprintf(buf, sizeof buf, "\033[1;%dH", x); + */ + sprintf(buf,"\033[1;%dH",x); printf("%s", buf); } static inline void goto_xy(int x, int y) { char buf[16]; + /* Removed cos not supported snprintf(buf, sizeof buf, "\033[%d;%dH", y, x); + */ + sprintf(buf,"\033[%d;%dH",y,x); printf("%s", buf); } @@ -55,7 +62,7 @@ msg_x = x; msg_y = y; goto_xy(x, y); - printf(BOLD "%s", s); + printf(LIGHTRED "%s", s); printf(RESTORE RESET); }