From 857e0426ffbf76ca2179b4632c81e470172eeef5 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 29 Jun 2013 22:10:09 +0200 Subject: procfs: fix the error handling in argp_parser Do not exit using error (1, ..) but gracefully handle the error using argp_error. Also fix a typo ("the a user") while touching these lines. * procfs/main.c (argp_parser): Proper error handling. (argp_parser): Fix typo. --- main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 3a976ccc..f33ace9a 100644 --- a/main.c +++ b/main.c @@ -48,13 +48,13 @@ argp_parser (int key, char *arg, struct argp_state *state) case 'h': opt_clk_tck = strtol (arg, &endp, 0); if (*endp || ! *arg || opt_clk_tck <= 0) - error (1, 0, "--clk-tck: HZ should be a positive integer"); + argp_error (state, "--clk-tck: HZ should be a positive integer"); break; case 's': opt_stat_mode = strtol (arg, &endp, 8); if (*endp || ! *arg || opt_stat_mode & ~07777) - error (1, 0, "--stat-mode: MODE should be an octal mode"); + argp_error (state, "--stat-mode: MODE should be an octal mode"); break; case 'S': @@ -62,7 +62,7 @@ argp_parser (int key, char *arg, struct argp_state *state) { opt_fake_self = strtol (arg, &endp, 0); if (*endp || ! *arg) - error (1, 0, "--fake-self: PID must be an integer"); + argp_error (state, "--fake-self: PID must be an integer"); } else opt_fake_self = 1; @@ -71,7 +71,7 @@ argp_parser (int key, char *arg, struct argp_state *state) case 'k': opt_kernel_pid = strtol (arg, &endp, 0); if (*endp || ! *arg || (signed) opt_kernel_pid < 0) - error (1, 0, "--kernel-process: PID must be a positive integer"); + argp_error (state, "--kernel-process: PID must be a positive integer"); break; case 'c': @@ -90,8 +90,8 @@ argp_parser (int key, char *arg, struct argp_state *state) opt_anon_owner = strtol (arg, &endp, 0); if (*endp || ! *arg || (signed) opt_anon_owner < 0) - error(1, 0, "--anonymous-owner: USER should be the a user name " - "or a numeric UID."); + argp_error (state, "--anonymous-owner: USER should be " + "a user name or a numeric UID."); break; } -- cgit v1.2.3 From b8fa4e0ea428454a59ff887e925f519a01f6294c Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 29 Jun 2013 22:13:16 +0200 Subject: procfs: keep old config values if the parsing fails Previously if strtol failed the previous configuration value would get overwritten. Prevent this by storing the result in a temporary variable and update the configuration if the argument was parsed correctly and passed the sanity checks. * procfs/main.c (argp_parser): Keep old configuration in case a malformed value is encountered. --- main.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index f33ace9a..0892d369 100644 --- a/main.c +++ b/main.c @@ -42,36 +42,45 @@ argp_parser (int key, char *arg, struct argp_state *state) { struct passwd *pw; char *endp; + long int v; switch (key) { case 'h': - opt_clk_tck = strtol (arg, &endp, 0); - if (*endp || ! *arg || opt_clk_tck <= 0) + v = strtol (arg, &endp, 0); + if (*endp || ! *arg || v <= 0) argp_error (state, "--clk-tck: HZ should be a positive integer"); + else + opt_clk_tck = v; break; case 's': - opt_stat_mode = strtol (arg, &endp, 8); - if (*endp || ! *arg || opt_stat_mode & ~07777) + v = strtol (arg, &endp, 8); + if (*endp || ! *arg || (mode_t) v & ~07777) argp_error (state, "--stat-mode: MODE should be an octal mode"); + else + opt_stat_mode = v; break; case 'S': if (arg) { - opt_fake_self = strtol (arg, &endp, 0); + v = strtol (arg, &endp, 0); if (*endp || ! *arg) argp_error (state, "--fake-self: PID must be an integer"); + else + opt_fake_self = v; } else opt_fake_self = 1; break; case 'k': - opt_kernel_pid = strtol (arg, &endp, 0); + v = strtol (arg, &endp, 0); if (*endp || ! *arg || (signed) opt_kernel_pid < 0) argp_error (state, "--kernel-process: PID must be a positive integer"); + else + opt_kernel_pid = v; break; case 'c': @@ -88,10 +97,12 @@ argp_parser (int key, char *arg, struct argp_state *state) break; } - opt_anon_owner = strtol (arg, &endp, 0); - if (*endp || ! *arg || (signed) opt_anon_owner < 0) + v = strtol (arg, &endp, 0); + if (*endp || ! *arg || v < 0) argp_error (state, "--anonymous-owner: USER should be " "a user name or a numeric UID."); + else + opt_anon_owner = v; break; } -- cgit v1.2.3 From e03fc07ab9285a8aaf0d801fc8f1f86d203f6129 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 29 Jun 2013 22:14:13 +0200 Subject: procfs: enable fsys_set_options Make procfs translators handle fsys_set_options requests by pointing netfs_runtime_argp to our argp struct. * procfs/main.c (netfs_runtime_argp): New variable. --- main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.c b/main.c index 0892d369..1b19c013 100644 --- a/main.c +++ b/main.c @@ -146,6 +146,9 @@ struct argp argp = { }, }; +/* Used by netfs_set_options to handle runtime option parsing. */ +struct argp *netfs_runtime_argp = &argp; + error_t root_make_node (struct ps_context *pc, struct node **np) { -- cgit v1.2.3