diff options
author | Dimitri Staessens <[email protected]> | 2018-02-19 23:46:34 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2018-02-20 08:49:34 +0100 |
commit | e72fcd924b25b2b3b8a45c85d9c3d09388885249 (patch) | |
tree | e5ab66df04cedd1845dfa624a0ab97366c290325 /src/lib | |
parent | 91012d9af758a48c4c57fc940dfcc8a581fa46ac (diff) | |
download | ouroboros-e72fcd924b25b2b3b8a45c85d9c3d09388885249.tar.gz ouroboros-e72fcd924b25b2b3b8a45c85d9c3d09388885249.zip |
lib: Get RIB attributes from component
This revises the RIB so it gets the complete file attribute list from
the component instead of setting some attributes in the library. This
will allow setting read/write access later on in the component
itself. The time of last change of lsdb entries in the file system is
now set to the time of the last received Link State Update for that
entry.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/rib.c | 70 |
1 files changed, 47 insertions, 23 deletions
diff --git a/src/lib/rib.c b/src/lib/rib.c index 5bb8c1c3..947226a9 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -29,6 +29,7 @@ #include <ouroboros/rib.h> #include <ouroboros/utils.h> +#include <assert.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> @@ -155,9 +156,11 @@ static int rib_readdir(const char * path, ssize_t i; struct reg_comp * c; c = list_entry(p, struct reg_comp, next); - if (strcmp(path + 1, c->path) == 0) - if (c->ops->readdir == NULL) - break; + + if (strcmp(path + 1, c->path) != 0) + continue; + + assert(c->ops->readdir != NULL); len = c->ops->readdir(&dir_entries); if (len < 0) @@ -173,49 +176,70 @@ static int rib_readdir(const char * path, return 0; } +static size_t __getattr(const char * path, + struct stat * st) +{ + struct list_head * p; + char comp[RIB_PATH_LEN + 1]; + char * c; + + strcpy(comp, path + 1); + + c = strstr(comp, "/"); + + if (c != NULL) + *c = '\0'; + + pthread_rwlock_rdlock(&rib.lock); + + list_for_each(p, &rib.reg_comps) { + struct reg_comp * r = list_entry(p, struct reg_comp, next); + if (strcmp(comp, r->path) == 0) { + size_t ret = r->ops->getattr(c + 1, st); + pthread_rwlock_unlock(&rib.lock); + return ret; + } + } + + pthread_rwlock_unlock(&rib.lock); + + return -1; +} + static int rib_getattr(const char * path, struct stat * st) { struct list_head * p; struct timespec now; - clock_gettime(CLOCK_REALTIME_COARSE, &now); - memset(st, 0, sizeof(*st)); - if (strcmp(path, RT) == 0) { - st->st_mode = S_IFDIR | 0755; - st->st_nlink = 2; - st->st_uid = getuid(); - st->st_gid = getgid(); - st->st_mtime = now.tv_sec; - return 0; - } + if (strcmp(path, RT) == 0) + goto finish_dir; pthread_rwlock_rdlock(&rib.lock); list_for_each(p, &rib.reg_comps) { struct reg_comp * rc = list_entry(p, struct reg_comp, next); if (strcmp(path + 1, rc->path) == 0) { - st->st_mode = S_IFDIR | 0755; - st->st_nlink = 2; - break; + pthread_rwlock_unlock(&rib.lock); + goto finish_dir; } } pthread_rwlock_unlock(&rib.lock); - if (st->st_mode == 0) { - char buf[4096]; - st->st_nlink = 2; - st->st_mode = S_IFREG | 0755; - st->st_size = rib_read(path, buf, 4096, 0, NULL); - } + assert(st->st_mode == 0); + + return __getattr(path, st); + finish_dir: + clock_gettime(CLOCK_REALTIME_COARSE, &now); + st->st_mode = S_IFDIR | 0755; + st->st_nlink = 2; st->st_uid = getuid(); st->st_gid = getgid(); st->st_mtime = now.tv_sec; - return 0; } |