| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Licensed under the GPL | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | #include <fcntl.h>
 | 
					
						
							| 
									
										
										
										
											2012-10-08 03:27:32 +01:00
										 |  |  | #include <kern_util.h>
 | 
					
						
							|  |  |  | #include <os.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct grantpt_info { | 
					
						
							|  |  |  | 	int fd; | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void grantpt_cb(void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct grantpt_info *info = arg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	info->res = grantpt(info->fd); | 
					
						
							|  |  |  | 	info->err = errno; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int get_pty(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct grantpt_info info; | 
					
						
							| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | 	int fd, err; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fd = open("/dev/ptmx", O_RDWR); | 
					
						
							|  |  |  | 	if (fd < 0) { | 
					
						
							|  |  |  | 		err = -errno; | 
					
						
							|  |  |  | 		printk(UM_KERN_ERR "get_pty : Couldn't open /dev/ptmx - " | 
					
						
							|  |  |  | 		       "err = %d\n", errno); | 
					
						
							|  |  |  | 		return err; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	info.fd = fd; | 
					
						
							|  |  |  | 	initial_thread_cb(grantpt_cb, &info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | 	if (info.res < 0) { | 
					
						
							|  |  |  | 		err = -info.err; | 
					
						
							|  |  |  | 		printk(UM_KERN_ERR "get_pty : Couldn't grant pty - " | 
					
						
							|  |  |  | 		       "errno = %d\n", -info.err); | 
					
						
							|  |  |  | 		goto out; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (unlockpt(fd) < 0) { | 
					
						
							|  |  |  | 		err = -errno; | 
					
						
							|  |  |  | 		printk(UM_KERN_ERR "get_pty : Couldn't unlock pty - " | 
					
						
							|  |  |  | 		       "errno = %d\n", errno); | 
					
						
							|  |  |  | 		goto out; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-04 22:30:46 -08:00
										 |  |  | 	return fd; | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	close(fd); | 
					
						
							|  |  |  | 	return err; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } |