2 * Modified for OpenSSH by Kevin Steves
5 * $OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $
9 * Copyright (c) 1994, 1995 Christopher G. Demetriou
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Christopher G. Demetriou
23 * for the NetBSD Project.
24 * 4. The name of the author may not be used to endorse or promote products
25 * derived from this software without specific prior written permission
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #ifndef HAVE_SETPROCTITLE
47 #define SPT_TYPE SPT_NONE
50 #if SPT_TYPE == SPT_PSTAT
51 #include <sys/param.h>
52 #include <sys/pstat.h>
53 #endif /* SPT_TYPE == SPT_PSTAT */
55 #define MAX_PROCTITLE 2048
57 extern char *__progname;
60 * Set Process Title (SPT) defines. Modeled after sendmail's
61 * SPT type definition strategy.
65 * SPT_NONE: Don't set the process title. Default.
66 * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific.
70 setproctitle(const char *fmt, ...)
72 #if SPT_TYPE != SPT_NONE
75 char buf[MAX_PROCTITLE];
78 #if SPT_TYPE == SPT_PSTAT
80 #endif /* SPT_TYPE == SPT_PSTAT */
84 used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname);
85 if (used >= MAX_PROCTITLE)
86 used = MAX_PROCTITLE - 1;
87 (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap);
89 (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname);
93 #if SPT_TYPE == SPT_PSTAT
94 pst.pst_command = buf;
95 pstat(PSTAT_SETCMD, pst, used, 0, 0);
96 #endif /* SPT_TYPE == SPT_PSTAT */
98 #endif /* SPT_TYPE != SPT_NONE */
100 #endif /* HAVE_SETPROCTITLE */