1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

ptyfwd: Add --read-only option

This commit is contained in:
Daan De Meyer 2025-01-03 19:40:45 +01:00
parent 83154c8995
commit 276890d629
2 changed files with 17 additions and 1 deletions

View File

@ -74,6 +74,14 @@
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
</varlistentry>
<varlistentry>
<term><option>--read-only</option></term>
<listitem><para>Do not accept any user input on standard input.</para>
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help"/>
<xi:include href="standard-options.xml" xpointer="version"/>
</variablelist>

View File

@ -13,6 +13,7 @@
#include "strv.h"
static bool arg_quiet = false;
static bool arg_read_only = false;
static char *arg_background = NULL;
static char *arg_title = NULL;
@ -33,6 +34,7 @@ static int help(void) {
" -h --help Show this help\n"
" --version Print version\n"
" -q --quiet Suppress information messages during runtime\n"
" --read-only Do not accept any user input on stdin\n"
" --background=COLOR Set ANSI color for background\n"
" --title=TITLE Set terminal title\n"
"\nSee the %2$s for details.\n",
@ -49,6 +51,7 @@ static int help(void) {
static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
ARG_READ_ONLY,
ARG_BACKGROUND,
ARG_TITLE,
};
@ -57,6 +60,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "quiet", no_argument, NULL, 'q' },
{ "read-only", no_argument, NULL, ARG_READ_ONLY },
{ "background", required_argument, NULL, ARG_BACKGROUND },
{ "title", required_argument, NULL, ARG_TITLE },
{}
@ -81,6 +85,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_quiet = true;
break;
case ARG_READ_ONLY:
arg_read_only = true;
break;
case ARG_BACKGROUND:
r = free_and_strdup_warn(&arg_background, optarg);
if (r < 0)
@ -161,7 +169,7 @@ static int run(int argc, char *argv[]) {
if (!arg_quiet)
log_info("Press ^] three times within 1s to disconnect TTY.");
r = pty_forward_new(event, pty_fd, /*flags=*/ 0, &forward);
r = pty_forward_new(event, pty_fd, arg_read_only ? PTY_FORWARD_READ_ONLY : 0, &forward);
if (r < 0)
return log_error_errno(r, "Failed to create PTY forwarder: %m");