]> granicus.if.org Git - strace/blob - term.c
Enhance capget and capset syscalls decoding
[strace] / term.c
1 /*
2  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
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  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  *      $Id$
28  */
29
30 #include "defs.h"
31
32 /*
33  * The C library's definition of struct termios might differ from
34  * the kernel one, and we need to use the kernel layout.
35  */
36 #include <linux/termios.h>
37
38 #ifdef HAVE_SYS_FILIO_H
39 #include <sys/filio.h>
40 #endif
41
42 static const struct xlat tcxonc_options[] = {
43         { TCOOFF,       "TCOOFF"        },
44         { TCOON,        "TCOON"         },
45         { TCIOFF,       "TCIOFF"        },
46         { TCION,        "TCION"         },
47         { 0,            NULL            },
48 };
49
50 #ifdef TCLFLSH
51 static const struct xlat tcflsh_options[] = {
52         { TCIFLUSH,     "TCIFLUSH"      },
53         { TCOFLUSH,     "TCOFLUSH"      },
54         { TCIOFLUSH,    "TCIOFLUSH"     },
55         { 0,            NULL            },
56 };
57 #endif
58
59 static const struct xlat baud_options[] = {
60         { B0,           "B0"            },
61         { B50,          "B50"           },
62         { B75,          "B75"           },
63         { B110,         "B110"          },
64         { B134,         "B134"          },
65         { B150,         "B150"          },
66         { B200,         "B200"          },
67         { B300,         "B300"          },
68         { B600,         "B600"          },
69         { B1200,        "B1200"         },
70         { B1800,        "B1800"         },
71         { B2400,        "B2400"         },
72         { B4800,        "B4800"         },
73         { B9600,        "B9600"         },
74 #ifdef B19200
75         { B19200,       "B19200"        },
76 #endif
77 #ifdef B38400
78         { B38400,       "B38400"        },
79 #endif
80 #ifdef B57600
81         { B57600,       "B57600"        },
82 #endif
83 #ifdef B115200
84         { B115200,      "B115200"       },
85 #endif
86 #ifdef B230400
87         { B230400,      "B230400"       },
88 #endif
89 #ifdef B460800
90         { B460800,      "B460800"       },
91 #endif
92 #ifdef B500000
93         { B500000,      "B500000"       },
94 #endif
95 #ifdef B576000
96         { B576000,      "B576000"       },
97 #endif
98 #ifdef B921600
99         { B921600,      "B921600"       },
100 #endif
101 #ifdef B1000000
102         { B1000000,     "B1000000"      },
103 #endif
104 #ifdef B1152000
105         { B1152000,     "B1152000"      },
106 #endif
107 #ifdef B1500000
108         { B1500000,     "B1500000"      },
109 #endif
110 #ifdef B2000000
111         { B2000000,     "B2000000"      },
112 #endif
113 #ifdef B2500000
114         { B2500000,     "B2500000"      },
115 #endif
116 #ifdef B3000000
117         { B3000000,     "B3000000"      },
118 #endif
119 #ifdef B3500000
120         { B3500000,     "B3500000"      },
121 #endif
122 #ifdef B4000000
123         { B4000000,     "B4000000"      },
124 #endif
125 #ifdef EXTA
126         { EXTA,         "EXTA"          },
127 #endif
128 #ifdef EXTB
129         { EXTB,         "EXTB"          },
130 #endif
131         { 0,            NULL            },
132 };
133
134 static const struct xlat modem_flags[] = {
135 #ifdef TIOCM_LE
136         { TIOCM_LE,     "TIOCM_LE",     },
137 #endif
138 #ifdef TIOCM_DTR
139         { TIOCM_DTR,    "TIOCM_DTR",    },
140 #endif
141 #ifdef TIOCM_RTS
142         { TIOCM_RTS,    "TIOCM_RTS",    },
143 #endif
144 #ifdef TIOCM_ST
145         { TIOCM_ST,     "TIOCM_ST",     },
146 #endif
147 #ifdef TIOCM_SR
148         { TIOCM_SR,     "TIOCM_SR",     },
149 #endif
150 #ifdef TIOCM_CTS
151         { TIOCM_CTS,    "TIOCM_CTS",    },
152 #endif
153 #ifdef TIOCM_CAR
154         { TIOCM_CAR,    "TIOCM_CAR",    },
155 #endif
156 #ifdef TIOCM_CD
157         { TIOCM_CD,     "TIOCM_CD",     },
158 #endif
159 #ifdef TIOCM_RNG
160         { TIOCM_RNG,    "TIOCM_RNG",    },
161 #endif
162 #ifdef TIOCM_RI
163         { TIOCM_RI,     "TIOCM_RI",     },
164 #endif
165 #ifdef TIOCM_DSR
166         { TIOCM_DSR,    "TIOCM_DSR",    },
167 #endif
168         { 0,            NULL,           },
169 };
170
171 int term_ioctl(struct tcb *tcp, long code, long arg)
172 {
173         struct termios tios;
174         struct termio tio;
175         struct winsize ws;
176 #ifdef TIOCGSIZE
177         struct  ttysize ts;
178 #endif
179         int i;
180
181         if (entering(tcp))
182                 return 0;
183
184         switch (code) {
185
186         /* ioctls with termios or termio args */
187
188 #ifdef TCGETS
189         case TCGETS:
190                 if (syserror(tcp))
191                         return 0;
192         case TCSETS:
193         case TCSETSW:
194         case TCSETSF:
195                 if (!verbose(tcp) || umove(tcp, arg, &tios) < 0)
196                         return 0;
197                 if (abbrev(tcp)) {
198                         tprints(", {");
199                         printxval(baud_options, tios.c_cflag & CBAUD, "B???");
200                         tprintf(" %sopost %sisig %sicanon %secho ...}",
201                                 (tios.c_oflag & OPOST) ? "" : "-",
202                                 (tios.c_lflag & ISIG) ? "" : "-",
203                                 (tios.c_lflag & ICANON) ? "" : "-",
204                                 (tios.c_lflag & ECHO) ? "" : "-");
205                         return 1;
206                 }
207                 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
208                         (long) tios.c_iflag, (long) tios.c_oflag);
209                 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
210                         (long) tios.c_cflag, (long) tios.c_lflag);
211                 tprintf("c_line=%u, ", tios.c_line);
212                 if (!(tios.c_lflag & ICANON))
213                         tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
214                                 tios.c_cc[VMIN], tios.c_cc[VTIME]);
215                 tprintf("c_cc=\"");
216                 for (i = 0; i < NCCS; i++)
217                         tprintf("\\x%02x", tios.c_cc[i]);
218                 tprintf("\"}");
219                 return 1;
220 #endif /* TCGETS */
221
222 #ifdef TCGETA
223         case TCGETA:
224                 if (syserror(tcp))
225                         return 0;
226         case TCSETA:
227         case TCSETAW:
228         case TCSETAF:
229                 if (!verbose(tcp) || umove(tcp, arg, &tio) < 0)
230                         return 0;
231                 if (abbrev(tcp)) {
232                         tprints(", {");
233                         printxval(baud_options, tio.c_cflag & CBAUD, "B???");
234                         tprintf(" %sopost %sisig %sicanon %secho ...}",
235                                 (tio.c_oflag & OPOST) ? "" : "-",
236                                 (tio.c_lflag & ISIG) ? "" : "-",
237                                 (tio.c_lflag & ICANON) ? "" : "-",
238                                 (tio.c_lflag & ECHO) ? "" : "-");
239                         return 1;
240                 }
241                 tprintf(", {c_iflags=%#lx, c_oflags=%#lx, ",
242                         (long) tio.c_iflag, (long) tio.c_oflag);
243                 tprintf("c_cflags=%#lx, c_lflags=%#lx, ",
244                         (long) tio.c_cflag, (long) tio.c_lflag);
245                 tprintf("c_line=%u, ", tio.c_line);
246 #ifdef _VMIN
247                 if (!(tio.c_lflag & ICANON))
248                         tprintf("c_cc[_VMIN]=%d, c_cc[_VTIME]=%d, ",
249                                 tio.c_cc[_VMIN], tio.c_cc[_VTIME]);
250 #else /* !_VMIN */
251                 if (!(tio.c_lflag & ICANON))
252                         tprintf("c_cc[VMIN]=%d, c_cc[VTIME]=%d, ",
253                                 tio.c_cc[VMIN], tio.c_cc[VTIME]);
254 #endif /* !_VMIN */
255                 tprintf("c_cc=\"");
256                 for (i = 0; i < NCC; i++)
257                         tprintf("\\x%02x", tio.c_cc[i]);
258                 tprintf("\"}");
259                 return 1;
260 #endif /* TCGETA */
261
262         /* ioctls with winsize or ttysize args */
263
264 #ifdef TIOCGWINSZ
265         case TIOCGWINSZ:
266                 if (syserror(tcp))
267                         return 0;
268         case TIOCSWINSZ:
269                 if (!verbose(tcp) || umove(tcp, arg, &ws) < 0)
270                         return 0;
271                 tprintf(", {ws_row=%d, ws_col=%d, ws_xpixel=%d, ws_ypixel=%d}",
272                         ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
273                 return 1;
274 #endif /* TIOCGWINSZ */
275
276 #ifdef TIOCGSIZE
277         case TIOCGSIZE:
278                 if (syserror(tcp))
279                         return 0;
280         case TIOCSSIZE:
281                 if (!verbose(tcp) || umove(tcp, arg, &ts) < 0)
282                         return 0;
283                 tprintf(", {ts_lines=%d, ts_cols=%d}",
284                         ts.ts_lines, ts.ts_cols);
285                 return 1;
286 #endif
287
288         /* ioctls with a direct decodable arg */
289 #ifdef TCXONC
290         case TCXONC:
291                 tprints(", ");
292                 printxval(tcxonc_options, arg, "TC???");
293                 return 1;
294 #endif
295 #ifdef TCLFLSH
296         case TCFLSH:
297                 tprints(", ");
298                 printxval(tcflsh_options, arg, "TC???");
299                 return 1;
300 #endif
301 #ifdef TIOCSCTTY
302         case TIOCSCTTY:
303                 tprintf(", %ld", arg);
304                 return 1;
305 #endif
306
307         /* ioctls with an indirect parameter displayed as modem flags */
308
309 #ifdef TIOCMGET
310         case TIOCMGET:
311         case TIOCMBIS:
312         case TIOCMBIC:
313         case TIOCMSET:
314                 if (umove(tcp, arg, &i) < 0)
315                         return 0;
316                 tprints(", [");
317                 printflags(modem_flags, i, "TIOCM_???");
318                 tprints("]");
319                 return 1;
320 #endif /* TIOCMGET */
321
322         /* ioctls with an indirect parameter displayed in decimal */
323
324         case TIOCSPGRP:
325         case TIOCGPGRP:
326 #ifdef TIOCGETPGRP
327         case TIOCGETPGRP:
328 #endif
329 #ifdef TIOCSETPGRP
330         case TIOCSETPGRP:
331 #endif
332 #ifdef FIONREAD
333         case FIONREAD:
334 #endif
335         case TIOCOUTQ:
336 #ifdef FIONBIO
337         case FIONBIO:
338 #endif
339 #ifdef FIOASYNC
340         case FIOASYNC:
341 #endif
342 #ifdef FIOGETOWN
343         case FIOGETOWN:
344 #endif
345 #ifdef FIOSETOWN
346         case FIOSETOWN:
347 #endif
348 #ifdef TIOCGETD
349         case TIOCGETD:
350 #endif
351 #ifdef TIOCSETD
352         case TIOCSETD:
353 #endif
354 #ifdef TIOCPKT
355         case TIOCPKT:
356 #endif
357 #ifdef TIOCREMOTE
358         case TIOCREMOTE:
359 #endif
360 #ifdef TIOCUCNTL
361         case TIOCUCNTL:
362 #endif
363 #ifdef TIOCTCNTL
364         case TIOCTCNTL:
365 #endif
366 #ifdef TIOCSIGNAL
367         case TIOCSIGNAL:
368 #endif
369 #ifdef TIOCSSOFTCAR
370         case TIOCSSOFTCAR:
371 #endif
372 #ifdef TIOCGSOFTCAR
373         case TIOCGSOFTCAR:
374 #endif
375 #ifdef TIOCISPACE
376         case TIOCISPACE:
377 #endif
378 #ifdef TIOCISIZE
379         case TIOCISIZE:
380 #endif
381 #ifdef TIOCSINTR
382         case TIOCSINTR:
383 #endif
384 #ifdef TIOCSPTLCK
385         case TIOCSPTLCK:
386 #endif
387 #ifdef TIOCGPTN
388         case TIOCGPTN:
389 #endif
390                 tprints(", ");
391                 printnum_int(tcp, arg, "%d");
392                 return 1;
393
394         /* ioctls with an indirect parameter displayed as a char */
395
396 #ifdef TIOCSTI
397         case TIOCSTI:
398 #endif
399                 tprints(", ");
400                 printstr(tcp, arg, 1);
401                 return 1;
402
403         /* ioctls with no parameters */
404
405 #ifdef TIOCNOTTY
406         case TIOCNOTTY:
407 #endif
408 #ifdef FIOCLEX
409         case FIOCLEX:
410 #endif
411 #ifdef FIONCLEX
412         case FIONCLEX:
413 #endif
414 #ifdef TIOCCONS
415         case TIOCCONS:
416 #endif
417                 return 1;
418
419         /* ioctls which are unknown */
420
421         default:
422                 return 0;
423         }
424 }