2010-05-19 08:57:53 +00:00
|
|
|
.\" Copyright (c) 1995 Peter Wemm <peter@FreeBSD.org>
|
1995-12-26 22:50:08 +00:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, is permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice immediately at the beginning of the file, without modification,
|
|
|
|
.\" this list of conditions, and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. This work was done expressly for inclusion into FreeBSD. Other use
|
|
|
|
.\" is permitted provided this notation is included.
|
|
|
|
.\" 4. Absolutely no warranty of function or purpose is made by the author
|
|
|
|
.\" Peter Wemm.
|
|
|
|
.\" 5. Modifications may be freely made to this file providing the above
|
|
|
|
.\" conditions are met.
|
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1995-12-26 22:50:08 +00:00
|
|
|
.\"
|
|
|
|
.\" The following requests are required for all man pages.
|
2020-11-13 13:47:18 +00:00
|
|
|
.Dd November 13, 2020
|
1995-12-26 22:50:08 +00:00
|
|
|
.Dt SETPROCTITLE 3
|
2010-04-14 19:08:06 +00:00
|
|
|
.Os
|
1995-12-26 22:50:08 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm setproctitle
|
2020-11-13 14:56:34 +00:00
|
|
|
.Nm setproctitle_fast
|
2001-05-25 20:42:40 +00:00
|
|
|
.Nd set process title
|
1995-12-26 22:50:08 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/types.h
|
|
|
|
.In unistd.h
|
1995-12-26 22:50:08 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn setproctitle "const char *fmt" "..."
|
2018-07-04 13:31:16 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn setproctitle_fast "const char *fmt" "..."
|
1995-12-26 22:50:08 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
1996-12-30 21:08:45 +00:00
|
|
|
.Fn setproctitle
|
1995-12-26 22:50:08 +00:00
|
|
|
library routine sets the process title that appears on the
|
|
|
|
.Xr ps 1
|
|
|
|
command.
|
2018-07-04 13:31:16 +00:00
|
|
|
The
|
|
|
|
.Fn setproctitle_fast
|
|
|
|
variant is optimized for high frequency updates, but may make the
|
|
|
|
.Xr ps 1
|
|
|
|
command slightly slower by not updating the kernel cache of the program
|
|
|
|
arguments.
|
1995-12-26 22:50:08 +00:00
|
|
|
.Pp
|
|
|
|
The title is set from the executable's name, followed by the
|
|
|
|
result of a
|
|
|
|
.Xr printf 3
|
|
|
|
style expansion of the arguments as specified by the
|
|
|
|
.Va fmt
|
|
|
|
argument.
|
2000-08-01 06:37:09 +00:00
|
|
|
If the
|
|
|
|
.Va fmt
|
|
|
|
argument begins with a
|
|
|
|
.Dq -
|
|
|
|
character, the executable's name is skipped.
|
1995-12-26 22:50:08 +00:00
|
|
|
.Pp
|
|
|
|
If
|
|
|
|
.Va fmt
|
1999-11-17 21:12:17 +00:00
|
|
|
is NULL, the process title is restored.
|
1995-12-26 22:50:08 +00:00
|
|
|
.Sh EXAMPLES
|
1997-04-17 23:31:47 +00:00
|
|
|
To set the title on a daemon to indicate its activity:
|
1995-12-26 22:50:08 +00:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
setproctitle("talking to %s", inet_ntoa(addr));
|
|
|
|
.Ed
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr ps 1 ,
|
|
|
|
.Xr w 1 ,
|
2020-11-13 13:47:18 +00:00
|
|
|
.Xr setprogname 3 ,
|
1995-12-26 22:50:08 +00:00
|
|
|
.Xr kvm 3 ,
|
|
|
|
.Xr kvm_getargv 3 ,
|
|
|
|
.Xr printf 3
|
|
|
|
.Sh STANDARDS
|
2002-12-18 10:13:54 +00:00
|
|
|
The
|
1996-12-30 21:08:45 +00:00
|
|
|
.Fn setproctitle
|
2002-12-18 10:13:54 +00:00
|
|
|
function
|
2004-07-02 23:52:20 +00:00
|
|
|
is implicitly non-standard.
|
|
|
|
Other methods of causing the
|
1995-12-26 22:50:08 +00:00
|
|
|
.Xr ps 1
|
|
|
|
command line to change, including copying over the argv[0] string are
|
2004-07-02 23:52:20 +00:00
|
|
|
also implicitly non-portable.
|
|
|
|
It is preferable to use an operating system
|
1995-12-26 22:50:08 +00:00
|
|
|
supplied
|
1996-12-30 21:08:45 +00:00
|
|
|
.Fn setproctitle
|
1995-12-26 22:50:08 +00:00
|
|
|
if present.
|
|
|
|
.Pp
|
|
|
|
Unfortunately, it is possible that there are other calling conventions
|
|
|
|
to other versions of
|
1996-12-30 21:08:45 +00:00
|
|
|
.Fn setproctitle ,
|
2004-07-02 23:52:20 +00:00
|
|
|
although none have been found by the author as yet.
|
|
|
|
This is believed to be
|
1995-12-26 22:50:08 +00:00
|
|
|
the predominant convention.
|
|
|
|
.Pp
|
1996-01-30 18:13:11 +00:00
|
|
|
It is thought that the implementation is compatible with other systems,
|
1995-12-26 22:50:08 +00:00
|
|
|
including
|
1999-09-21 19:39:27 +00:00
|
|
|
.Nx
|
1995-12-26 22:50:08 +00:00
|
|
|
and
|
2001-08-13 17:07:40 +00:00
|
|
|
.Bsx .
|
1995-12-26 22:50:08 +00:00
|
|
|
.Sh HISTORY
|
2002-12-18 10:13:54 +00:00
|
|
|
The
|
1996-12-30 21:08:45 +00:00
|
|
|
.Fn setproctitle
|
2002-12-18 10:13:54 +00:00
|
|
|
function
|
1996-08-23 20:52:53 +00:00
|
|
|
first appeared in
|
|
|
|
.Fx 2.2 .
|
2018-07-04 13:31:16 +00:00
|
|
|
The
|
|
|
|
.Fn setproctitle_fast
|
|
|
|
function first appeared in
|
|
|
|
.Fx 12 .
|
1996-08-23 20:52:53 +00:00
|
|
|
Other operating systems have
|
1995-12-26 22:50:08 +00:00
|
|
|
similar functions.
|
|
|
|
.Sh AUTHORS
|
2000-11-22 09:23:54 +00:00
|
|
|
.An -nosplit
|
2014-06-23 08:25:03 +00:00
|
|
|
.An Peter Wemm Aq Mt peter@FreeBSD.org
|
1995-12-26 22:50:08 +00:00
|
|
|
stole the idea from the
|
1996-08-23 20:52:53 +00:00
|
|
|
.Sy "Sendmail 8.7.3"
|
1995-12-26 22:50:08 +00:00
|
|
|
source code by
|
2014-06-23 08:25:03 +00:00
|
|
|
.An Eric Allman Aq Mt eric@sendmail.org .
|
2001-05-25 20:42:40 +00:00
|
|
|
.Sh BUGS
|
|
|
|
Never pass a string with user-supplied data as a format without using
|
|
|
|
.Ql %s .
|
2001-07-15 07:53:42 +00:00
|
|
|
An attacker can put format specifiers in the string to mangle your stack,
|
2001-05-25 20:42:40 +00:00
|
|
|
leading to a possible security hole.
|
|
|
|
This holds true even if the string was built using a function like
|
|
|
|
.Fn snprintf ,
|
|
|
|
as the resulting string may still contain user-supplied conversion specifiers
|
|
|
|
for later interpolation by
|
|
|
|
.Fn setproctitle .
|
|
|
|
.Pp
|
|
|
|
Always use the proper secure idiom:
|
|
|
|
.Pp
|
|
|
|
.Dl setproctitle("%s", string);
|