ktrace.2: Add description of kern.ktrace_suid
[dragonfly.git] / lib / libc / sys / ktrace.2
1 .\" Copyright (c) 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)ktrace.2    8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/sys/ktrace.2,v 1.9.2.7 2001/12/14 18:34:01 ru Exp $
34 .\" $DragonFly: src/lib/libc/sys/ktrace.2,v 1.4 2008/10/16 08:15:18 swildner Exp $
35 .\"
36 .Dd November 15, 2009
37 .Dt KTRACE 2
38 .Os
39 .Sh NAME
40 .Nm ktrace
41 .Nd process tracing
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In sys/param.h
46 .In sys/time.h
47 .In sys/uio.h
48 .In sys/ktrace.h
49 .Ft int
50 .Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid"
51 .Sh DESCRIPTION
52 The
53 .Fn ktrace
54 function enables or disables tracing of one or more processes.
55 Users may only trace their own processes.
56 By default only the super-user can trace setuid or setgid programs.
57 This restriction can be removed by setting the sysctl
58 .Va kern.ktrace_suid
59 to a non-zero value.
60 .Pp
61 The
62 .Fa tracefile
63 gives the pathname of the file to be used for tracing.
64 The file must exist and be a regular file writable by the calling process.
65 All trace records are always appended to the file,
66 so the file must be truncated to zero length to discard
67 previous trace data.
68 If tracing points are being disabled (see KTROP_CLEAR below),
69 .Fa tracefile
70 may be NULL.
71 .Pp
72 The
73 .Fa ops
74 parameter specifies the requested ktrace operation.
75 The defined operations are:
76 .Bl -column KTRFLAG_DESCENDXXX -offset indent
77 .It "KTROP_SET  Enable trace points specified in"
78 .Fa trpoints .
79 .It "KTROP_CLEAR        Disable trace points specified in"
80 .Fa trpoints .
81 .It "KTROP_CLEARFILE    Stop all tracing."
82 .It "KTRFLAG_DESCEND    The tracing change should apply to the"
83 specified process and all its current children.
84 .El
85 .Pp
86 The
87 .Fa trpoints
88 parameter specifies the trace points of interest.
89 The defined trace points are:
90 .Bl -column KTRFAC_SYSCALLXXX -offset indent
91 .It "KTRFAC_SYSCALL     Trace system calls."
92 .It "KTRFAC_SYSRET      Trace return values from system calls."
93 .It "KTRFAC_NAMEI       Trace name lookup operations."
94 .It "KTRFAC_GENIO       Trace all I/O (note that this option can"
95 generate much output).
96 .It "KTRFAC_PSIG        Trace posted signals."
97 .It "KTRFAC_CSW Trace context switch points."
98 .It "KTRFAC_INHERIT     Inherit tracing to future children."
99 .El
100 .Pp
101 Each tracing event outputs a record composed of a generic header
102 followed by a trace point specific structure.
103 The generic header is:
104 .Bd -literal
105 struct ktr_header {
106         int     ktr_len;                /* length of buf */
107         short   ktr_type;               /* trace record type */
108         pid_t   ktr_pid;                /* process id */
109         char    ktr_comm[MAXCOMLEN+1];  /* command name */
110         struct  timeval ktr_time;       /* timestamp */
111         caddr_t ktr_buf;
112 };
113 .Ed
114 .Pp
115 The
116 .Va ktr_len
117 field specifies the length of the
118 .Va ktr_type
119 data that follows this header.
120 The
121 .Va ktr_pid
122 and
123 .Va ktr_comm
124 fields specify the process and command generating the record.
125 The
126 .Va ktr_time
127 field gives the time (with microsecond resolution)
128 that the record was generated.
129 The
130 .Va ktr_buf
131 is an internal kernel pointer and is not useful.
132 .Pp
133 The generic header is followed by
134 .Va ktr_len
135 bytes of a
136 .Va ktr_type
137 record.
138 The type specific records are defined in the
139 .In sys/ktrace.h
140 include file.
141 .Sh RETURN VALUES
142 .Rv -std ktrace
143 .Sh ERRORS
144 .Fn Ktrace
145 will fail if:
146 .Bl -tag -width Er
147 .It Bq Er ENOTDIR
148 A component of the path prefix is not a directory.
149 .It Bq Er ENAMETOOLONG
150 A component of a pathname exceeded 255 characters,
151 or an entire path name exceeded 1023 characters.
152 .It Bq Er ENOENT
153 The named tracefile does not exist.
154 .It Bq Er EACCES
155 Search permission is denied for a component of the path prefix.
156 .It Bq Er ELOOP
157 Too many symbolic links were encountered in translating the pathname.
158 .It Bq Er EIO
159 An I/O error occurred while reading from or writing to the file system.
160 .It Bq Er ENOSYS
161 The kernel was not compiled with
162 .Nm
163 support.
164 .El
165 .Sh SEE ALSO
166 .Xr kdump 1 ,
167 .Xr ktrace 1 ,
168 .Xr utrace 2
169 .Sh HISTORY
170 A
171 .Fn ktrace
172 function call first appeared in
173 .Bx 4.4 .