1 /* global variables for shared memory segment */
16 int main(int argc, char *argv[])
20 if ((argc - optind) != 1) { /* There must be remaing parameters */
21 printf("Wrong number of arguments %d\n", argc - optind);
24 if (chdir(argv[1])) { /* chdir to be sure dir exist */
25 perror("Cannot find directory to monitor");
27 Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */
28 Signal(SIGINT, HandSIGTERM);
29 Signal(SIGQUIT, HandSIGTERM);
30 key = ftok("~/gapil/sources/DirMonitor.c", 1); /* define a key */
31 shmptr = ShmCreate(key, 4096, 0666, 0); /* get a shared memory segment */
33 perror("Cannot create shared memory");
36 if ((mutex = MutexCreate(key)) == -1) { /* get a Mutex */
37 perror("Cannot create mutex");
40 /* main loop, monitor directory properties each 10 sec */
41 daemon(1, 0); /* demonize process, staying in monitored dir */
43 MutexLock(mutex); /* lock shared memory */
44 memset(shmptr, 0, sizeof(struct DirProp)); /* erase previous data */
45 DirScan(argv[1], ComputeValues); /* execute scan */
46 MutexUnlock(mutex); /* unlock shared memory */
47 sleep(pause); /* sleep until next watch */