ttynvt: Add overall access lock

Different processes or threads accessing the device simultaneously or
rapidly after each other could cause problems.

Based on suggestion by Jo Luxer:
https://gitlab.com/lars-thrane-as/ttynvt/-/merge_requests/4
This commit is contained in:
Kim Woelders
2023-02-10 19:26:11 +01:00
parent cac5be0ddc
commit 8bf4b7705d
+8
View File
@@ -84,6 +84,8 @@ typedef struct {
} ttynvt_t; } ttynvt_t;
static pthread_mutex_t access_lock = PTHREAD_MUTEX_INITIALIZER;
static volatile char _is_interrupted = 0; static volatile char _is_interrupted = 0;
static void sig_handler(int sig) static void sig_handler(int sig)
@@ -437,6 +439,8 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
int res; int res;
int n; int n;
pthread_mutex_lock(&access_lock);
nvt_log(LOG_INFO, "Connecting to server: %s:%d\n", nvt_log(LOG_INFO, "Connecting to server: %s:%d\n",
ttynvt_param.host, ttynvt_param.port); ttynvt_param.host, ttynvt_param.port);
@@ -525,6 +529,8 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
nvt_log(LOG_ERR, "Connection to server: %s:%d failed: %m\n", nvt_log(LOG_ERR, "Connection to server: %s:%d failed: %m\n",
ttynvt_param.host, ttynvt_param.port); ttynvt_param.host, ttynvt_param.port);
pthread_mutex_unlock(&access_lock);
} }
static void static void
@@ -1135,6 +1141,8 @@ static void ttynvt_release(fuse_req_t req, struct fuse_file_info *info)
nvt_log(LOG_INFO, "Disconnected from server: %s:%d\n", nvt_log(LOG_INFO, "Disconnected from server: %s:%d\n",
ttynvt_param.host, ttynvt_param.port); ttynvt_param.host, ttynvt_param.port);
pthread_mutex_unlock(&access_lock);
} }
static const struct cuse_lowlevel_ops ttynvt_op = { static const struct cuse_lowlevel_ops ttynvt_op = {