summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-08-25 12:50:57 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-08-25 12:50:57 +0200
commit4e925980d16a7468a55ad2c23cc29ec51311ef6d (patch)
treeca34a2d343c1a84c0b9ed7bec080cf9864ae1828
parente3017eacd1b265377d6581fe255d8c0b994a3cec (diff)
afb-api-so: fix a bug in error detection
Error detection wasn't reported when an error occured in a subdirectory. Also closes the opened directories on error and allows a mode for ignoring binding errors. Change-Id: I34e52de8ea71bf84556878a395b56c6628cc5d9a Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-api-so.c38
-rw-r--r--src/afb-api-so.h9
-rw-r--r--src/main.c2
3 files changed, 34 insertions, 15 deletions
diff --git a/src/afb-api-so.c b/src/afb-api-so.c
index bee5fe80..9744bae2 100644
--- a/src/afb-api-so.c
+++ b/src/afb-api-so.c
@@ -81,11 +81,12 @@ int afb_api_so_add_binding(const char *path, struct afb_apiset *apiset)
return load_binding(path, 1, apiset);
}
-static int adddirs(char path[PATH_MAX], size_t end, struct afb_apiset *apiset)
+static int adddirs(char path[PATH_MAX], size_t end, struct afb_apiset *apiset, int failstops)
{
DIR *dir;
struct dirent *dent;
size_t len;
+ int rc;
/* open the DIR now */
dir = opendir(path);
@@ -121,21 +122,24 @@ static int adddirs(char path[PATH_MAX], size_t end, struct afb_apiset *apiset)
continue;
}
memcpy(&path[end], dent->d_name, len+1);
- adddirs(path, end+len, apiset);
+ rc = adddirs(path, end+len, apiset, failstops);
} else if (dent->d_type == DT_REG) {
/* case of files */
if (memcmp(&dent->d_name[len - 3], ".so", 4))
continue;
memcpy(&path[end], dent->d_name, len+1);
- if (load_binding(path, 0, apiset) < 0)
- return -1;
+ rc = load_binding(path, 0, apiset);
+ }
+ if (rc < 0 && failstops) {
+ closedir(dir);
+ return rc;
}
}
closedir(dir);
return 0;
}
-int afb_api_so_add_directory(const char *path, struct afb_apiset *apiset)
+int afb_api_so_add_directory(const char *path, struct afb_apiset *apiset, int failstops)
{
size_t length;
char buffer[PATH_MAX];
@@ -147,10 +151,10 @@ int afb_api_so_add_directory(const char *path, struct afb_apiset *apiset)
}
memcpy(buffer, path, length + 1);
- return adddirs(buffer, length, apiset);
+ return adddirs(buffer, length, apiset, failstops);
}
-int afb_api_so_add_path(const char *path, struct afb_apiset *apiset)
+int afb_api_so_add_path(const char *path, struct afb_apiset *apiset, int failstops)
{
struct stat st;
int rc;
@@ -159,7 +163,7 @@ int afb_api_so_add_path(const char *path, struct afb_apiset *apiset)
if (rc < 0)
ERROR("Invalid binding path [%s]: %m", path);
else if (S_ISDIR(st.st_mode))
- rc = afb_api_so_add_directory(path, apiset);
+ rc = afb_api_so_add_directory(path, apiset, failstops);
else if (strstr(path, ".so"))
rc = load_binding(path, 0, apiset);
else
@@ -167,18 +171,30 @@ int afb_api_so_add_path(const char *path, struct afb_apiset *apiset)
return rc;
}
-int afb_api_so_add_pathset(const char *pathset, struct afb_apiset *apiset)
+int afb_api_so_add_pathset(const char *pathset, struct afb_apiset *apiset, int failstops)
{
static char sep[] = ":";
char *ps, *p;
+ int rc;
ps = strdupa(pathset);
for (;;) {
p = strsep(&ps, sep);
if (!p)
return 0;
- if (afb_api_so_add_path(p, apiset) < 0)
- return -1;
+ rc = afb_api_so_add_path(p, apiset, failstops);
+ if (rc < 0)
+ return rc;
}
}
+int afb_api_so_add_pathset_fails(const char *pathset, struct afb_apiset *apiset)
+{
+ return afb_api_so_add_pathset(pathset, apiset, 1);
+}
+
+int afb_api_so_add_pathset_nofails(const char *pathset, struct afb_apiset *apiset)
+{
+ return afb_api_so_add_pathset(pathset, apiset, 0);
+}
+
diff --git a/src/afb-api-so.h b/src/afb-api-so.h
index 382dad03..c831567a 100644
--- a/src/afb-api-so.h
+++ b/src/afb-api-so.h
@@ -22,10 +22,13 @@ struct afb_apiset;
extern int afb_api_so_add_binding(const char *path, struct afb_apiset *apiset);
-extern int afb_api_so_add_directory(const char *path, struct afb_apiset *apiset);
+extern int afb_api_so_add_directory(const char *path, struct afb_apiset *apiset, int failstops);
-extern int afb_api_so_add_path(const char *path, struct afb_apiset *apiset);
+extern int afb_api_so_add_path(const char *path, struct afb_apiset *apiset, int failstops);
-extern int afb_api_so_add_pathset(const char *pathset, struct afb_apiset *apiset);
+extern int afb_api_so_add_pathset(const char *pathset, struct afb_apiset *apiset, int failstops);
+
+extern int afb_api_so_add_pathset_fails(const char *pathset, struct afb_apiset *apiset);
+extern int afb_api_so_add_pathset_nofails(const char *pathset, struct afb_apiset *apiset);
diff --git a/src/main.c b/src/main.c
index dee79d86..84bdc610 100644
--- a/src/main.c
+++ b/src/main.c
@@ -592,7 +592,7 @@ static void start(int signum)
afb_debug("start-load");
apiset_start_list(config->dbus_clients, afb_api_dbus_add_client, "the afb-dbus client");
apiset_start_list(config->ws_clients, afb_api_ws_add_client, "the afb-websocket client");
- apiset_start_list(config->ldpaths, afb_api_so_add_pathset, "the binding path set");
+ apiset_start_list(config->ldpaths, afb_api_so_add_pathset_fails, "the binding path set");
apiset_start_list(config->so_bindings, afb_api_so_add_binding, "the binding");
apiset_start_list(config->dbus_servers, afb_api_dbus_add_server, "the afb-dbus service");