From f79087dc4f45a54fda53ffafa350c18beeca9dbf Mon Sep 17 00:00:00 2001 From: Bui Nguyen Quoc Thanh Date: Mon, 24 Aug 2020 17:36:26 +0700 Subject: dlt-daemon: complete logstorage path with '/' Currently, the logstorage device cannot be disconnected if "/" is appended at the end of path. For example: int dlt.conf, the configuration is: OfflineLogstorageDirPath = /var/log/dlt_raw Then the control message as below won't work. "dlt-logstorage-ctrl -c 0 -p /var/log/dlt_raw/" The fix is to get the information the requested mount point via stat() to ensure the path of connected/disconnected control messages are validated properly. Signed-off-by: Bui Nguyen Quoc Thanh --- src/daemon/dlt_daemon_client.c | 58 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index 941aa8c..081f524 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -29,6 +29,7 @@ #include #include /* for printf() and fprintf() */ #include /* for socket(), connect(), (), and recv() */ +#include /* for stat() */ #include /* for sockaddr_in and inet_addr() */ #include /* for atoi() and exit() */ #include /* for memset() */ @@ -2407,6 +2408,14 @@ void dlt_daemon_control_service_logstorage(int sock, int device_index = -1; int i = 0; + int tmp_errno = 0; + + struct stat daemon_mpoint_st = {0}; + int daemon_st_status = 0; + + struct stat req_mpoint_st = {0}; + int req_st_status = 0; + PRINT_FUNCTION_VERBOSE(verbose); if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL)) { @@ -2434,14 +2443,53 @@ void dlt_daemon_control_service_logstorage(int sock, req = (DltServiceOfflineLogstorage *)(msg->databuffer); + req_st_status= stat(req->mount_point, &req_mpoint_st); + + tmp_errno = errno; + + if (req_st_status < 0) { + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); + + dlt_vlog(LOG_WARNING, + "%s: Failed to stat requested mount point [%s] with error [%s]\n", + __func__, req->mount_point, strerror(tmp_errno)); + return; + } + for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) { connection_type = daemon->storage_handle[i].connection_type; - /* Check if the requested device path is already used as log storage device */ - if (strncmp(daemon->storage_handle[i].device_mount_point, - req->mount_point, strlen(req->mount_point)) == 0) { - device_index = i; - break; + memset(&daemon_mpoint_st, 0, sizeof(struct stat)); + if (strlen(daemon->storage_handle[i].device_mount_point) > 1) { + daemon_st_status = stat(daemon->storage_handle[i].device_mount_point, + &daemon_mpoint_st); + tmp_errno = errno; + + if (daemon_st_status < 0) { + dlt_daemon_control_service_response(sock, + daemon, + daemon_local, + DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, + DLT_SERVICE_RESPONSE_ERROR, + verbose); + dlt_vlog(LOG_WARNING, + "%s: Failed to stat daemon mount point [%s] with error [%s]\n", + __func__, daemon->storage_handle[i].device_mount_point, + strerror(tmp_errno)); + return; + } + + /* Check if the requested device path is already used as log storage device */ + if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev && + req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) { + device_index = i; + break; + } } /* Get first available device index here */ -- cgit v1.2.1