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