Home | History | Annotate | Line # | Download | only in sunos
sunos_misc.c revision 1.9.2.1
      1 /*
      2  * Copyright (c) 1992, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * This software was developed by the Computer Systems Engineering group
      6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      7  * contributed to Berkeley.
      8  *
      9  * All advertising materials mentioning features or use of this software
     10  * must display the following acknowledgement:
     11  *	This product includes software developed by the University of
     12  *	California, Lawrence Berkeley Laboratory.
     13  *
     14  * Redistribution and use in source and binary forms, with or without
     15  * modification, are permitted provided that the following conditions
     16  * are met:
     17  * 1. Redistributions of source code must retain the above copyright
     18  *    notice, this list of conditions and the following disclaimer.
     19  * 2. Redistributions in binary form must reproduce the above copyright
     20  *    notice, this list of conditions and the following disclaimer in the
     21  *    documentation and/or other materials provided with the distribution.
     22  * 3. All advertising materials mentioning features or use of this software
     23  *    must display the following acknowledgement:
     24  *	This product includes software developed by the University of
     25  *	California, Berkeley and its contributors.
     26  * 4. Neither the name of the University nor the names of its contributors
     27  *    may be used to endorse or promote products derived from this software
     28  *    without specific prior written permission.
     29  *
     30  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     40  * SUCH DAMAGE.
     41  *
     42  *	@(#)sun_misc.c	8.1 (Berkeley) 6/18/93
     43  *
     44  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     45  * $Id: sunos_misc.c,v 1.9.2.1 1993/11/26 12:07:43 deraadt Exp $
     46  */
     47 
     48 /*
     49  * SunOS compatibility module.
     50  *
     51  * SunOS system calls that are implemented differently in BSD are
     52  * handled here.
     53  */
     54 
     55 #include <sys/param.h>
     56 #include <sys/systm.h>
     57 #include <ufs/dir.h>
     58 #include <sys/proc.h>
     59 #include <sys/file.h>
     60 #include <sys/filedesc.h>
     61 #include <sys/ioctl.h>
     62 #include <sys/kernel.h>
     63 #include <sys/exec.h>
     64 #include <sys/malloc.h>
     65 #include <sys/mbuf.h>
     66 #include <sys/mman.h>
     67 #include <sys/mount.h>
     68 #include <sys/resource.h>
     69 #include <sys/resourcevar.h>
     70 #include <sys/signal.h>
     71 #include <sys/signalvar.h>
     72 #include <sys/socket.h>
     73 #include <sys/vnode.h>
     74 #include <sys/uio.h>
     75 #include <sys/wait.h>
     76 #include <sys/utsname.h>
     77 
     78 #include <netinet/in.h>
     79 
     80 #include <miscfs/specfs/specdev.h>
     81 
     82 #include <vm/vm.h>
     83 
     84 struct sun_wait4_args {
     85 	int	pid;
     86 	int	*status;
     87 	int	options;
     88 	struct	rusage *rusage;
     89 };
     90 sun_wait4(p, uap, retval)
     91 	struct proc *p;
     92 	struct sun_wait4_args *uap;
     93 	int *retval;
     94 {
     95 
     96 	if (uap->pid == 0)
     97 		uap->pid = WAIT_ANY;
     98 	return (wait4(p, uap, retval));
     99 }
    100 
    101 struct sun_creat_args {
    102 	char	*fname;
    103 	int	fmode;
    104 };
    105 sun_creat(p, uap, retval)
    106 	struct proc *p;
    107 	struct sun_creat_args *uap;
    108 	int *retval;
    109 {
    110 	struct args {
    111 		char	*fname;
    112 		int	mode;
    113 		int	crtmode;
    114 	} openuap;
    115 
    116 	openuap.fname = uap->fname;
    117 	openuap.crtmode = uap->fmode;
    118 	openuap.mode = O_WRONLY | O_CREAT | O_TRUNC;
    119 	return (open(p, &openuap, retval));
    120 }
    121 
    122 struct sun_execv_args {
    123 	char	*fname;
    124 	char	**argp;
    125 	char	**envp;		/* pseudo */
    126 };
    127 sun_execv(p, uap, retval)
    128 	struct proc *p;
    129 	struct sun_execv_args *uap;
    130 	int *retval;
    131 {
    132 
    133 	uap->envp = NULL;
    134 	return (execve(p, uap, retval));
    135 }
    136 
    137 struct sun_omsync_args {
    138 	caddr_t	addr;
    139 	int	len;
    140 	int	flags;
    141 };
    142 sun_omsync(p, uap, retval)
    143 	struct proc *p;
    144 	struct sun_omsync_args *uap;
    145 	int *retval;
    146 {
    147 
    148 	if (uap->flags)
    149 		return (EINVAL);
    150 	return (msync(p, uap, retval));
    151 }
    152 
    153 struct sun_unmount_args {
    154 	char	*name;
    155 	int	flags;	/* pseudo */
    156 };
    157 sun_unmount(p, uap, retval)
    158 	struct proc *p;
    159 	struct sun_unmount_args *uap;
    160 	int *retval;
    161 {
    162 
    163 	uap->flags = 0;
    164 	return (unmount(p, uap, retval));
    165 }
    166 
    167 static int
    168 gettype(tptr)
    169 	int *tptr;
    170 {
    171 	int type, error;
    172 	char in[20];
    173 
    174 	if (error = copyinstr((caddr_t)*tptr, in, sizeof in, (u_int *)0))
    175 		return (error);
    176 	if (strcmp(in, "4.2") == 0 || strcmp(in, "ufs") == 0)
    177 		type = MOUNT_UFS;
    178 	else if (strcmp(in, "nfs") == 0)
    179 		type = MOUNT_NFS;
    180 	else
    181 		return (EINVAL);
    182 	*tptr = type;
    183 	return (0);
    184 }
    185 
    186 #define	SUNM_RDONLY	0x01	/* mount fs read-only */
    187 #define	SUNM_NOSUID	0x02	/* mount fs with setuid disallowed */
    188 #define	SUNM_NEWTYPE	0x04	/* type is string (char *), not int */
    189 #define	SUNM_GRPID	0x08	/* (bsd semantics; ignored) */
    190 #define	SUNM_REMOUNT	0x10	/* update existing mount */
    191 #define	SUNM_NOSUB	0x20	/* prevent submounts (rejected) */
    192 #define	SUNM_MULTI	0x40	/* (ignored) */
    193 #define	SUNM_SYS5	0x80	/* Sys 5-specific semantics (rejected) */
    194 
    195 struct	sun_nfs_args {
    196 	struct	sockaddr_in *addr;	/* file server address */
    197 	caddr_t	fh;			/* file handle to be mounted */
    198 	int	flags;			/* flags */
    199 	int	wsize;			/* write size in bytes */
    200 	int	rsize;			/* read size in bytes */
    201 	int	timeo;			/* initial timeout in .1 secs */
    202 	int	retrans;		/* times to retry send */
    203 	char	*hostname;		/* server's hostname */
    204 	int	acregmin;		/* attr cache file min secs */
    205 	int	acregmax;		/* attr cache file max secs */
    206 	int	acdirmin;		/* attr cache dir min secs */
    207 	int	acdirmax;		/* attr cache dir max secs */
    208 	char	*netname;		/* server's netname */
    209 	struct	pathcnf *pathconf;	/* static pathconf kludge */
    210 };
    211 
    212 struct sun_mount_args {
    213 	int	type;
    214 	char	*dir;
    215 	int	flags;
    216 	caddr_t	data;
    217 };
    218 sun_mount(p, uap, retval)
    219 	struct proc *p;
    220 	struct sun_mount_args *uap;
    221 	int *retval;
    222 {
    223 	int oflags = uap->flags, nflags, error;
    224 	extern char sigcode[], esigcode[];
    225 #define	szsigcode	(esigcode - sigcode)
    226 
    227 	if (oflags & (SUNM_NOSUB | SUNM_SYS5))
    228 		return (EINVAL);
    229 	if (oflags & SUNM_NEWTYPE && (error = gettype(&uap->type)))
    230 		return (error);
    231 	nflags = 0;
    232 	if (oflags & SUNM_RDONLY)
    233 		nflags |= MNT_RDONLY;
    234 	if (oflags & SUNM_NOSUID)
    235 		nflags |= MNT_NOSUID;
    236 	if (oflags & SUNM_REMOUNT)
    237 		nflags |= MNT_UPDATE;
    238 	uap->flags = nflags;
    239 
    240 	if (uap->type == MOUNT_NFS) {
    241 		struct sun_nfs_args sna;
    242 		struct sockaddr_in sain;
    243 		struct nfs_args na;
    244 		struct sockaddr sa;
    245 
    246 		if (error = copyin(uap->data, &sna, sizeof sna))
    247 			return (error);
    248 		if (error = copyin(sna.addr, &sain, sizeof sain))
    249 			return (error);
    250 		bcopy(&sain, &sa, sizeof sa);
    251 		sa.sa_len = sizeof(sain);
    252 		uap->data = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
    253 		na.addr = (struct sockaddr *)((int)uap->data + sizeof na);
    254 		na.sotype = SOCK_DGRAM;
    255 		na.proto = IPPROTO_UDP;
    256 		na.fh = (nfsv2fh_t *)sna.fh;
    257 		na.flags = sna.flags;
    258 		na.wsize = sna.wsize;
    259 		na.rsize = sna.rsize;
    260 		na.timeo = sna.timeo;
    261 		na.retrans = sna.retrans;
    262 		na.hostname = sna.hostname;
    263 
    264 		if (error = copyout(&sa, na.addr, sizeof sa))
    265 			return (error);
    266 		if (error = copyout(&na, uap->data, sizeof na))
    267 			return (error);
    268 	}
    269 	return (mount(p, uap, retval));
    270 }
    271 
    272 struct sun_sigpending_args {
    273 	int	*mask;
    274 };
    275 sun_sigpending(p, uap, retval)
    276 	struct proc *p;
    277 	struct sun_sigpending_args *uap;
    278 	int *retval;
    279 {
    280 	int mask = p->p_sig & p->p_sigmask;
    281 
    282 	return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int)));
    283 }
    284 
    285 /* XXX: Temporary until sys/dir.h, include/dirent.h and sys/dirent.h are fixed */
    286 struct dirent {
    287 	u_long	d_fileno;		/* file number of entry */
    288 	u_short	d_reclen;		/* length of this record */
    289 	u_short	d_namlen;		/* length of string in d_name */
    290 	char	d_name[255 + 1];	/* name must be no longer than this */
    291 };
    292 
    293 /*
    294  * Here is the sun layout.  (Compare the BSD layout in <sys/dirent.h>.)
    295  * We can assume big-endian, so the BSD d_type field is just the high
    296  * byte of the SunOS d_namlen field, after adjusting for the extra "long".
    297  */
    298 struct sun_dirent {
    299 	long	d_off;
    300 	u_long	d_fileno;
    301 	u_short	d_reclen;
    302 	u_short	d_namlen;
    303 	char	d_name[256];
    304 };
    305 
    306 /*
    307  * Read Sun-style directory entries.  We suck them into kernel space so
    308  * that they can be massaged before being copied out to user code.  Like
    309  * SunOS, we squish out `empty' entries.
    310  *
    311  * This is quite ugly, but what do you expect from compatibility code?
    312  */
    313 struct sun_getdents_args {
    314 	int	fd;
    315 	char	*buf;
    316 	int	nbytes;
    317 };
    318 sun_getdents(p, uap, retval)
    319 	struct proc *p;
    320 	register struct sun_getdents_args *uap;
    321 	int *retval;
    322 {
    323 	register struct vnode *vp;
    324 	register caddr_t inp, buf;	/* BSD-format */
    325 	register int len, reclen;	/* BSD-format */
    326 	register caddr_t outp;		/* Sun-format */
    327 	register int resid;		/* Sun-format */
    328 	struct file *fp;
    329 	struct uio auio;
    330 	struct iovec aiov;
    331 	off_t off;			/* true file offset */
    332 	long soff;			/* Sun file offset */
    333 	int buflen, error, eofflag;
    334 #define	BSD_DIRENT(cp) ((struct dirent *)(cp))
    335 #define	SUN_RECLEN(reclen) (reclen + sizeof(long))
    336 
    337 	if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0)
    338 		return (error);
    339 	if ((fp->f_flag & FREAD) == 0)
    340 		return (EBADF);
    341 	vp = (struct vnode *)fp->f_data;
    342 	if (vp->v_type != VDIR)	/* XXX  vnode readdir op should do this */
    343 		return (EINVAL);
    344 	buflen = min(MAXBSIZE, uap->nbytes);
    345 	buf = malloc(buflen, M_TEMP, M_WAITOK);
    346 	VOP_LOCK(vp);
    347 	off = fp->f_offset;
    348 again:
    349 	aiov.iov_base = buf;
    350 	aiov.iov_len = buflen;
    351 	auio.uio_iov = &aiov;
    352 	auio.uio_iovcnt = 1;
    353 	auio.uio_rw = UIO_READ;
    354 	auio.uio_segflg = UIO_SYSSPACE;
    355 	auio.uio_procp = p;
    356 	auio.uio_resid = buflen;
    357 	auio.uio_offset = off;
    358 	/*
    359 	 * First we read into the malloc'ed buffer, then
    360 	 * we massage it into user space, one record at a time.
    361 	 */
    362 	if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL, 0))
    363 		goto out;
    364 	inp = buf;
    365 	outp = uap->buf;
    366 	resid = uap->nbytes;
    367 	if ((len = buflen - auio.uio_resid) == 0)
    368 		goto eof;
    369 	for (; len > 0; len -= reclen) {
    370 		reclen = ((struct dirent *)inp)->d_reclen;
    371 		if (reclen & 3)
    372 			panic("sun_getdents");
    373 		off += reclen;		/* each entry points to next */
    374 		if (BSD_DIRENT(inp)->d_fileno == 0) {
    375 			inp += reclen;	/* it is a hole; squish it out */
    376 			continue;
    377 		}
    378 		if (reclen > len || resid < SUN_RECLEN(reclen)) {
    379 			/* entry too big for buffer, so just stop */
    380 			outp++;
    381 			break;
    382 		}
    383 		/*
    384 		 * Massage in place to make a Sun-shaped dirent (otherwise
    385 		 * we have to worry about touching user memory outside of
    386 		 * the copyout() call).
    387 		 */
    388 		BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen);
    389 #if notdef
    390 		BSD_DIRENT(inp)->d_type = 0; 	/* 4.4 specific */
    391 #endif
    392 		soff = off;
    393 		if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
    394 		    (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
    395 			goto out;
    396 		/* advance past this real entry */
    397 		inp += reclen;
    398 		/* advance output past Sun-shaped entry */
    399 		outp += SUN_RECLEN(reclen);
    400 		resid -= SUN_RECLEN(reclen);
    401 	}
    402 	/* if we squished out the whole block, try again */
    403 	if (outp == uap->buf)
    404 		goto again;
    405 	fp->f_offset = off;		/* update the vnode offset */
    406 eof:
    407 	*retval = uap->nbytes - resid;
    408 out:
    409 	VOP_UNLOCK(vp);
    410 	free(buf, M_TEMP);
    411 	return (error);
    412 }
    413 
    414 /*
    415  * The Sun bit-style arguments are not in the same order as the
    416  * NetBSD ones. We must remap them the bits.
    417  */
    418 
    419 #if defined(sparc)
    420 #define	DEVZERO	makedev(3, 12)		/* major,minor of /dev/zero */
    421 #endif
    422 #if defined(sun3) || defined(amiga) || defined(mac) || defined(hp300)
    423 #define	DEVZERO	makedev(2, 12)		/* major,minor of /dev/zero */
    424 #endif
    425 
    426 #define SUN_PROT_READ	1
    427 #define SUN_PROT_WRITE	2
    428 #define SUN_PROT_EXEC	4
    429 #define SUN_PROT_UALL	(SUN_PROT_READ | SUN_PROT_WRITE | SUN_PROT_EXEC)
    430 
    431 #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    432 
    433 #define SUN_MAP_SHARED	1
    434 #define SUN_MAP_PRIVATE	2
    435 #define	SUN_MAP_TYPE	0xf
    436 #define SUN_MAP_FIXED	0x10
    437 
    438 struct sun_mmap_args {
    439 	caddr_t	addr;
    440 	size_t	len;
    441 	int	prot;
    442 	int	flags;
    443 	int	fd;
    444 	off_t	off;
    445 };
    446 sun_mmap(p, uap, retval)
    447 	register struct proc *p;
    448 	register struct sun_mmap_args *uap;
    449 	int *retval;
    450 {
    451 	register int flags, prot, newflags, newprot;
    452 	register struct filedesc *fdp;
    453 	register struct file *fp;
    454 	register struct vnode *vp;
    455 
    456 	/*
    457 	 * Verify and re-map the arguments.
    458 	 */
    459 	prot = uap->prot;
    460 	newprot = 0;
    461 	if (uap->prot & ~SUN_PROT_UALL)
    462 		return (EINVAL);
    463 	if (uap->prot & SUN_PROT_READ)
    464 		newprot |= PROT_READ;
    465 	if (uap->prot & SUN_PROT_WRITE)
    466 		newprot |= PROT_WRITE;
    467 	if (uap->prot & SUN_PROT_EXEC)
    468 		newprot |= PROT_EXEC;
    469 
    470 	flags = uap->flags;
    471 	newflags = 0;
    472 	if ((flags & SUN__MAP_NEW) == 0)
    473 		return (EINVAL);
    474 
    475 	switch (flags & SUN_MAP_TYPE) {
    476 	case SUN_MAP_SHARED:
    477 		newflags |= MAP_SHARED;
    478 		break;
    479 	case SUN_MAP_PRIVATE:
    480 		newflags |= MAP_PRIVATE;
    481 		break;
    482 	default:
    483 		return (EINVAL);
    484 	}
    485 
    486 	if (flags & SUN_MAP_FIXED)
    487 		newflags |= MAP_FIXED;
    488 
    489 	/*
    490 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    491 	 */
    492 	fdp = p->p_fd;
    493 	if ((unsigned)uap->fd < fdp->fd_nfiles &&			/*XXX*/
    494 	    (fp = fdp->fd_ofiles[uap->fd]) != NULL &&			/*XXX*/
    495 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    496 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    497 	    vp->v_rdev == DEVZERO) {					/*XXX*/
    498 		newflags |= MAP_ANON;
    499 		uap->fd = -1;
    500 	} else
    501 		newflags |= MAP_FILE;
    502 
    503 	/* All done, fix up fields and go. */
    504 	uap->flags = newflags;
    505 	uap->prot = newprot;
    506 	return (smmap(p, uap, retval));
    507 }
    508 
    509 #define	MC_SYNC		1
    510 #define	MC_LOCK		2
    511 #define	MC_UNLOCK	3
    512 #define	MC_ADVISE	4
    513 #define	MC_LOCKAS	5
    514 #define	MC_UNLOCKAS	6
    515 
    516 struct sun_mctl_args {
    517 	caddr_t	addr;
    518 	size_t	len;
    519 	int	func;
    520 	void	*arg;
    521 };
    522 sun_mctl(p, uap, retval)
    523 	register struct proc *p;
    524 	register struct sun_mctl_args *uap;
    525 	int *retval;
    526 {
    527 
    528 	switch (uap->func) {
    529 
    530 	case MC_ADVISE:		/* ignore for now */
    531 		return (0);
    532 
    533 	case MC_SYNC:		/* translate to msync */
    534 		return (msync(p, uap, retval));
    535 
    536 	default:
    537 		return (EINVAL);
    538 	}
    539 }
    540 
    541 struct sun_setsockopt_args {
    542 	int	s;
    543 	int	level;
    544 	int	name;
    545 	caddr_t	val;
    546 	int	valsize;
    547 };
    548 sun_setsockopt(p, uap, retval)
    549 	struct proc *p;
    550 	register struct sun_setsockopt_args *uap;
    551 	int *retval;
    552 {
    553 	struct file *fp;
    554 	struct mbuf *m = NULL;
    555 	int error;
    556 
    557 	if (error = getsock(p->p_fd, uap->s, &fp))
    558 		return (error);
    559 #define	SO_DONTLINGER (~SO_LINGER)
    560 	if (uap->name == SO_DONTLINGER) {
    561 		m = m_get(M_WAIT, MT_SOOPTS);
    562 		if (m == NULL)
    563 			return (ENOBUFS);
    564 		mtod(m, struct linger *)->l_onoff = 0;
    565 		m->m_len = sizeof(struct linger);
    566 		return (sosetopt((struct socket *)fp->f_data, uap->level,
    567 		    SO_LINGER, m));
    568 	}
    569 	if (uap->valsize > MLEN)
    570 		return (EINVAL);
    571 	if (uap->val) {
    572 		m = m_get(M_WAIT, MT_SOOPTS);
    573 		if (m == NULL)
    574 			return (ENOBUFS);
    575 		if (error = copyin(uap->val, mtod(m, caddr_t),
    576 		    (u_int)uap->valsize)) {
    577 			(void) m_free(m);
    578 			return (error);
    579 		}
    580 		m->m_len = uap->valsize;
    581 	}
    582 	return (sosetopt((struct socket *)fp->f_data, uap->level,
    583 	    uap->name, m));
    584 }
    585 
    586 struct sun_fchroot_args {
    587 	int	fdes;
    588 };
    589 sun_fchroot(p, uap, retval)
    590 	register struct proc *p;
    591 	register struct sun_fchroot_args *uap;
    592 	int *retval;
    593 {
    594 	register struct filedesc *fdp = p->p_fd;
    595 	register struct vnode *vp;
    596 	struct file *fp;
    597 	int error;
    598 
    599 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    600 		return (error);
    601 	if ((error = getvnode(fdp, uap->fdes, &fp)) != 0)
    602 		return (error);
    603 	vp = (struct vnode *)fp->f_data;
    604 	VOP_LOCK(vp);
    605 	if (vp->v_type != VDIR)
    606 		error = ENOTDIR;
    607 	else
    608 		error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
    609 	VOP_UNLOCK(vp);
    610 	if (error)
    611 		return (error);
    612 	VREF(vp);
    613 	if (fdp->fd_rdir != NULL)
    614 		vrele(fdp->fd_rdir);
    615 	fdp->fd_rdir = vp;
    616 	return (0);
    617 }
    618 
    619 /*
    620  * XXX: This needs cleaning up.
    621  */
    622 sun_auditsys(...)
    623 {
    624 	return 0;
    625 }
    626 
    627 struct sun_utsname {
    628 	char    sysname[9];
    629 	char    nodename[9];
    630 	char    nodeext[65-9];
    631 	char    release[9];
    632 	char    version[9];
    633 	char    machine[9];
    634 };
    635 
    636 struct sun_uname_args {
    637 	struct sun_utsname *name;
    638 };
    639 sun_uname(p, uap, retval)
    640 	struct proc *p;
    641 	struct sun_uname_args *uap;
    642 	int *retval;
    643 {
    644 	struct sun_utsname sut;
    645 
    646 	/* first update utsname just as with NetBSD uname() */
    647 	bcopy(hostname, utsname.nodename, sizeof(utsname.nodename));
    648 	utsname.nodename[sizeof(utsname.nodename)-1] = '\0';
    649 
    650 	/* then copy it over into SunOS struct utsname */
    651 	bzero(&sut, sizeof(sut));
    652 	bcopy(utsname.sysname, sut.sysname, sizeof(sut.sysname) - 1);
    653 	bcopy(utsname.nodename, sut.nodename, sizeof(sut.nodename) - 1);
    654 	bcopy(utsname.release, sut.release, sizeof(sut.release) - 1);
    655 	bcopy(utsname.version, sut.version, sizeof(sut.version) - 1);
    656 	bcopy(utsname.machine, sut.machine, sizeof(sut.machine) - 1);
    657 
    658 	return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname));
    659 }
    660 
    661 struct sun_setpgid_args {
    662 	int	pid;	/* target process id */
    663 	int	pgid;	/* target pgrp id */
    664 };
    665 int
    666 sun_setpgid(p, uap, retval)
    667 	struct proc *p;
    668 	struct sun_setpgid_args *uap;
    669 	int *retval;
    670 {
    671 	/*
    672 	 * difference to our setpgid call is to include backwards
    673 	 * compatibility to pre-setsid() binaries. Do setsid()
    674 	 * instead of setpgid() in those cases where the process
    675 	 * tries to create a new session the old way.
    676 	 */
    677 	if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid))
    678 		return setsid(p, uap, retval);
    679 	else
    680 		return setpgid(p, uap, retval);
    681 }
    682 
    683 struct sun_open_args {
    684 	char	*fname;
    685 	int	fmode;
    686 	int	crtmode;
    687 };
    688 sun_open(p, uap, retval)
    689 	struct proc *p;
    690 	struct sun_open_args *uap;
    691 	int *retval;
    692 {
    693 	int l, r;
    694 	int noctty = uap->fmode & 0x8000;
    695 	int ret;
    696 
    697 	/* convert mode into NetBSD mode */
    698 	l = uap->fmode;
    699 	r =	(l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
    700 	r |=	((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
    701 	r |=	((l & 0x0080) ? O_SHLOCK : 0);
    702 	r |=	((l & 0x0100) ? O_EXLOCK : 0);
    703 	r |=	((l & 0x2000) ? O_FSYNC : 0);
    704 
    705 	uap->fmode = r;
    706 	ret = open(p, uap, retval);
    707 
    708 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & SCTTY)) {
    709 		struct filedesc *fdp = p->p_fd;
    710 		struct file *fp = fdp->fd_ofiles[*retval];
    711 
    712 		/* ignore any error, just give it a try */
    713 		if (fp->f_type == DTYPE_VNODE)
    714 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
    715 	}
    716 	return ret;
    717 }
    718