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 December 16, 1995 24.Os 25.Dt SETPROCTITLE 3 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.Sh DESCRIPTION 35The 36.Fn setproctitle 37library routine sets the process title that appears on the 38.Xr ps 1 39command. 40.Pp 41The title is set from the executable's name, followed by the 42result of a 43.Xr printf 3 44style expansion of the arguments as specified by the 45.Va fmt 46argument. 47If the 48.Va fmt 49argument begins with a 50.Dq - 51character, the executable's name is skipped. 52.Pp 53If 54.Va fmt 55is NULL, the process title is restored. 56.Sh EXAMPLES 57To set the title on a daemon to indicate its activity: 58.Bd -literal -offset indent 59setproctitle("talking to %s", inet_ntoa(addr)); 60.Ed 61.Sh SEE ALSO 62.Xr ps 1 , 63.Xr w 1 , 64.Xr kvm 3 , 65.Xr kvm_getargv 3 , 66.Xr printf 3 67.Sh STANDARDS 68.Fn setproctitle 69is implicitly non-standard. Other methods of causing the 70.Xr ps 1 71command line to change, including copying over the argv[0] string are 72also implicitly non-portable. It is preferable to use an operating system 73supplied 74.Fn setproctitle 75if present. 76.Pp 77Unfortunately, it is possible that there are other calling conventions 78to other versions of 79.Fn setproctitle , 80although none have been found by the author as yet. This is believed to be 81the predominant convention. 82.Pp 83It is thought that the implementation is compatible with other systems, 84including 85.Nx 86and 87.Bsx . 88.Sh HISTORY 89.Fn setproctitle 90first appeared in 91.Fx 2.2 . 92Other operating systems have 93similar functions. 94.Sh AUTHORS 95.An -nosplit 96.An Peter Wemm Aq peter@FreeBSD.org 97stole the idea from the 98.Sy "Sendmail 8.7.3" 99source code by 100.An Eric Allman Aq eric@sendmail.org . 101.Sh BUGS 102Never pass a string with user-supplied data as a format without using 103.Ql %s . 104An attacker can put format specifiers in the string to mangle your stack, 105leading to a possible security hole. 106This holds true even if the string was built using a function like 107.Fn snprintf , 108as the resulting string may still contain user-supplied conversion specifiers 109for later interpolation by 110.Fn setproctitle . 111.Pp 112Always use the proper secure idiom: 113.Pp 114.Dl setproctitle("%s", string); 115