mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
tools: fix regression passing command with virt-login-shell
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 4feeb2d986
Author: Daniel P. Berrangé <berrange@redhat.com>
Date: Thu Aug 1 10:58:31 2019 +0100
tools: split virt-login-shell into two binaries
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
0ad9f12e75
commit
f4e1ef9d39
2
cfg.mk
2
cfg.mk
@ -1353,4 +1353,4 @@ exclude_file_name_regexp--sc_prohibit_dirent_d_type = \
|
|||||||
^(src/util/vircgroup.c)$
|
^(src/util/vircgroup.c)$
|
||||||
|
|
||||||
exclude_file_name_regexp--sc_prohibit_strcmp = \
|
exclude_file_name_regexp--sc_prohibit_strcmp = \
|
||||||
^(tools/nss/libvirt_nss.*\.c)
|
^(tools/nss/libvirt_nss.*\.c|tools/virt-login-shell\.c)
|
||||||
|
@ -38,12 +38,8 @@
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char uidstr[INT_BUFSIZE_BOUND(uid_t)];
|
char uidstr[INT_BUFSIZE_BOUND(uid_t)];
|
||||||
char gidstr[INT_BUFSIZE_BOUND(gid_t)];
|
char gidstr[INT_BUFSIZE_BOUND(gid_t)];
|
||||||
const char *const newargv[] = {
|
const char * newargv[6];
|
||||||
LIBEXECDIR "/virt-login-shell-helper",
|
size_t nargs = 0;
|
||||||
uidstr,
|
|
||||||
gidstr,
|
|
||||||
NULL,
|
|
||||||
};
|
|
||||||
char *newenv[] = {
|
char *newenv[] = {
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@ -60,10 +56,23 @@ int main(int argc, char **argv) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 1) {
|
newargv[nargs++] = LIBEXECDIR "/virt-login-shell-helper";
|
||||||
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);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
newargv[nargs++] = argv[1];
|
||||||
|
newargv[nargs++] = argv[2];
|
||||||
|
} else if (argc != 1) {
|
||||||
|
fprintf(stderr, "%s: syntax: %s [-c CMDSTR]\n", argv[0], argv[0]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
newargv[nargs++] = uidstr;
|
||||||
|
newargv[nargs++] = gidstr;
|
||||||
|
newargv[nargs++] = NULL;
|
||||||
|
|
||||||
|
assert(nargs <= (sizeof(newargv)/sizeof(newargv[0])));
|
||||||
|
|
||||||
if (term &&
|
if (term &&
|
||||||
asprintf(&(newenv[0]), "TERM=%s", term) < 0) {
|
asprintf(&(newenv[0]), "TERM=%s", term) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user