Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 */
5
6#include <stdlib.h>
7#include <unistd.h>
8#include <errno.h>
9#include <fcntl.h>
10#include <kern_util.h>
11#include <os.h>
12
13struct grantpt_info {
14 int fd;
15 int res;
16 int err;
17};
18
19static void grantpt_cb(void *arg)
20{
21 struct grantpt_info *info = arg;
22
23 info->res = grantpt(info->fd);
24 info->err = errno;
25}
26
27int get_pty(void)
28{
29 struct grantpt_info info;
30 int fd, err;
31
32 fd = open("/dev/ptmx", O_RDWR);
33 if (fd < 0) {
34 err = -errno;
35 printk(UM_KERN_ERR "get_pty : Couldn't open /dev/ptmx - "
36 "err = %d\n", errno);
37 return err;
38 }
39
40 info.fd = fd;
41 initial_thread_cb(grantpt_cb, &info);
42
43 if (info.res < 0) {
44 err = -info.err;
45 printk(UM_KERN_ERR "get_pty : Couldn't grant pty - "
46 "errno = %d\n", -info.err);
47 goto out;
48 }
49
50 if (unlockpt(fd) < 0) {
51 err = -errno;
52 printk(UM_KERN_ERR "get_pty : Couldn't unlock pty - "
53 "errno = %d\n", errno);
54 goto out;
55 }
56 return fd;
57out:
58 close(fd);
59 return err;
60}
1/*
2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
6#include <stdlib.h>
7#include <unistd.h>
8#include <errno.h>
9#include <fcntl.h>
10#include "kern_constants.h"
11#include "kern_util.h"
12#include "os.h"
13#include "user.h"
14
15struct grantpt_info {
16 int fd;
17 int res;
18 int err;
19};
20
21static void grantpt_cb(void *arg)
22{
23 struct grantpt_info *info = arg;
24
25 info->res = grantpt(info->fd);
26 info->err = errno;
27}
28
29int get_pty(void)
30{
31 struct grantpt_info info;
32 int fd, err;
33
34 fd = open("/dev/ptmx", O_RDWR);
35 if (fd < 0) {
36 err = -errno;
37 printk(UM_KERN_ERR "get_pty : Couldn't open /dev/ptmx - "
38 "err = %d\n", errno);
39 return err;
40 }
41
42 info.fd = fd;
43 initial_thread_cb(grantpt_cb, &info);
44
45 if (info.res < 0) {
46 err = -info.err;
47 printk(UM_KERN_ERR "get_pty : Couldn't grant pty - "
48 "errno = %d\n", -info.err);
49 goto out;
50 }
51
52 if (unlockpt(fd) < 0) {
53 err = -errno;
54 printk(UM_KERN_ERR "get_pty : Couldn't unlock pty - "
55 "errno = %d\n", errno);
56 goto out;
57 }
58 return fd;
59out:
60 close(fd);
61 return err;
62}