Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipe qrexec-client(-vm) --help output to stdout #179

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions agent/qrexec-client-vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,21 @@
};

_Noreturn static void usage(const char *argv0, int status) {
fprintf(stderr,
FILE *stream = status ? stderr : stdout;
fprintf(stream,

Check warning on line 116 in agent/qrexec-client-vm.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-client-vm.c#L115-L116

Added lines #L115 - L116 were not covered by tests
"usage: %s [options] target_vmname program_ident [local_program [local program arguments]]\n",
argv0);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -h, --help - print this message\n");
fprintf(stderr, " --buffer-size=BUFFER_SIZE - minimum vchan buffer size (default: 64k)\n");
fprintf(stderr, " -t, --filter-escape-chars-stdout - filter non-ASCII and control characters on stdout (default if stdout is a terminal)\n");
fprintf(stderr, " -T, --filter-escape-chars-stderr - filter non-ASCII and control characters on stderr (default if stderr is a terminal)\n");
fprintf(stderr, " --no-filter-escape-chars-stdout - opposite to --filter-escape-chars-stdout\n");
fprintf(stderr, " --no-filter-escape-chars-stderr - opposite to --filter-escape-chars-stderr\n");
fprintf(stderr, " --agent-socket=PATH - path to connect to, default: %s\n", QREXEC_AGENT_TRIGGER_PATH);
fprintf(stderr, " -p PREFIX-DATA, --prefix-data=PREFIX-DATA - send the given data before the provided stdin (can only be used once)\n");
fprintf(stderr, " --use-stdin-socket - use fd 0 (which must be socket) for both stdin and stdout\n");
alimirjamali marked this conversation as resolved.
Show resolved Hide resolved
fprintf(stream, "Options:\n");
fprintf(stream, " -h, --help - print this message\n");
fprintf(stream, " --buffer-size=BUFFER_SIZE - minimum vchan buffer size (default: 64k)\n");
fprintf(stream, " -t, --filter-escape-chars-stdout - filter non-ASCII and control characters on stdout (default if stdout is a terminal)\n");
fprintf(stream, " -T, --filter-escape-chars-stderr - filter non-ASCII and control characters on stderr (default if stderr is a terminal)\n");
fprintf(stream, " --no-filter-escape-chars-stdout - opposite to --filter-escape-chars-stdout\n");
fprintf(stream, " --no-filter-escape-chars-stderr - opposite to --filter-escape-chars-stderr\n");
fprintf(stream, " --agent-socket=PATH - path to connect to, default: %s\n",

Check warning on line 126 in agent/qrexec-client-vm.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-client-vm.c#L119-L126

Added lines #L119 - L126 were not covered by tests
QREXEC_AGENT_TRIGGER_PATH);
fprintf(stream, " -p PREFIX-DATA, --prefix-data=PREFIX-DATA - send the given data before the provided stdin (can only be used once)\n");
fprintf(stream, " --use-stdin-socket - use fd 0 (which must be socket) for both stdin and stdout\n");

Check warning on line 129 in agent/qrexec-client-vm.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-client-vm.c#L128-L129

Added lines #L128 - L129 were not covered by tests
exit(status);
}

Expand Down
24 changes: 10 additions & 14 deletions daemon/qrexec-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
{ NULL, 0, 0, 0 },
};

_Noreturn static void usage(const char *const name)
_Noreturn static void usage(const char *const name, int status)

Check warning on line 88 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L88

Added line #L88 was not covered by tests
{
fprintf(stderr,
FILE *stream = status ? stderr : stdout;
fprintf(stream,

Check warning on line 91 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L90-L91

Added lines #L90 - L91 were not covered by tests
"usage: %s [options] -d domain_name ["
"-l local_prog|"
"-c request_id,src_domain_name,src_domain_id|"
Expand All @@ -104,7 +105,7 @@
" --socket-dir=PATH - directory for qrexec socket, default: %s\n"
" --use-stdin-socket - use fd 0 (which must be socket) for both stdin and stdout\n",
name ? name : "qrexec-client", QREXEC_DAEMON_SOCKET_DIR);
exit(1);
exit(status);

Check warning on line 108 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L108

Added line #L108 was not covered by tests
}

static int parse_int(const char *str, const char *msg) {
Expand Down Expand Up @@ -173,11 +174,6 @@
bool exit_with_code = true;
int rc = QREXEC_EXIT_PROBLEM;

if (argc < 3) {
// certainly too few arguments
usage(argv[0]);
}

setup_logging("qrexec-client");

while ((opt = getopt_long(argc, argv, "hd:l:eEc:tTw:Wk", longopts, NULL)) != -1) {
Expand All @@ -197,7 +193,7 @@
case 'c':
if (request_id != NULL) {
warnx("ERROR: -c passed more than once");
usage(argv[0]);
usage(argv[0], 1);

Check warning on line 196 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L196

Added line #L196 was not covered by tests
}
parse_connect(optarg, &request_id, &src_domain_name, &src_domain_id);
break;
Expand Down Expand Up @@ -238,11 +234,11 @@
break;
case 'h':
default:
usage(argv[0]);
usage(argv[0], 0);

Check warning on line 237 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L237

Added line #L237 was not covered by tests
}
}
if (optind >= argc || !domname)
usage(argv[0]);
usage(argv[0], 1);

Check warning on line 241 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L241

Added line #L241 was not covered by tests
remote_cmdline = argv[optind];

signal(SIGPIPE, SIG_IGN);
Expand All @@ -251,18 +247,18 @@

if (just_exec + (request_id != NULL) + (local_cmdline != NULL) > 1) {
fprintf(stderr, "ERROR: only one of -e, -l, -c can be specified\n");
usage(argv[0]);
usage(argv[0], 1);

Check warning on line 250 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L250

Added line #L250 was not covered by tests
}

if ((local_cmdline != NULL) && (local_stdin_fd != 1)) {
fprintf(stderr, "ERROR: at most one of -l and --use-stdin-socket can be specified\n");
usage(argv[0]);
usage(argv[0], 1);

Check warning on line 255 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L255

Added line #L255 was not covered by tests
}

if (strcmp(domname, "dom0") == 0 || strcmp(domname, "@adminvm") == 0) {
if (request_id == NULL) {
fprintf(stderr, "ERROR: when target domain is 'dom0', -c must be specified\n");
usage(argv[0]);
usage(argv[0], 1);

Check warning on line 261 in daemon/qrexec-client.c

View check run for this annotation

Codecov / codecov/patch

daemon/qrexec-client.c#L261

Added line #L261 was not covered by tests
}
strncpy(svc_params.ident, request_id, sizeof(svc_params.ident) - 1);
svc_params.ident[sizeof(svc_params.ident) - 1] = '\0';
Expand Down