From 7a424bc10ddf6edf75b06dfcce48309f6ead3b52 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Thu, 28 Jun 2018 13:02:02 +0200 Subject: [PATCH] Make ttynvt_param global struct and avoid secondary variables --- ttynvt.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/ttynvt.c b/ttynvt.c index 43e87b0..0eaf66c 100644 --- a/ttynvt.c +++ b/ttynvt.c @@ -30,12 +30,19 @@ #include "telnet.h" #define RX_BUF_SIZE 1024 -#define MAX_HOST_NAME 64 -static char host_name[MAX_HOST_NAME]; -static int host_port; + static int lfd; +static struct ttynvt_param { + unsigned int major; + unsigned int minor; + char *dev_name; + char *logfile; + char *host; + unsigned int port; +} ttynvt_param; + typedef struct ttynvt { int nonblock; pthread_mutex_t tty_lock; @@ -331,7 +338,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info) return; } - sockfd = ttynvt_connect(host_name, host_port); + sockfd = ttynvt_connect(ttynvt_param.host, ttynvt_param.port); if (sockfd < 0) { free(tty->tn); @@ -378,7 +385,8 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info) info->nonseekable = 1; info->direct_io = 1; - ttynvt_log("open connection to server: %s:%d\n", host_name, host_port); + ttynvt_log("open connection to server: %s:%d\n", + ttynvt_param.host, ttynvt_param.port); fuse_reply_open(req, info); } @@ -776,14 +784,6 @@ static const struct cuse_lowlevel_ops ttynvt_op = { }; #define TTYNET_OPT(t, p, v) { t, offsetof(struct ttynvt_param, p), v } -struct ttynvt_param { - unsigned int major; - unsigned int minor; - char *dev_name; - char *logfile; - char *host; - unsigned int port; -}; static const struct fuse_opt ttynvt_opts[] = { TTYNET_OPT("-M %u", major, 1), @@ -831,28 +831,23 @@ process_arg(void *data, const char *arg, int key, struct fuse_args *outargs) int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - struct ttynvt_param param = { 0 }; char dev_name[128] = { 0 }; const char *dev_info_argv[] = { dev_name }; - if (fuse_opt_parse(&args, ¶m, ttynvt_opts, process_arg)) + if (fuse_opt_parse(&args, &ttynvt_param, ttynvt_opts, process_arg)) { fprintf(stderr, "Failed to parse arguments\n"); return 1; } snprintf(dev_name, sizeof(dev_name), "DEVNAME=%s", - param.dev_name ? param.dev_name : "ttyNVT0"); + ttynvt_param.dev_name ? ttynvt_param.dev_name : "ttyNVT0"); - snprintf(host_name, sizeof(host_name), "%s", param.host); - - host_port = param.port; - - if (param.logfile) + if (ttynvt_param.logfile) { lfd = - open(param.logfile, O_CREAT | O_RDWR | O_APPEND, + open(ttynvt_param.logfile, O_CREAT | O_RDWR | O_APPEND, S_IWUSR | S_IRUSR); if (lfd < 0) { @@ -860,14 +855,14 @@ int main(int argc, char *argv[]) return 1; } ttynvt_log("ttynvt ver:%s started, dev:%s\n", - PACKAGE_VERSION, param.dev_name); + PACKAGE_VERSION, ttynvt_param.dev_name); } else lfd = -1; struct cuse_info ci = { - .dev_major = param.major, - .dev_minor = param.minor, + .dev_major = ttynvt_param.major, + .dev_minor = ttynvt_param.minor, .dev_info_argc = 1, .dev_info_argv = dev_info_argv, .flags = CUSE_UNRESTRICTED_IOCTL,