X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2FDirMonitor.c;h=65173c86ddef116fcf188c8d4d578efb7949d7d0;hp=edd5bb9eae458c0216207eb5cd794070dcaace30;hb=d47f15496fa85c8ec22edcde608f2665ec5b95ae;hpb=b324b7a09e071b2f84a1849d109d4d14f27f44cd;ds=sidebyside diff --git a/listati/DirMonitor.c b/listati/DirMonitor.c index edd5bb9..65173c8 100644 --- a/listati/DirMonitor.c +++ b/listati/DirMonitor.c @@ -17,33 +17,33 @@ int main(int argc, char *argv[]) { int i, pause = 10; ... - if ((argc - optind) != 1) { /* There must be remaing parameters */ + if ((argc - optind) != 1) { /* There must be remaing parameters */ printf("Wrong number of arguments %d\n", argc - optind); usage(); } - if (chdir(argv[1])) { /* chdir to be sure dir exist */ + if (chdir(argv[1])) { /* chdir to be sure dir exist */ perror("Cannot find directory to monitor"); } - Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */ + Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */ Signal(SIGINT, HandSIGTERM); Signal(SIGQUIT, HandSIGTERM); - key = ftok("~/gapil/sources/DirMonitor.c", 1); /* define a key */ - shmptr = ShmCreate(key, 4096, 0666, 0); /* get a shared memory segment */ + key = ftok("~/gapil/sources/DirMonitor.c", 1); /* define a key */ + shmptr = ShmCreate(key, 4096, 0666, 0); /* get a shared memory segment */ if (!shmptr) { perror("Cannot create shared memory"); exit(1); } - if ((mutex = MutexCreate(key)) == -1) { /* get a Mutex */ + if ((mutex = MutexCreate(key)) == -1) { /* get a Mutex */ perror("Cannot create mutex"); exit(1); } /* main loop, monitor directory properties each 10 sec */ - daemon(1, 0); /* demonize process, staying in monitored dir */ + daemon(1, 0); /* demonize process, staying in monitored dir */ while (1) { - MutexLock(mutex); /* lock shared memory */ - memset(shmptr, 0, sizeof(struct DirProp)); /* erase previous data */ - DirScan(argv[1], ComputeValues); /* execute scan */ - MutexUnlock(mutex); /* unlock shared memory */ - sleep(pause); /* sleep until next watch */ + MutexLock(mutex); /* lock shared memory */ + memset(shmptr, 0, sizeof(struct DirProp)); /* erase previous data */ + DirScan(argv[1], ComputeValues); /* execute scan */ + MutexUnlock(mutex); /* unlock shared memory */ + sleep(pause); /* sleep until next watch */ } }