Skip to contentSkip to conversation

ksmbd-tools: add missing long option in adduser/addshare/control

PATCH Superseded Namjae Jeon 2 participants 3 messages Jun 2, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Namjae Jeon

author maintainer
#0 lore raw

PATCH 1/1 ksmbd-tools: add missing long option in adduser/addshare/control

Add missing long option in adduser/addshare/control.

---
 addshare/addshare.c | 11 ++++++++++-
 adduser/adduser.c   | 12 +++++++++++-
 control/control.c   |  9 ++++++++-
 3 files changed, 29 insertions(+), 3 deletions(-)
addshare/addshare.c +10 -1
index 4d25047..a8ba71a 100644
@@ -54,6 +54,15 @@ static void usage(void)
 	exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+	{"add-share",		required_argument,	NULL,	'a' },
+	{"del-share",		required_argument,	NULL,	'd' },
+	{"update-share",	required_argument,	NULL,	'u' },
+	{"options",		required_argument,	NULL,	'o' },
+	{"version",		no_argument,		NULL,	'V' },
+	{"verbose",		no_argument,		NULL,	'v' },
+};
+
 static void show_version(void)
 {
 	printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -102,7 +111,7 @@ int main(int argc, char *argv[])
 	set_logger_app_name("ksmbd.addshare");
 
 	opterr = 0;
-	while ((c = getopt(argc, argv, "c:a:d:u:p:o:Vvh")) != EOF)
+	while ((c = getopt_long(argc, argv, "c:a:d:u:p:o:Vvh", opts, NULL)) != EOF)
 		switch (c) {
 		case 'a':
 			arg_name = g_ascii_strdown(optarg, strlen(optarg));
adduser/adduser.c +11 -1
index 88b12db..60a059d 100644
@@ -50,6 +50,16 @@ static void usage(void)
 	exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+	{"add-user",		required_argument,	NULL,	'a' },
+	{"del-user",		required_argument,	NULL,	'd' },
+	{"update-user",		required_argument,	NULL,	'u' },
+	{"password",		required_argument,	NULL,	'p' },
+	{"import-users",	required_argument,	NULL,	'i' },
+	{"version",		no_argument,		NULL,	'V' },
+	{"verbose",		no_argument,		NULL,	'v' },
+};
+
 static void show_version(void)
 {
 	printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -102,7 +112,7 @@ int main(int argc, char *argv[])
 	set_logger_app_name("ksmbd.adduser");
 
 	opterr = 0;
-	while ((c = getopt(argc, argv, "c:i:a:d:u:p:Vvh")) != EOF)
+	while ((c = getopt_long(argc, argv, "c:i:a:d:u:p:Vvh", opts, NULL)) != EOF)
 		switch (c) {
 		case 'a':
 			arg_account = g_strdup(optarg);
control/control.c +8 -1
index 780a48a..3dc8c7e 100644
@@ -23,6 +23,13 @@ static void usage(void)
 	exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+	{"shutdown",		no_argument,		NULL,	's' },
+	{"debug",		required_argument,	NULL,	'd' },
+	{"ksmbd-version",	no_argument,		NULL,	'c' },
+	{"version",		no_argument,		NULL,	'V' },
+};
+
 static void show_version(void)
 {
 	printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -101,7 +108,7 @@ int main(int argc, char *argv[])
 	}
 
 	opterr = 0;
-	while ((c = getopt(argc, argv, "sd:cVh")) != EOF)
+	while ((c = getopt_long(argc, argv, "sd:cVh", opts, NULL)) != EOF)
 		switch (c) {
 		case 's':
 			ret = ksmbd_control_shutdown();
Signature · 1 line
2.25.1
#1 lore raw

Hi Namjae,

2022년 6월 2일 (목) 오전 10:14, Namjae Jeon <[email protected]>님이 작성:

Quoted 17 lines

Add missing long option in adduser/addshare/control.

---
 addshare/addshare.c | 11 ++++++++++-
 adduser/adduser.c   | 12 +++++++++++-
 control/control.c   |  9 ++++++++-
 3 files changed, 29 insertions(+), 3 deletions(-)
addshare/addshare.c +0 -0
index 4d25047..a8ba71a 100644
@@ -54,6 +54,15 @@ static void usage(void)
        exit(EXIT_FAILURE);

addshare/addshare.c static void usage(void) · line 64

Quoted 10 lines
addshare/addshare.c +8 -0
 }
 
+static const struct option opts[] = {
+       {"add-share",           required_argument,      NULL,   'a' },
+       {"del-share",           required_argument,      NULL,   'd' },
+       {"update-share",        required_argument,      NULL,   'u' },
+       {"options",             required_argument,      NULL,   'o' },
+       {"version",             no_argument,            NULL,   'V' },
+       {"verbose",             no_argument,            NULL,   'v' },
+};

We have to add the last element, {NULL, 0, NULL, 0} to avoid Segment Fault. otherwise Looks good to me.

Quoted 73 lines
addshare/addshare.c +2 -1
+
 static void show_version(void)
 {
        printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -102,7 +111,7 @@ int main(int argc, char *argv[])
        set_logger_app_name("ksmbd.addshare");
 
        opterr = 0;
-       while ((c = getopt(argc, argv, "c:a:d:u:p:o:Vvh")) != EOF)
+       while ((c = getopt_long(argc, argv, "c:a:d:u:p:o:Vvh", opts, NULL)) != EOF)
                switch (c) {
                case 'a':
                        arg_name = g_ascii_strdown(optarg, strlen(optarg));
adduser/adduser.c +11 -1
index 88b12db..60a059d 100644
@@ -50,6 +50,16 @@ static void usage(void)
        exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+       {"add-user",            required_argument,      NULL,   'a' },
+       {"del-user",            required_argument,      NULL,   'd' },
+       {"update-user",         required_argument,      NULL,   'u' },
+       {"password",            required_argument,      NULL,   'p' },
+       {"import-users",        required_argument,      NULL,   'i' },
+       {"version",             no_argument,            NULL,   'V' },
+       {"verbose",             no_argument,            NULL,   'v' },
+};
+
 static void show_version(void)
 {
        printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -102,7 +112,7 @@ int main(int argc, char *argv[])
        set_logger_app_name("ksmbd.adduser");
 
        opterr = 0;
-       while ((c = getopt(argc, argv, "c:i:a:d:u:p:Vvh")) != EOF)
+       while ((c = getopt_long(argc, argv, "c:i:a:d:u:p:Vvh", opts, NULL)) != EOF)
                switch (c) {
                case 'a':
                        arg_account = g_strdup(optarg);
control/control.c +8 -2
index 780a48a..3dc8c7e 100644
@@ -23,6 +23,13 @@ static void usage(void)
        exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+       {"shutdown",            no_argument,            NULL,   's' },
+       {"debug",               required_argument,      NULL,   'd' },
+       {"ksmbd-version",       no_argument,            NULL,   'c' },
+       {"version",             no_argument,            NULL,   'V' },
+};
+
 static void show_version(void)
 {
        printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -101,7 +108,7 @@ int main(int argc, char *argv[])
        }
 
        opterr = 0;
-       while ((c = getopt(argc, argv, "sd:cVh")) != EOF)
+       while ((c = getopt_long(argc, argv, "sd:cVh", opts, NULL)) != EOF)
                switch (c) {
                case 's':
                        ret = ksmbd_control_shutdown();
--

2.25.1

Signature · 2 lines
Thanks,
Hyunchul
author maintainer
#2 lore raw

2022-06-02 14:07 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 22 lines

Hi Namjae,

2022년 6월 2일 (목) 오전 10:14, Namjae Jeon <[email protected]>님이 작성:

Quoted 19 lines

Add missing long option in adduser/addshare/control.

---
 addshare/addshare.c | 11 ++++++++++-
 adduser/adduser.c   | 12 +++++++++++-
 control/control.c   |  9 ++++++++-
 3 files changed, 29 insertions(+), 3 deletions(-)
addshare/addshare.c +0 -0
index 4d25047..a8ba71a 100644
@@ -54,6 +54,15 @@ static void usage(void)
        exit(EXIT_FAILURE);
 }
 
Quoted 11 lines

addshare/addshare.c static void usage(void) · line 64

Quoted 8 lines
addshare/addshare.c +8 -0
+static const struct option opts[] = {
+       {"add-share",           required_argument,      NULL,   'a' },
+       {"del-share",           required_argument,      NULL,   'd' },
+       {"update-share",        required_argument,      NULL,   'u' },
+       {"options",             required_argument,      NULL,   'o' },
+       {"version",             no_argument,            NULL,   'V' },
+       {"verbose",             no_argument,            NULL,   'v' },
+};

We have to add the last element, {NULL, 0, NULL, 0} to avoid Segment Fault. otherwise Looks good to me.

Good catch. fixed it on v2.

Thanks!

Quoted 84 lines
Quoted 75 lines
addshare/addshare.c +2 -1
+
 static void show_version(void)
 {
        printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -102,7 +111,7 @@ int main(int argc, char *argv[])
        set_logger_app_name("ksmbd.addshare");
 
        opterr = 0;
-       while ((c = getopt(argc, argv, "c:a:d:u:p:o:Vvh")) != EOF)
+       while ((c = getopt_long(argc, argv, "c:a:d:u:p:o:Vvh", opts,
 NULL)) != EOF)
                switch (c) {
                case 'a':

arg_name = g_ascii_strdown(optarg,
strlen(optarg));

adduser/adduser.c +11 -1
index 88b12db..60a059d 100644
@@ -50,6 +50,16 @@ static void usage(void)
        exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+       {"add-user",            required_argument,      NULL,   'a' },
+       {"del-user",            required_argument,      NULL,   'd' },
+       {"update-user",         required_argument,      NULL,   'u' },
+       {"password",            required_argument,      NULL,   'p' },
+       {"import-users",        required_argument,      NULL,   'i' },
+       {"version",             no_argument,            NULL,   'V' },
+       {"verbose",             no_argument,            NULL,   'v' },
+};
+
 static void show_version(void)
 {
        printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -102,7 +112,7 @@ int main(int argc, char *argv[])
        set_logger_app_name("ksmbd.adduser");
 
        opterr = 0;
-       while ((c = getopt(argc, argv, "c:i:a:d:u:p:Vvh")) != EOF)
+       while ((c = getopt_long(argc, argv, "c:i:a:d:u:p:Vvh", opts,
 NULL)) != EOF)
                switch (c) {
                case 'a':
                        arg_account = g_strdup(optarg);
control/control.c +8 -1
index 780a48a..3dc8c7e 100644
@@ -23,6 +23,13 @@ static void usage(void)
        exit(EXIT_FAILURE);
 }
 
+static const struct option opts[] = {
+       {"shutdown",            no_argument,            NULL,   's' },
+       {"debug",               required_argument,      NULL,   'd' },
+       {"ksmbd-version",       no_argument,            NULL,   'c' },
+       {"version",             no_argument,            NULL,   'V' },
+};
+
 static void show_version(void)
 {
        printf("ksmbd-tools version : %s\n", KSMBD_TOOLS_VERSION);
@@ -101,7 +108,7 @@ int main(int argc, char *argv[])
        }
 
        opterr = 0;
-       while ((c = getopt(argc, argv, "sd:cVh")) != EOF)
+       while ((c = getopt_long(argc, argv, "sd:cVh", opts, NULL)) !=
 EOF)
                switch (c) {
                case 's':
                        ret = ksmbd_control_shutdown();
Quoted 3 lines

--
2.25.1

--
Thanks,
Hyunchul