X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FDirMonitor.c;h=aece529fcef7c3302aa62e3cb160e80f18fc48fe;hp=c9b92f43ab2bf8245a8ff5a2a1d6c7bdd311a4d0;hb=3f50b8e3fd683f710e34a88436109157d328e1b6;hpb=59b107d5207f19e0049bbd1032e10cba660da92e diff --git a/sources/DirMonitor.c b/sources/DirMonitor.c index c9b92f4..aece529 100644 --- a/sources/DirMonitor.c +++ b/sources/DirMonitor.c @@ -25,21 +25,20 @@ * * Author: S. Piccardi Jan. 2003 * - * $Id: DirMonitor.c,v 1.5 2003/01/12 00:24:28 piccardi Exp $ - * *****************************************************************************/ -#include -#include -#include /* directory */ -#include /* C standard library */ -#include +#include /* primitive system data types */ +#include /* file characteristics constants and functions */ +#include /* directory operation constants and functions */ +#include /* C standard library */ +#include /* unix standard library */ +#include /* C strings library */ #include "Gapil.h" #include "macros.h" /* Help printing routine */ void usage(void); -/* computation function for DirScan */ +/* computation function for dir_scan */ int ComputeValues(struct dirent * direntry); void HandSIGTERM(int signo); @@ -55,13 +54,12 @@ struct DirProp { int tot_char; int tot_sock; } *shmptr; -int shmid; +key_t key; int mutex; int main(int argc, char *argv[]) { int i, pause = 10; - key_t key; /* * Input section: decode command line parameters * Use getopt function @@ -106,15 +104,11 @@ int main(int argc, char *argv[]) Signal(SIGINT, HandSIGTERM); Signal(SIGQUIT, HandSIGTERM); key = ftok("~/gapil/sources/DirMonitor.c", 1); /* define a key, use dir */ - shmid = shmget(key, 4096, IPC_CREAT|0666); /* get a shared memory */ - if (shmid < 0) { + shmptr = ShmCreate(key, 4096, 0666, 0); /* get a shared memory segment */ + if (!shmptr) { perror("Cannot create shared memory"); exit(1); } - if ( (shmptr = shmat(shmid, NULL, 0)) == NULL ) { /* attach to process */ - perror("Cannot attach segment"); - exit(1); - } if ((mutex = MutexCreate(key)) == -1) { /* get a Mutex */ perror("Cannot create mutex"); exit(1); @@ -124,13 +118,13 @@ int main(int argc, char *argv[]) while (1) { MutexLock(mutex); /* lock shared memory */ memset(shmptr, 0, sizeof(struct DirProp)); /* erase previous data */ - DirScan(argv[1], ComputeValues); /* execute scan */ + dir_scan(argv[1], ComputeValues); /* execute scan */ MutexUnlock(mutex); /* unlock shared memory */ sleep(pause); /* sleep until next watch */ } } /* - * Routine to compute directory properties inside DirScan + * Routine to compute directory properties inside dir_scan */ int ComputeValues(struct dirent * direntry) { @@ -164,14 +158,7 @@ void usage(void) { void HandSIGTERM(int signo) { MutexLock(mutex); debug("Terminated by %s\n", strsignal(signo)); - if (shmdt(shmptr)) { - perror("Error detaching shared memory"); - exit(1); - } - if (shmctl(shmid, IPC_RMID, NULL)) { - perror("Cannot remove shared memory segment"); - exit(1); - } + ShmRemove(key, shmptr); MutexRemove(mutex); exit(0); }