[libvirt PATCH 1/6] virt-ssh-helper: Don't use optind

Andrea Bolognani posted 6 patches 4 years, 2 months ago
There is a newer version of this series
[libvirt PATCH 1/6] virt-ssh-helper: Don't use optind
Posted by Andrea Bolognani 4 years, 2 months ago
It's a getopt interface and we're not using getopt, at least
directly, so even though it works relying on it feels wrong.

GOption takes care of removing any trace of the arguments it
consumes from argc and argv, leaving behind only non-option
arguments, so we can just use those standard variables.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/remote/remote_ssh_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c
index 0945b90331..092676dd74 100644
--- a/src/remote/remote_ssh_helper.c
+++ b/src/remote/remote_ssh_helper.c
@@ -395,12 +395,12 @@ int main(int argc, char **argv)
     /* Initialize the log system */
     virLogSetFromEnv();
 
-    if (optind != (argc - 1)) {
+    if (argc != 2) {
         g_printerr("%s: expected a URI\n", argv[0]);
         exit(EXIT_FAILURE);
     }
 
-    uri_str = argv[optind];
+    uri_str = argv[1];
     VIR_DEBUG("Using URI %s", uri_str);
 
     if (!(uri = virURIParse(uri_str))) {
-- 
2.31.1

Re: [libvirt PATCH 1/6] virt-ssh-helper: Don't use optind
Posted by Ján Tomko 4 years, 2 months ago
On a Friday in 2021, Andrea Bolognani wrote:
>It's a getopt interface and we're not using getopt, at least
>directly, so even though it works relying on it feels wrong.
>
>GOption takes care of removing any trace of the arguments it
>consumes from argc and argv, leaving behind only non-option
>arguments, so we can just use those standard variables.
>
>Signed-off-by: Andrea Bolognani <abologna@redhat.com>
>---
> src/remote/remote_ssh_helper.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano