1/*- 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1994 Christos Zoulas 4 * Copyright (c) 1997 Todd Vierling 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 19 unchanged lines hidden (view full) --- 28 * 29 * Stolen from NetBSD /sys/compat/svr4/svr4_net.c. Pseudo-device driver 30 * skeleton produced from /usr/share/examples/drivers/make_pseudo_driver.sh 31 * in 3.0-980524-SNAP then hacked a bit (but probably not enough :-). 32 * 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/dev/streams/streams.c 141466 2005-02-07 18:22:20Z jhb $"); |
37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/kernel.h> /* SYSINIT stuff */ 41#include <sys/conf.h> /* cdevsw stuff */ 42#include <sys/malloc.h> /* malloc region definitions */ 43#include <sys/file.h> 44#include <sys/filedesc.h> 45#include <sys/unistd.h> 46#include <sys/fcntl.h> 47#include <sys/socket.h> 48#include <sys/protosw.h> 49#include <sys/socketvar.h> |
50#include <sys/syscallsubr.h> |
51#include <sys/un.h> 52#include <sys/domain.h> 53#include <net/if.h> 54#include <netinet/in.h> 55#include <sys/proc.h> 56#include <sys/uio.h> 57 58#include <sys/sysproto.h> --- 226 unchanged lines hidden (view full) --- 285 PROC_UNLOCK(p); 286 return ENXIO; 287} 288 289static int 290svr4_ptm_alloc(td) 291 struct thread *td; 292{ |
293 /* 294 * XXX this is very, very ugly. But I can't find a better 295 * way that won't duplicate a big amount of code from 296 * sys_open(). Ho hum... 297 * 298 * Fortunately for us, Solaris (at least 2.5.1) makes the 299 * /dev/ptmx open automatically just open a pty, that (after 300 * STREAMS I_PUSHes), is just a plain pty. fstat() is used 301 * to get the minor device number to map to a tty. 302 * 303 * Cycle through the names. If sys_open() returns ENOENT (or 304 * ENXIO), short circuit the cycle and exit. 305 */ 306 static char ptyname[] = "/dev/ptyXX"; 307 static char ttyletters[] = "pqrstuwxyzPQRST"; 308 static char ttynumbers[] = "0123456789abcdef"; |
309 struct proc *p; 310 register_t fd; 311 int error, l, n; |
312 |
313 fd = -1; 314 n = 0; 315 l = 0; 316 p = td->td_proc; |
317 while (fd == -1) { 318 ptyname[8] = ttyletters[l]; 319 ptyname[9] = ttynumbers[n]; 320 |
321 error = kern_open(td, ptyname, UIO_SYSSPACE, O_RDWR, 0); 322 switch (error) { |
323 case ENOENT: 324 case ENXIO: 325 return error; 326 case 0: 327 PROC_LOCK(p); 328 td->td_dupfd = td->td_retval[0]; 329 PROC_UNLOCK(p); 330 return ENXIO; --- 91 unchanged lines hidden --- |