]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/setproctitle.3
MFC r335939, r336088:
[FreeBSD/FreeBSD.git] / lib / libc / gen / setproctitle.3
1 .\" Copyright (c) 1995 Peter Wemm <peter@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, is permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice immediately at the beginning of the file, without modification,
9 .\"    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. This work was done expressly for inclusion into FreeBSD.  Other use
14 .\"    is permitted provided this notation is included.
15 .\" 4. Absolutely no warranty of function or purpose is made by the author
16 .\"    Peter Wemm.
17 .\" 5. Modifications may be freely made to this file providing the above
18 .\"    conditions are met.
19 .\"
20 .\" $FreeBSD$
21 .\"
22 .\" The following requests are required for all man pages.
23 .Dd July 4, 2018
24 .Dt SETPROCTITLE 3
25 .Os
26 .Sh NAME
27 .Nm setproctitle
28 .Nd set process title
29 .Sh SYNOPSIS
30 .In sys/types.h
31 .In unistd.h
32 .Ft void
33 .Fn setproctitle "const char *fmt" "..."
34 .Ft void
35 .Fn setproctitle_fast "const char *fmt" "..."
36 .Sh DESCRIPTION
37 The
38 .Fn setproctitle
39 library routine sets the process title that appears on the
40 .Xr ps 1
41 command.
42 The
43 .Fn setproctitle_fast
44 variant is optimized for high frequency updates, but may make the
45 .Xr ps 1
46 command slightly slower by not updating the kernel cache of the program
47 arguments.
48 .Pp
49 The title is set from the executable's name, followed by the
50 result of a
51 .Xr printf 3
52 style expansion of the arguments as specified by the
53 .Va fmt
54 argument.
55 If the
56 .Va fmt
57 argument begins with a
58 .Dq -
59 character, the executable's name is skipped.
60 .Pp
61 If
62 .Va fmt
63 is NULL, the process title is restored.
64 .Sh EXAMPLES
65 To set the title on a daemon to indicate its activity:
66 .Bd -literal -offset indent
67 setproctitle("talking to %s", inet_ntoa(addr));
68 .Ed
69 .Sh SEE ALSO
70 .Xr ps 1 ,
71 .Xr w 1 ,
72 .Xr kvm 3 ,
73 .Xr kvm_getargv 3 ,
74 .Xr printf 3
75 .Sh STANDARDS
76 The
77 .Fn setproctitle
78 function
79 is implicitly non-standard.
80 Other methods of causing the
81 .Xr ps 1
82 command line to change, including copying over the argv[0] string are
83 also implicitly non-portable.
84 It is preferable to use an operating system
85 supplied
86 .Fn setproctitle
87 if present.
88 .Pp
89 Unfortunately, it is possible that there are other calling conventions
90 to other versions of
91 .Fn setproctitle ,
92 although none have been found by the author as yet.
93 This is believed to be
94 the predominant convention.
95 .Pp
96 It is thought that the implementation is compatible with other systems,
97 including
98 .Nx
99 and
100 .Bsx .
101 .Sh HISTORY
102 The
103 .Fn setproctitle
104 function
105 first appeared in
106 .Fx 2.2 .
107 The
108 .Fn setproctitle_fast
109 function first appeared in
110 .Fx 12 .
111 Other operating systems have
112 similar functions.
113 .Sh AUTHORS
114 .An -nosplit
115 .An Peter Wemm Aq Mt peter@FreeBSD.org
116 stole the idea from the
117 .Sy "Sendmail 8.7.3"
118 source code by
119 .An Eric Allman Aq Mt eric@sendmail.org .
120 .Sh BUGS
121 Never pass a string with user-supplied data as a format without using
122 .Ql %s .
123 An attacker can put format specifiers in the string to mangle your stack,
124 leading to a possible security hole.
125 This holds true even if the string was built using a function like
126 .Fn snprintf ,
127 as the resulting string may still contain user-supplied conversion specifiers
128 for later interpolation by
129 .Fn setproctitle .
130 .Pp
131 Always use the proper secure idiom:
132 .Pp
133 .Dl setproctitle("%s", string);