summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>2020-08-24 17:36:26 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-01-06 09:27:28 +0900
commitf79087dc4f45a54fda53ffafa350c18beeca9dbf (patch)
tree4b631f8fdc7dc67b4cf9d3bbcc4429eff07d70d0
parent43c8c18c5130b5d4dfdddcb0b4c61a9155f65b86 (diff)
downloadDLT-daemon-f79087dc4f45a54fda53ffafa350c18beeca9dbf.tar.gz
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 <thanh.buinguyenquoc@vn.bosch.com>
-rw-r--r--src/daemon/dlt_daemon_client.c58
1 files 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 <ctype.h>
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), (), and recv() */
+#include <sys/stat.h> /* for stat() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* 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 */