projects
/
gapil.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Altre correzioni, con esempi sul server fortunes e relativa "demonizzazzione"
[gapil.git]
/
sources
/
DirMonitor.c
diff --git
a/sources/DirMonitor.c
b/sources/DirMonitor.c
index 47253548ab1f5ea769f91dd492f6306b10698c09..c9b92f43ab2bf8245a8ff5a2a1d6c7bdd311a4d0 100644
(file)
--- a/
sources/DirMonitor.c
+++ b/
sources/DirMonitor.c
@@
-25,7
+25,7
@@
*
* Author: S. Piccardi Jan. 2003
*
*
* Author: S. Piccardi Jan. 2003
*
- * $Id: DirMonitor.c,v 1.
3 2003/01/06 16:44:20
piccardi Exp $
+ * $Id: DirMonitor.c,v 1.
5 2003/01/12 00:24:28
piccardi Exp $
*
*****************************************************************************/
#include <sys/types.h>
*
*****************************************************************************/
#include <sys/types.h>
@@
-54,8
+54,7
@@
struct DirProp {
int tot_block;
int tot_char;
int tot_sock;
int tot_block;
int tot_char;
int tot_sock;
-};
-struct DirProp *shmptr;
+} *shmptr;
int shmid;
int mutex;
int shmid;
int mutex;
@@
-99,11
+98,14
@@
int main(int argc, char *argv[])
printf("Wrong number of arguments %d\n", argc - optind);
usage();
}
printf("Wrong number of arguments %d\n", argc - optind);
usage();
}
+ if (chdir(argv[1])) { /* chdir to be sure dir exist */
+ perror("Cannot find directory to monitor");
+ exit(1);
+ }
Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */
Signal(SIGINT, HandSIGTERM);
Signal(SIGQUIT, HandSIGTERM);
Signal(SIGTERM, HandSIGTERM); /* set handlers for termination */
Signal(SIGINT, HandSIGTERM);
Signal(SIGQUIT, HandSIGTERM);
- /* create needed IPC objects */
- key = ftok("./DirMonitor.c", 1); /* define a key */
+ 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) {
perror("Cannot create shared memory");
shmid = shmget(key, 4096, IPC_CREAT|0666); /* get a shared memory */
if (shmid < 0) {
perror("Cannot create shared memory");
@@
-111,12
+113,14
@@
int main(int argc, char *argv[])
}
if ( (shmptr = shmat(shmid, NULL, 0)) == NULL ) { /* attach to process */
perror("Cannot attach segment");
}
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);
}
/* main loop, monitor directory properties each 10 sec */
}
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 */
while (1) {
MutexLock(mutex); /* lock shared memory */
memset(shmptr, 0, sizeof(struct DirProp)); /* erase previous data */
while (1) {
MutexLock(mutex); /* lock shared memory */
memset(shmptr, 0, sizeof(struct DirProp)); /* erase previous data */
@@
-137,10
+141,10
@@
int ComputeValues(struct dirent * direntry)
if (S_ISREG(data.st_mode)) shmptr->tot_regular++;
if (S_ISFIFO(data.st_mode)) shmptr->tot_fifo++;
if (S_ISLNK(data.st_mode)) shmptr->tot_link++;
if (S_ISREG(data.st_mode)) shmptr->tot_regular++;
if (S_ISFIFO(data.st_mode)) shmptr->tot_fifo++;
if (S_ISLNK(data.st_mode)) shmptr->tot_link++;
- if (S_ISDIR(data.st_mode)) shmptr->tot_dir;
- if (S_ISBLK(data.st_mode)) shmptr->tot_block;
- if (S_ISCHR(data.st_mode)) shmptr->tot_char;
- if (S_ISSOCK(data.st_mode)) shmptr->tot_sock;
+ if (S_ISDIR(data.st_mode)) shmptr->tot_dir
++
;
+ if (S_ISBLK(data.st_mode)) shmptr->tot_block
++
;
+ if (S_ISCHR(data.st_mode)) shmptr->tot_char
++
;
+ if (S_ISSOCK(data.st_mode)) shmptr->tot_sock
++
;
return 0;
}
/*
return 0;
}
/*