summaryrefslogtreecommitdiffstats
path: root/filescan-utils.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-08 17:21:40 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:12:02 +0100
commitf9bc4d078a3e6e273b5602042220d63cdd26c0f6 (patch)
tree6c41a482b5c4cf4792cd2ba455558acedcfa9bd6 /filescan-utils.c
parent0d3acdd1ac876a1de4893d534ba6fc438045c93d (diff)
Only return binding root dir.
If subdirs path is needed then concatenation as to be done using the rootdir. Change-Id: I50a1eeb1f853ae26995a96e1661ff38cb7959f60 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'filescan-utils.c')
-rw-r--r--filescan-utils.c31
1 files changed, 5 insertions, 26 deletions
diff --git a/filescan-utils.c b/filescan-utils.c
index fe01bdc..83565b2 100644
--- a/filescan-utils.c
+++ b/filescan-utils.c
@@ -126,42 +126,21 @@ PUBLIC const char *GetBinderName() {
PUBLIC const char *GetBindingDirPath(BindingDirsT dir)
{
// A file description should not be greater than 999.999.999
- char fd[10];
- static char retdir[CONTROL_MAXPATH_LEN];
- sprintf(fd, "%d", afb_daemon_rootdir_get_fd());
- char* fd_link = malloc(strlen("/proc/self/fd/") + strlen(fd));
- strcpy(fd_link, "/proc/self/fd/");
- strcat(fd_link, fd);
+ char fd_link[CONTROL_MAXPATH_LEN];
+ char retdir[CONTROL_MAXPATH_LEN];
+ sprintf(fd_link, "/proc/self/fd/%d", afb_daemon_rootdir_get_fd());
ssize_t len;
if((len = readlink(fd_link, retdir, sizeof(retdir)-1)) == -1)
{
perror("lstat");
AFB_ERROR("Error reading stat of link: %s", fd_link);
- strcpy(retdir, "/tmp");
+ strncpy(retdir, "/tmp", 4);
}
else
{
retdir[len] = '\0';
- switch (dir) {
- case BIN_DIR:
- strcat(retdir, "/bin");
- break;
- case ETC_DIR:
- strcat(retdir, "/etc");
- break;
- case LIB_DIR:
- strcat(retdir, "/lib");
- break;
- case DATA_DIR:
- strcat(retdir, "/data");
- break;
- case HTTP_DIR:
- strcat(retdir, "/http");
- break;
- }
}
- free(fd_link);
- return retdir;
+ return strndup(retdir, sizeof(retdir));
}