X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FDirMonitor.c;h=8c7335233000a3e5fe0f1c3c9c816c27c908e768;hp=c9b92f43ab2bf8245a8ff5a2a1d6c7bdd311a4d0;hb=de83478a4dec2c8dd1b3721c4548b8d902555566;hpb=aa6e7fc3085168384700494a4bd22208f71e089e diff --git a/sources/DirMonitor.c b/sources/DirMonitor.c index c9b92f4..8c73352 100644 --- a/sources/DirMonitor.c +++ b/sources/DirMonitor.c @@ -25,7 +25,7 @@ * * Author: S. Piccardi Jan. 2003 * - * $Id: DirMonitor.c,v 1.5 2003/01/12 00:24:28 piccardi Exp $ + * $Id: DirMonitor.c,v 1.6 2003/02/26 21:37:36 piccardi Exp $ * *****************************************************************************/ #include @@ -55,13 +55,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 +105,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); @@ -164,14 +159,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); }