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