xref: /openbsd/lib/libc/gen/setproctitle.3 (revision 133306f0)
1.\"	$OpenBSD: setproctitle.3,v 1.13 2001/01/26 06:38:23 aaron Exp $
2.\"
3.\" Copyright (c) 1994, 1995 Christopher G. Demetriou
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
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. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"      This product includes software developed by Christopher G. Demetriou
17.\"	 for the NetBSD Project.
18.\" 3. The name of the author may not be used to endorse or promote products
19.\"    derived from this software without specific prior written permission
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd April 13, 1994
33.Dt SETPROCTITLE 3
34.Os
35.Sh NAME
36.Nm setproctitle
37.Nd set process title
38.Sh SYNOPSIS
39.Fd #include <stdlib.h>
40.Ft void
41.Fn setproctitle "const char *fmt" "..."
42.Sh DESCRIPTION
43The
44.Fn setproctitle
45function sets the invoking process's title.
46The process title is set to the last component of the program
47name, followed by a colon, a single space, and the formatted string specified
48by
49.Fa fmt .
50If
51.Fa fmt
52is
53.Dv NULL ,
54the colon and formatted string are omitted.
55The length of a process title is limited to 2048 bytes.
56.Sh EXAMPLES
57Set the process title to the program name, with no further information:
58.Bd -literal -offset indent
59setproctitle(NULL);
60.Ed
61.Pp
62Set the process title to the program name, an informational string,
63and the process ID:
64.Bd -literal -offset indent
65setproctitle("foo! (%d)", getpid());
66.Ed
67.Sh SEE ALSO
68.Xr ps 1 ,
69.Xr w 1 ,
70.Xr printf 3
71.Sh HISTORY
72The
73.Fn setproctitle
74function first appeared in
75.Nx 0.9a .
76.Sh CAVEATS
77It is important to never pass a string with user-supplied data as a
78format without using
79.Ql %s .
80An attacker can put format specifiers in the string to mangle your stack,
81leading to a possible security hole.
82This holds true even if you have built the string
83.Dq by hand
84using a function like
85.Fn snprintf ,
86as the resulting string may still contain user-supplied conversion specifiers
87for later interpolation by
88.Fn setproctitle .
89.Pp
90Be sure to always use the proper secure idiom:
91.Bd -literal -offset indent
92setproctitle("%s", string);
93.Ed
94