procfs_ioctl.c revision 87321
1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD: head/sys/fs/procfs/procfs_ioctl.c 87321 2001-12-04 01:35:06Z des $ 29 */ 30 31#include <sys/param.h> 32#include <sys/lock.h> 33#include <sys/mutex.h> 34#include <sys/pioctl.h> 35#include <sys/proc.h> 36#include <sys/signalvar.h> 37#include <sys/systm.h> 38 39#include <fs/pseudofs/pseudofs.h> 40#include <fs/procfs/procfs.h> 41 42#ifdef PROCFS_DEBUG 43/* 44 * Process ioctls 45 */ 46int 47procfs_ioctl(PFS_IOCTL_ARGS) 48{ 49 struct procfs_status *ps; 50 int error, sig; 51 52 PROC_LOCK(p); 53 error = 0; 54 switch (cmd) { 55 case PIOCBIS: 56 p->p_stops |= *(unsigned int *)data; 57 break; 58 case PIOCBIC: 59 p->p_stops &= ~*(unsigned int *)data; 60 break; 61 case PIOCSFL: 62 /* ignore */ 63 break; 64 case PIOCGFL: 65 *(unsigned int *)data = 0; /* nope */ 66 break; 67 case PIOCWAIT: 68 while (p->p_step == 0) { 69 /* sleep until p stops */ 70 error = msleep(&p->p_stype, &p->p_mtx, 71 PWAIT|PCATCH, "pioctl", 0); 72 if (error != 0) 73 break; 74 } 75 /* fall through to PIOCSTATUS */ 76 case PIOCSTATUS: 77 ps = (struct procfs_status *)data; 78 ps->state = (p->p_step == 0); 79 ps->flags = 0; /* nope */ 80 ps->events = p->p_stops; 81 ps->why = p->p_step ? p->p_stype : 0; 82 ps->val = p->p_step ? p->p_xstat : 0; 83 break; 84 case PIOCCONT: 85 if (p->p_step) 86 break; 87 sig = *(int *)data; 88 if (!_SIG_VALID(sig)) { 89 error = EINVAL; 90 break; 91 } 92#if 0 93 mtx_lock_spin(&sched_lock); 94 p->p_step = 0; 95 if (p->p_stat == SSTOP) { 96 p->p_xstat = sig; 97 setrunnable(&p->p_thread); 98 mtx_unlock_spin(&sched_lock); 99 } else { 100 mtx_unlock_spin(&sched_lock); 101 if (sig) 102 psignal(p, sig); 103 } 104#else 105 if (sig) 106 psignal(p, sig); 107 wakeup(&p->p_step); 108#endif 109 break; 110 default: 111 error = (ENOTTY); 112 } 113 PROC_UNLOCK(p); 114 115 return (error); 116} 117 118/* 119 * Clean up on last close 120 */ 121int 122procfs_close(PFS_CLOSE_ARGS) 123{ 124 if (p != NULL && (p->p_pfsflags & PF_LINGER) == 0) { 125 p->p_pfsflags = 0; 126 p->p_stops = 0; 127 p->p_step = 0; 128 wakeup(&p->p_step); 129 } 130 return (0); 131} 132#endif 133