Files
gui/macos/DModem/PtySpawn.c
T
Claude 8b2ba3e58c Remote page on macOS: SSH by /usr/bin/ssh on a pty, Telnet and rlogin on a socket; the docs
The terminal view now takes any TerminalHost (the modem, or a remote
login), so both pages draw with the same view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRSV65geuGd6zMt2V6r
2026-11-12 12:28:13 +00:00

43 lines
963 B
C

/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (C) 2026 D-Modem Authors
*
* PtySpawn.c - a program started on a new pty, for the Remote page's ssh
*/
#include <fcntl.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <util.h>
#include "PtySpawn.h"
int dm_pty_spawn(const char *path, const char *const *argv, const char *term,
int cols, int rows, pid_t *pid)
{
struct winsize ws = { 0 };
ws.ws_col = (unsigned short)cols;
ws.ws_row = (unsigned short)rows;
int fd;
pid_t p = forkpty(&fd, NULL, NULL, &ws);
if (p < 0)
return -1;
if (p == 0) {
setenv("TERM", term, 1);
execv(path, (char *const *)argv);
_exit(127);
}
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
fcntl(fd, F_SETFD, FD_CLOEXEC);
*pid = p;
return fd;
}
void dm_pty_resize(int fd, int cols, int rows)
{
struct winsize ws = { 0 };
ws.ws_col = (unsigned short)cols;
ws.ws_row = (unsigned short)rows;
ioctl(fd, TIOCSWINSZ, &ws);
}