streams.c (139749) | streams.c (141466) |
---|---|
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> | 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 139749 2005-01-06 01:43:34Z imp $"); | 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> | 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> |
|
50#include <sys/un.h> 51#include <sys/domain.h> 52#include <net/if.h> 53#include <netinet/in.h> 54#include <sys/proc.h> 55#include <sys/uio.h> 56 57#include <sys/sysproto.h> --- 226 unchanged lines hidden (view full) --- 284 PROC_UNLOCK(p); 285 return ENXIO; 286} 287 288static int 289svr4_ptm_alloc(td) 290 struct thread *td; 291{ | 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{ |
292 struct proc *p = td->td_proc; | |
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"; | 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 caddr_t sg = stackgap_init(); 310 char *path = stackgap_alloc(&sg, sizeof(ptyname)); 311 struct open_args oa; 312 int l = 0, n = 0; 313 register_t fd = -1; 314 int error; | 309 struct proc *p; 310 register_t fd; 311 int error, l, n; |
315 | 312 |
316 oa.path = path; 317 oa.flags = O_RDWR; 318 oa.mode = 0; 319 | 313 fd = -1; 314 n = 0; 315 l = 0; 316 p = td->td_proc; |
320 while (fd == -1) { 321 ptyname[8] = ttyletters[l]; 322 ptyname[9] = ttynumbers[n]; 323 | 317 while (fd == -1) { 318 ptyname[8] = ttyletters[l]; 319 ptyname[9] = ttynumbers[n]; 320 |
324 if ((error = copyout(ptyname, path, sizeof(ptyname))) != 0) 325 return error; 326 327 switch (error = open(td, &oa)) { | 321 error = kern_open(td, ptyname, UIO_SYSSPACE, O_RDWR, 0); 322 switch (error) { |
328 case ENOENT: 329 case ENXIO: 330 return error; 331 case 0: 332 PROC_LOCK(p); 333 td->td_dupfd = td->td_retval[0]; 334 PROC_UNLOCK(p); 335 return ENXIO; --- 91 unchanged lines hidden --- | 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 --- |