1 /* 2 * Copyright (c) 1993 The Regents of the University of California. 3 * Copyright (c) 1993 Jan-Simon Pendry 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Jan-Simon Pendry. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * From: 38 * Id: procfs_note.c,v 4.1 1993/12/17 10:47:45 jsp Rel 39 * 40 * $Id: procfs_note.c,v 1.3 1994/05/04 03:42:19 cgd Exp $ 41 */ 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/time.h> 46 #include <sys/kernel.h> 47 #include <sys/proc.h> 48 #include <sys/vnode.h> 49 #include <sys/signal.h> 50 #include <sys/signalvar.h> 51 #include <miscfs/procfs/procfs.h> 52 53 procfs_namemap_t procfs_signames[] = { 54 /* regular signal names */ 55 { "hup", SIGHUP }, { "int", SIGINT }, 56 { "quit", SIGQUIT }, { "ill", SIGILL }, 57 { "trap", SIGTRAP }, { "abrt", SIGABRT }, 58 { "iot", SIGIOT }, { "emt", SIGEMT }, 59 { "fpe", SIGFPE }, { "kill", SIGKILL }, 60 { "bus", SIGBUS }, { "segv", SIGSEGV }, 61 { "sys", SIGSYS }, { "pipe", SIGPIPE }, 62 { "alrm", SIGALRM }, { "term", SIGTERM }, 63 { "urg", SIGURG }, { "stop", SIGSTOP }, 64 { "tstp", SIGTSTP }, { "cont", SIGCONT }, 65 { "chld", SIGCHLD }, { "ttin", SIGTTIN }, 66 { "ttou", SIGTTOU }, { "io", SIGIO }, 67 { "xcpu", SIGXCPU }, { "xfsz", SIGXFSZ }, 68 { "vtalrm", SIGVTALRM }, { "prof", SIGPROF }, 69 { "winch", SIGWINCH }, { "info", SIGINFO }, 70 { "usr1", SIGUSR1 }, { "usr2", SIGUSR2 }, 71 { 0 }, 72 }; 73 74 pfs_readnote(sig, uio) 75 int sig; 76 struct uio *uio; 77 { 78 int xlen; 79 int error; 80 procfs_namemap_t *nm; 81 82 /* could do indexing by sig */ 83 for (nm = procfs_signames; nm->nm_name; nm++) 84 if (nm->nm_val == sig) 85 break; 86 if (!nm->nm_name) 87 panic("pfs_readnote"); 88 89 xlen = strlen(nm->nm_name); 90 if (uio->uio_resid < xlen) 91 return EMSGSIZE; 92 93 if (error = uiomove(nm->nm_name, xlen, uio)) 94 return error; 95 96 return 0; 97 } 98 99 pfs_donote(curp, p, pfs, uio) 100 struct proc *curp; 101 struct proc *p; 102 struct pfsnode *pfs; 103 struct uio *uio; 104 { 105 int len = uio->uio_resid; 106 int xlen; 107 int error; 108 char note[PROCFS_NOTELEN+1]; 109 procfs_namemap_t *nm; 110 int sig, mask; 111 112 if (pfs->pfs_type == Pnote && uio->uio_rw == UIO_READ) { 113 114 mask = p->p_sig & ~p->p_sigmask; 115 116 if (p->p_flag&P_PPWAIT) 117 mask &= ~stopsigmask; 118 if (mask == 0) 119 return 0; 120 sig = ffs((long)mask); 121 122 if (error = pfs_readnote(sig, pfs, uio)) 123 return error; 124 125 p->p_sig &= ~mask; 126 return 0; 127 } 128 129 if (uio->uio_rw != UIO_WRITE) 130 return (EINVAL); 131 132 xlen = PROCFS_NOTELEN; 133 error = procfs_getuserstr(uio, note, &xlen); 134 if (error) 135 return (error); 136 137 /* 138 * Map signal names into signal generation 139 * Unknown signals return EOPNOTSUPP. 140 */ 141 error = EOPNOTSUPP; 142 143 nm = procfs_findname(procfs_signames, note, xlen); 144 if (nm) { 145 if (pfs->pfs_type == Pnote) 146 psignal(p, nm->nm_val); 147 else 148 gsignal(p->p_pgid, nm->nm_val); 149 150 error = 0; 151 } 152 return (error); 153 } 154