mailing list of musl libc
 help / color / mirror / code / Atom feed
9eab7a37953ecf27afcf97543808ad4e82d7e6d8 blob 1332 bytes (raw)

 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
68
 
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <pty.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>

/* Nonstandard, but vastly superior to the standard functions */

int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struct winsize *ws)
{
	int m, s = -1, cs;
	char buf[20];

	m = open("/dev/ptmx", O_RDWR|O_NOCTTY);
	if (m < 0) return -1;

	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);

	if (!name) name = buf;

#ifdef TIOCGPTPEER
	int ret;

	/* Try to allocate slave fd solely based on the master fd in case the
	 * kernel supports it.
	 */
	s = ioctl(m, TIOCGPTPEER, O_RDWR|O_NOCTTY);
	if (s < 0)
		goto fail;

	/* Check the contents of the symlink in case devpts has been mounted in
	 * a non-standard location.
	 */
	ret = ttyname_r(s, name, sizeof buf);
	if (ret)
		goto fail;

	if (strncmp(name, "/dev/pts/", 9))
		goto fail;
#else
	int n = 0;

	if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n))
		goto fail;

	snprintf(name, sizeof buf, "/dev/pts/%d", n);
	s = open(name, O_RDWR|O_NOCTTY);
	if (s < 0)
		goto fail;
#endif

	if (tio) tcsetattr(s, TCSANOW, tio);
	if (ws) ioctl(s, TIOCSWINSZ, ws);

	*pm = m;
	*ps = s;

	pthread_setcancelstate(cs, 0);
	return 0;
fail:
	close(m);
	if (s >= 0)
		close(s);
	pthread_setcancelstate(cs, 0);
	return -1;
}
debug log:

solving 9eab7a37 ...
found 9eab7a37 in https://inbox.vuxu.org/musl/20170901153558.29715-2-christian.brauner@ubuntu.com/
found c1074060 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 c10740606111778c16b1d6c3dd3adb5a791240b6	src/misc/openpty.c

applying [1/1] https://inbox.vuxu.org/musl/20170901153558.29715-2-christian.brauner@ubuntu.com/
diff --git a/src/misc/openpty.c b/src/misc/openpty.c
index c1074060..9eab7a37 100644

Checking patch src/misc/openpty.c...
Applied patch src/misc/openpty.c cleanly.

index at:
100644 9eab7a37953ecf27afcf97543808ad4e82d7e6d8	src/misc/openpty.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).