{
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 */
}
}