X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so.c;h=daa353347cb5ed8f0c5cde939e9097ec68ecb3a1;hb=3bf52bb36ed428d0a7b947519fbccc7c376fd4a9;hp=ea7ffb1f928d038335d988551ab671b35918f478;hpb=2a2a9835cfe31a495020c79b0eeadbddb70f52ae;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so.c b/src/afb-api-so.c index ea7ffb1f..daa35334 100644 --- a/src/afb-api-so.c +++ b/src/afb-api-so.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 "IoT.bzh" + * Copyright (C) 2016, 2017 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -32,12 +33,11 @@ #include #include -#include "session.h" +#include "afb-session.h" #include "afb-common.h" #include "afb-context.h" #include "afb-apis.h" #include "afb-api-so.h" -#include "afb-sig-handler.h" #include "afb-thread.h" #include "afb-evt.h" #include "afb-svc.h" @@ -182,23 +182,18 @@ static int call_check(struct afb_req req, struct afb_context *context, const str return 1; } -static void call_cb(void *closure, struct afb_req req, struct afb_context *context, const char *strverb, size_t lenverb) +static void call_cb(void *closure, struct afb_req req, struct afb_context *context, const char *strverb) { const struct afb_verb_desc_v1 *verb; struct api_so_desc *desc = closure; verb = desc->binding->v1.verbs; - while (verb->name && (strncasecmp(verb->name, strverb, lenverb) || verb->name[lenverb])) + while (verb->name && strcasecmp(verb->name, strverb)) verb++; if (!verb->name) - afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, strverb, desc->binding->v1.prefix); + afb_req_fail_f(req, "unknown-verb", "verb %s unknown within api %s", strverb, desc->binding->v1.prefix); else if (call_check(req, context, verb)) { - if (0) - /* not threaded */ - afb_sig_req_timeout(req, verb->callback, api_timeout); - else - /* threaded */ - afb_thread_call(req, verb->callback, api_timeout, desc); + afb_thread_req_call(req, verb->callback, api_timeout, desc); } } @@ -350,7 +345,7 @@ error: static int adddirs(char path[PATH_MAX], size_t end) { DIR *dir; - struct dirent ent, *result; + struct dirent *dent; size_t len; /* open the DIR now */ @@ -365,29 +360,34 @@ static int adddirs(char path[PATH_MAX], size_t end) if (end) path[end++] = '/'; for (;;) { - readdir_r(dir, &ent, &result); - if (result == NULL) + errno = 0; + dent = readdir(dir); + if (dent == NULL) { + if (errno != 0) + ERROR("read error while scanning directory %.*s: %m", (int)(end - 1), path); break; + } - len = strlen(ent.d_name); + len = strlen(dent->d_name); if (len + end >= PATH_MAX) { - ERROR("path too long while scanning bindings for %s", ent.d_name); + ERROR("path too long while scanning bindings for %s", dent->d_name); continue; } - memcpy(&path[end], ent.d_name, len+1); - if (ent.d_type == DT_DIR) { + if (dent->d_type == DT_DIR) { /* case of directories */ - if (ent.d_name[0] == '.') { + if (dent->d_name[0] == '.') { if (len == 1) continue; - if (ent.d_name[1] == '.' && len == 2) + if (dent->d_name[1] == '.' && len == 2) continue; } + memcpy(&path[end], dent->d_name, len+1); adddirs(path, end+len);; - } else if (ent.d_type == DT_REG) { + } else if (dent->d_type == DT_REG) { /* case of files */ - if (!strstr(ent.d_name, ".so")) + if (memcmp(&dent->d_name[len - 3], ".so", 4)) continue; + memcpy(&path[end], dent->d_name, len+1); if (afb_api_so_add_binding(path) < 0) return -1; }