libinput Generic way of gathering user commandline input
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m49s

This commit is contained in:
2026-03-20 18:04:26 +01:00
parent 3e44106752
commit bf1e8e8573
22 changed files with 310 additions and 202 deletions

View File

@@ -340,26 +340,15 @@ static void help (struct context* context) {
cprintf (context, "quit\n");
}
static void cmd_cancel_proc (void* arg) {
int pid = (int)(uintptr_t)arg;
uint8_t ch = 0;
for (;;) {
if (stream_read (process_get_pgid (), STREAM_IN, &ch, 1) > 0 && ch == KB_CTRL ('C'))
break;
else
sched ();
}
kill (pid);
}
struct cmd_write_proc_ctx {
int pgid;
int cancel_pid;
};
static void cmd_collect_proc (void* arg) {
#define RECV_MAX (1024 * 16)
int pgid = (int)(uintptr_t)arg;
char recv[RECV_MAX];
char recv[1024];
int n;
for (;;) {
if ((n = stream_read (pgid, STREAM_OUT, (void*)recv, sizeof (recv) - 1)) > 0)
@@ -369,6 +358,24 @@ static void cmd_collect_proc (void* arg) {
}
}
static void cmd_write_proc (void* arg) {
struct cmd_write_proc_ctx* ctx = arg;
uint8_t ch = 0;
for (;;) {
if (stream_read (process_get_pgid (), STREAM_IN, &ch, 1) > 0) {
if (ch == KB_CTRL ('C')) {
kill (ctx->cancel_pid);
return;
}
stream_write (ctx->pgid, STREAM_IN, &ch, 1);
} else {
sched ();
}
}
}
static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
if (strcmp (cmd->name, "echo") == 0) {
echo (context, cmd->args, cmd->arg_count);
@@ -442,16 +449,18 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
}
}
struct cmd_write_proc_ctx wpctx = {.pgid = pgid, .cancel_pid = pid};
struct process_data* write_pdata = process_spawn (&cmd_write_proc, (void*)&wpctx);
struct process_data* collect_pdata = process_spawn (&cmd_collect_proc, (void*)(uintptr_t)pgid);
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, (void*)(uintptr_t)pid);
exec_partial_fini (pid);
wait_for_pid (pid);
kill (write_pdata->pid);
process_data_free (write_pdata);
kill (collect_pdata->pid);
process_data_free (collect_pdata);
kill (cancel_pdata->pid);
process_data_free (cancel_pdata);
}
}