[libvirt] [PATCH] tools: fix regression passing command with virt-login-shell

Daniel P. Berrangé posted 1 patch 4 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190927162302.22713-1-berrange@redhat.com
There is a newer version of this series
tools/virt-login-shell.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
[libvirt] [PATCH] tools: fix regression passing command with virt-login-shell
Posted by Daniel P. Berrangé 4 years, 6 months ago
It is documented that a command to run inside the container can be
passed with the -c arg.

  virt-login-shell -c "ls -l /"

This fixes

  commit 4feeb2d986b98013ebfb1d41ab6b9007b6cce6e2
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Thu Aug 1 10:58:31 2019 +0100

    tools: split virt-login-shell into two binaries

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tools/virt-login-shell.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c
index f92cc0a749..f5aa02420b 100644
--- a/tools/virt-login-shell.c
+++ b/tools/virt-login-shell.c
@@ -38,11 +38,13 @@
 int main(int argc, char **argv) {
     char uidstr[INT_BUFSIZE_BOUND(uid_t)];
     char gidstr[INT_BUFSIZE_BOUND(gid_t)];
-    const char *const newargv[] = {
+    const char * newargv[] = {
         LIBEXECDIR "/virt-login-shell-helper",
         uidstr,
         gidstr,
         NULL,
+        NULL,
+        NULL,
     };
     char *newenv[] = {
         NULL,
@@ -60,8 +62,15 @@ int main(int argc, char **argv) {
         exit(EXIT_FAILURE);
     }
 
-    if (argc != 1) {
-        fprintf(stderr, "%s: no arguments expected\n", argv[0]);
+    if (argc == 3) {
+        if (strcmp(argv[1], "-c") != 0) {
+            fprintf(stderr, "%s: syntax: %s [-c CMDSTR]\n", argv[0], argv[0]);
+            exit(EXIT_FAILURE);
+        }
+        newargv[3] = argv[1];
+        newargv[4] = argv[2];
+    } else if (argc != 1) {
+        fprintf(stderr, "%s: syntax: %s [-c CMDSTR]\n", argv[0], argv[0]);
         exit(EXIT_FAILURE);
     }
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] tools: fix regression passing command with virt-login-shell
Posted by Peter Krempa 4 years, 6 months ago
On Fri, Sep 27, 2019 at 17:23:02 +0100, Daniel Berrange wrote:
> It is documented that a command to run inside the container can be
> passed with the -c arg.
> 
>   virt-login-shell -c "ls -l /"
> 
> This fixes
> 
>   commit 4feeb2d986b98013ebfb1d41ab6b9007b6cce6e2
>   Author: Daniel P. Berrangé <berrange@redhat.com>
>   Date:   Thu Aug 1 10:58:31 2019 +0100
> 
>     tools: split virt-login-shell into two binaries
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  tools/virt-login-shell.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)

ACK

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list