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:
@@ -84,6 +84,8 @@ typedef struct {
|
||||
} ttynvt_t;
|
||||
|
||||
|
||||
static pthread_mutex_t access_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static volatile char _is_interrupted = 0;
|
||||
|
||||
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 n;
|
||||
|
||||
pthread_mutex_lock(&access_lock);
|
||||
|
||||
nvt_log(LOG_INFO, "Connecting to server: %s:%d\n",
|
||||
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",
|
||||
ttynvt_param.host, ttynvt_param.port);
|
||||
|
||||
pthread_mutex_unlock(&access_lock);
|
||||
}
|
||||
|
||||
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",
|
||||
ttynvt_param.host, ttynvt_param.port);
|
||||
|
||||
pthread_mutex_unlock(&access_lock);
|
||||
}
|
||||
|
||||
static const struct cuse_lowlevel_ops ttynvt_op = {
|
||||
|
||||
Reference in New Issue
Block a user