aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: d4fa33cd86c9aebedca2bfc073ed452d6e78f865 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# taketty

Create a new PTY that other programs can attach to as their controlling terminal.

## Building

```bash
make
```

## Usage

### Creating a PTY

Run `taketty` to create a new PTY and forward I/O:

```bash
./taketty
```

This will:
- Create a new PTY via `/dev/ptmx`
- Configure and unlock the slave
- Put the master terminal in raw mode
- Forward stdin/stdout to the PTY master
- Print the slave path to stderr as `TAKETTY_PTY=/dev/pts/N`

### Attaching to the PTY

#### Method 1: Using the attach helper (with job control)

In another terminal, capture the PTY path and use the attach helper to exec a shell:

```bash
export TAKETTY_PTY=/dev/pts/N
./attach $TAKETTY_PTY bash
```

Or pass the command directly:

```bash
./attach /dev/pts/N bash
```

The attach helper will:
- Call `setsid()` to create a new session
- Open the slave PTY
- Use `ioctl(TIOCSCTTY)` to make it the controlling terminal
- Redirect stdin/stdout/stderr to the PTY
- Execute the specified program (or return if none specified)

#### Method 2: Source the bash script (I/O only, no job control)

If you only need I/O redirection without full job control:

```bash
export TAKETTY_PTY=/dev/pts/N
source ./attach.sh
```

Note: This method redirects file descriptors but doesn't set the controlling terminal, so signals like Ctrl+C won't work as expected.

## Architecture

- **taketty.c**: Creates PTY master, forwards I/O between stdin/stdout and master FD
- **attach.c**: Helper to attach a process to the PTY slave as controlling terminal
- **attach.sh**: Bash script for simple I/O redirection (sourcing only)