From 86fa115e9e49541b9e15813c33e9940065e2d6e1 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Thu, 26 Nov 2015 11:12:56 +0900 Subject: Logstorage: Check if given path is writable in logstorage control application Signed-off-by: Christoph Lipka --- src/console/logstorage/dlt-logstorage-common.c | 23 +++++++++++++++++++++++ src/console/logstorage/dlt-logstorage-common.h | 8 ++++++++ src/console/logstorage/dlt-logstorage-ctrl.c | 6 ++++++ 3 files changed, 37 insertions(+) (limited to 'src/console') diff --git a/src/console/logstorage/dlt-logstorage-common.c b/src/console/logstorage/dlt-logstorage-common.c index a2f60a0..592da25 100644 --- a/src/console/logstorage/dlt-logstorage-common.c +++ b/src/console/logstorage/dlt-logstorage-common.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -234,6 +235,28 @@ int dlt_logstorage_check_config_file(char *mnt_point) return ret; } +/** @brief Check if given mount point is writable + * + * @param mnt_point The mount point to check + * + * @return 1 if the file is writable, 0 otherwise. + */ +int dlt_logstorage_check_directory_permission(char *mnt_point) +{ + if (mnt_point == NULL) + { + pr_error("Given mount point is NULL\n"); + return 0; + } + + if (access(mnt_point, W_OK) == 0) + { + return 1; + } + + return 0; +} + /** @brief Prepares the body of the message to be send to DLT * * @param body A pointer to the MsgBody structure pointer diff --git a/src/console/logstorage/dlt-logstorage-common.h b/src/console/logstorage/dlt-logstorage-common.h index 712f2e3..a1c0994 100644 --- a/src/console/logstorage/dlt-logstorage-common.h +++ b/src/console/logstorage/dlt-logstorage-common.h @@ -80,4 +80,12 @@ int dlt_logstorage_send_event(int, char *); */ int dlt_logstorage_check_config_file(char *); +/** @brief Check if given mount point is writable + * + * @param mnt_point The mount point to check + * + * @return 1 if the file is writable, 0 otherwise. + */ +int dlt_logstorage_check_directory_permission(char *mnt_point); + #endif diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c index b4d2b92..b213501 100644 --- a/src/console/logstorage/dlt-logstorage-ctrl.c +++ b/src/console/logstorage/dlt-logstorage-ctrl.c @@ -374,6 +374,12 @@ static int dlt_logstorage_ctrl_single_request() return -1; } + if (!dlt_logstorage_check_directory_permission(get_default_path())) + { + pr_error("'%s' is not writable\n", get_default_path()); + return -1; + } + /* Initializing the communication with the daemon */ while (dlt_control_init(analyze_response, get_ecuid(), get_verbosity()) && !dlt_logstorage_must_exit()) -- cgit v1.2.1