[Sysfence-commit] sysfence datastruct.c,1.2,1.3 datastruct.h,1.2,1.3
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-28 23:26:30
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11352 Modified Files: datastruct.c datastruct.h Log Message: + functions handling fs database Index: datastruct.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- datastruct.h 26 May 2004 04:07:13 -0000 1.2 +++ datastruct.h 28 May 2004 23:26:20 -0000 1.3 @@ -185,6 +185,8 @@ void add_def_to_list (sf_list **hd, sf_stat_def *def); int equal_defs (sf_stat_def *d1, sf_stat_def *d2); int uid_in_list (sf_list *hd, uid_t uid); +void add_fs_entry_to_list (sf_list **hd, char *path); +sf_fs_stats * get_fs_entry_from_list (sf_list *hd, char *path); char * def_2_string (sf_stat_def *def); /* $Id$ */ Index: datastruct.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- datastruct.c 26 May 2004 17:39:12 -0000 1.2 +++ datastruct.c 28 May 2004 23:26:20 -0000 1.3 @@ -84,6 +84,68 @@ return 1; } +void add_fs_entry_to_list (sf_list **hd, char *path) +{ + /* adds new fs entry to list of paths being watched + * used to register new paths while parsing config file + */ + sf_list *l = *hd; + sf_fs_stats *e; + +#ifdef DEBUG + if (!hd) + syslog (LOG_DEBUG, "add_fs_entry_to_list(NULL, %s)", path); + else if (! l) + syslog (LOG_DEBUG, "add_fs_entry_to_list(%x -> NULL, %s)", hd, path); + else + syslog (LOG_DEBUG, "add_fs_entry_to_list(%x -> %x, %s)", hd, l, path); +#endif + + if (! l) { + /* end-of-list reached, add entry */ + e = (sf_fs_stats *) xalloc (NULL, sizeof (sf_fs_stats)); + e->path = (char *) xalloc (NULL, strlen (path) + 1); + strcpy (e->path, path); + + l = (sf_list *) xalloc (NULL, sizeof (sf_list)); + l->next = NULL; + l->elsize = sizeof (sf_fs_stats); + l->el = (void *) e; + *hd = l; + return; + } + + e = (sf_fs_stats *) l->el; + + /* do not insert duplicates */ +#ifdef DEBUG + syslog (LOG_DEBUG, "? %s == %s", e->path, path); +#endif + if (strcmp (e->path, path) == 0) return; + + add_fs_entry_to_list (&(l->next), path); +} + +sf_fs_stats * get_fs_entry_from_list (sf_list *hd, char *path) +{ + /* finds an entry in list of paths being watched */ + sf_fs_stats *st; + +#ifdef DEBUG + syslog (LOG_DEBUG, "get_fs_entry_from_list(%x, %s)", hd, path); +#endif + + // not found + if (! hd) return NULL; + + st = (sf_fs_stats *) hd->el; +#ifdef DEBUG + syslog (LOG_DEBUG, " +-- list element: %s)", st->path); +#endif + if (strcmp (st->path, path)) return st; + else return get_fs_entry_from_list (hd->next, path); +} + int equal_defs (sf_stat_def *d1, sf_stat_def *d2) { /* checks if two defs describe the same stat */ |