Make ttynvt_param global struct and avoid secondary variables

This commit is contained in:
Kim Woelders
2018-06-28 13:02:02 +02:00
parent 8956f3f851
commit 7a424bc10d
+20 -25
View File
@@ -30,12 +30,19 @@
#include "telnet.h" #include "telnet.h"
#define RX_BUF_SIZE 1024 #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 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 { typedef struct ttynvt {
int nonblock; int nonblock;
pthread_mutex_t tty_lock; pthread_mutex_t tty_lock;
@@ -331,7 +338,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
return; return;
} }
sockfd = ttynvt_connect(host_name, host_port); sockfd = ttynvt_connect(ttynvt_param.host, ttynvt_param.port);
if (sockfd < 0) if (sockfd < 0)
{ {
free(tty->tn); free(tty->tn);
@@ -378,7 +385,8 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
info->nonseekable = 1; info->nonseekable = 1;
info->direct_io = 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); 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 } #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[] = { static const struct fuse_opt ttynvt_opts[] = {
TTYNET_OPT("-M %u", major, 1), 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[]) int main(int argc, char *argv[])
{ {
struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct ttynvt_param param = { 0 };
char dev_name[128] = { 0 }; char dev_name[128] = { 0 };
const char *dev_info_argv[] = { dev_name }; const char *dev_info_argv[] = { dev_name };
if (fuse_opt_parse(&args, &param, ttynvt_opts, process_arg)) if (fuse_opt_parse(&args, &ttynvt_param, ttynvt_opts, process_arg))
{ {
fprintf(stderr, "Failed to parse arguments\n"); fprintf(stderr, "Failed to parse arguments\n");
return 1; return 1;
} }
snprintf(dev_name, sizeof(dev_name), "DEVNAME=%s", 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); if (ttynvt_param.logfile)
host_port = param.port;
if (param.logfile)
{ {
lfd = lfd =
open(param.logfile, O_CREAT | O_RDWR | O_APPEND, open(ttynvt_param.logfile, O_CREAT | O_RDWR | O_APPEND,
S_IWUSR | S_IRUSR); S_IWUSR | S_IRUSR);
if (lfd < 0) if (lfd < 0)
{ {
@@ -860,14 +855,14 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
ttynvt_log("ttynvt ver:%s started, dev:%s\n", ttynvt_log("ttynvt ver:%s started, dev:%s\n",
PACKAGE_VERSION, param.dev_name); PACKAGE_VERSION, ttynvt_param.dev_name);
} }
else else
lfd = -1; lfd = -1;
struct cuse_info ci = { struct cuse_info ci = {
.dev_major = param.major, .dev_major = ttynvt_param.major,
.dev_minor = param.minor, .dev_minor = ttynvt_param.minor,
.dev_info_argc = 1, .dev_info_argc = 1,
.dev_info_argv = dev_info_argv, .dev_info_argv = dev_info_argv,
.flags = CUSE_UNRESTRICTED_IOCTL, .flags = CUSE_UNRESTRICTED_IOCTL,