diff -ru old/wmfstatus-0.4/INSTALL new/wmfstatus-0.4/INSTALL --- old/wmfstatus-0.4/INSTALL Mon Jan 24 03:45:02 2000 +++ new/wmfstatus-0.4/INSTALL Sun May 21 13:18:15 2000 @@ -31,3 +31,6 @@ Note 2: Please DO read the HINTS, this file contains some very usefull hints & tips about WMFstatus. + +Note 3: If you are trying to compile for Solaris, you will need to edit + wmfstatus/Makefile according to the comments therein. diff -ru old/wmfstatus-0.4/wmfstatus/Makefile new/wmfstatus-0.4/wmfstatus/Makefile --- old/wmfstatus-0.4/wmfstatus/Makefile Mon Nov 22 11:38:29 1999 +++ new/wmfstatus-0.4/wmfstatus/Makefile Sun Sep 3 18:54:40 2000 @@ -1,17 +1,32 @@ LIBDIR = -L/usr/X11R6/lib +INCDIR = -I/usr/X11R6/share/include LIBS = -lXpm -lXext -lX11 -FLAGS = -O2 + +#use for gcc +CC = gcc +FLAGS = -O2 -Wall + +#uncomment for Sun's C compiler +#CC = cc +#FLAGS = -v -xO2 + OBJS = wmfstatus.o \ ../wmgeneral/wmgeneral.o \ ../wmgeneral/misc.o \ ../wmgeneral/list.o +# uncomment these for Solaris +# +LIBDIR += -L/usr/openwin/lib -R/usr/openwin/lib -L/usr/local/lib -R/usr/local/lib -L/opt/sfw/lib -R/opt/sfw/lib +FLAGS += -DNEED_POSIX_FILE_LOCKING=1 +INCDIR += -I/usr/openwin/include -I/usr/local/include -I/opt/sfw/include + .c.o: - cc -I/usr/X11R6/share/include $(FLAGS) -c -Wall $< -o $*.o + $(CC) $(INCDIR) $(FLAGS) -c $< -o $*.o wmfstatus: $(OBJS) - cc $(FLAGS) -o wmfstatus $^ -lXext $(LIBDIR) $(LIBS) + $(CC) $(FLAGS) -o wmfstatus $^ -lXext $(LIBDIR) $(LIBS) all:: wmfstatus diff -ru old/wmfstatus-0.4/wmfstatus/wmfstatus.c new/wmfstatus-0.4/wmfstatus/wmfstatus.c --- old/wmfstatus-0.4/wmfstatus/wmfstatus.c Mon Jan 24 03:42:00 2000 +++ new/wmfstatus-0.4/wmfstatus/wmfstatus.c Sun May 21 13:18:15 2000 @@ -20,8 +20,9 @@ #include #include -#include +#include #include +#include #include "../wmgeneral/wmgeneral.h" #include "../wmgeneral/misc.h" @@ -171,7 +172,7 @@ prevtime = time(0) - 1; - GetStats(); // Run for the first time anyway + GetStats(); /* Run for the first time anyway */ j = 11; k = 0; l = 11; while (1) @@ -182,7 +183,7 @@ if ( curtime >= prevtime + 1) { - // Get data to display + /* Get data to display */ if (mode == MOD_POL) GetStats(); prevtime = curtime; @@ -220,7 +221,7 @@ } RedrawWindow(); - // X Events + /* X Events */ while (XPending(display)) { XNextEvent(display, &Event); @@ -246,7 +247,7 @@ execCommand(Actions[((i+k)%lines)+1]); } but_stat = -1; -// RedrawWindow(); +/* RedrawWindow(); */ break; } } @@ -277,7 +278,7 @@ } } -// Blits a string at given co-ordinates +/* Blits a string at given co-ordinates */ void BlitString(char *name, int x, int y, int h) { int i; @@ -290,13 +291,13 @@ c = toupper(name[i]); if (c >= 'A' && c <= 'Z') - { // its a letter + { /* its a letter */ c -= 'A'; copyXPMArea(c * 6, 74, 6, h, k, y); k += 6; } else - { // its a number or symbol + { /* its a number or symbol */ c -= '0'; copyXPMArea(c * 6, 64, 6, h, k, y); k += 6; @@ -306,7 +307,7 @@ } -// Blits number to give coordinates.. two 0's, right justified +/* Blits number to give coordinates.. two 0's, right justified */ void BlitNum(int num, int x, int y, int h) { @@ -342,7 +343,7 @@ fprintf(stderr, " -h this help screen\n"); fprintf(stderr, " -v print the version number\n"); fprintf(stderr, " -p switch to non polling mode\n"); - fprintf(stderr, " info updated upon reciving SIGUSR1\n"); + fprintf(stderr, " info updated upon receiving SIGUSR1\n"); fprintf(stderr, "\n"); } @@ -359,6 +360,9 @@ FILE *f; int fd; int pid; +#if (NEED_POSIX_FILE_LOCKING == 1) + struct flock flock_desc; +#endif if (((fd = open(pidfile, O_RDWR|O_CREAT, 0644)) == -1) || ((f = fdopen(fd, "r+")) == NULL) ) { @@ -366,12 +370,25 @@ return 0; } +#if (NEED_POSIX_FILE_LOCKING == 1) + flock_desc.l_type = F_WRLCK; + flock_desc.l_whence = SEEK_SET; + flock_desc.l_start = 0; + flock_desc.l_len = 0; /* to end of file */ + if (fcntl(fd, F_SETLK, &flock_desc) != 0) { + fscanf(f, "%d", &pid); + fclose(f); + printf("Can't lock, lock is held by pid %d.\n", pid); + return 0; + } +#else /* NEED_POSIX_FILE_LOCKING */ if (flock(fd, LOCK_EX|LOCK_NB) == -1) { fscanf(f, "%d", &pid); fclose(f); printf("Can't lock, lock is held by pid %d.\n", pid); return 0; } +#endif /* NEED_POSIX_FILE_LOCKING */ pid = getpid(); if (!fprintf(f,"%d\n", pid)) { @@ -381,11 +398,25 @@ } fflush(f); +#if (NEED_POSIX_FILE_LOCKING == 1) + flock_desc.l_type = F_UNLCK; + flock_desc.l_whence = SEEK_SET; + flock_desc.l_start = 0; + flock_desc.l_len = 0; /* to end of file */ + if (fcntl(fd, F_SETLK, &flock_desc) != 0) { + fscanf(f, "%d", &pid); + fclose(f); + printf("Can't lock, lock is held by pid %d.\n", pid); + return 0; + } +#else /* NEED_POSIX_FILE_LOCKING */ if (flock(fd, LOCK_UN) == -1) { printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno)); close(fd); return 0; } +#endif /* NEED_POSIX_FILE_LOCKING */ + close(fd); return pid; @@ -400,7 +431,7 @@ return; } else{ - // Try to create empty file + /* Try to create empty file */ fprintf(stderr, "..doesn't exist.\nCreating empty.."); if ((fp = fopen(uconfig_file, "w")) == NULL){ fprintf(stderr, ".can't create [%s].\n", uconfig_file);