diff options
Diffstat (limited to 'bsd-setproctitle.c')
-rw-r--r-- | bsd-setproctitle.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/bsd-setproctitle.c b/bsd-setproctitle.c new file mode 100644 index 000000000..51a642e85 --- /dev/null +++ b/bsd-setproctitle.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * Modified for OpenSSH by Kevin Steves | ||
3 | * October 2000 | ||
4 | */ | ||
5 | |||
6 | /* | ||
7 | * Copyright (c) 1994, 1995 Christopher G. Demetriou | ||
8 | * All rights reserved. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
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 | ||
24 | * | ||
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. | ||
35 | */ | ||
36 | |||
37 | #if defined(LIBC_SCCS) && !defined(lint) | ||
38 | static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.7 1999/02/25 22:10:12 art Exp $"; | ||
39 | #endif /* LIBC_SCCS and not lint */ | ||
40 | |||
41 | #ifndef HAVE_SETPROCTITLE | ||
42 | |||
43 | #include "includes.h" | ||
44 | |||
45 | #define SPT_NONE 0 | ||
46 | #define SPT_PSTAT 1 | ||
47 | |||
48 | #ifndef SPT_TYPE | ||
49 | #define SPT_TYPE SPT_NONE | ||
50 | #endif | ||
51 | |||
52 | #if SPT_TYPE == SPT_PSTAT | ||
53 | #include <sys/param.h> | ||
54 | #include <sys/pstat.h> | ||
55 | #endif /* SPT_TYPE == SPT_PSTAT */ | ||
56 | |||
57 | #define MAX_PROCTITLE 2048 | ||
58 | |||
59 | #ifdef HAVE___PROGNAME | ||
60 | extern char *__progname; | ||
61 | #else | ||
62 | static const char *__progname = "sshd"; | ||
63 | #endif /* HAVE___PROGNAME */ | ||
64 | |||
65 | /* | ||
66 | * Set Process Title (SPT) defines. Modeled after sendmail's | ||
67 | * SPT type definition strategy. | ||
68 | * | ||
69 | * SPT_TYPE: | ||
70 | * | ||
71 | * SPT_NONE: Don't set the process title. Default. | ||
72 | * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific. | ||
73 | */ | ||
74 | |||
75 | void | ||
76 | setproctitle(const char *fmt, ...) | ||
77 | { | ||
78 | #if SPT_TYPE != SPT_NONE | ||
79 | va_list ap; | ||
80 | |||
81 | char buf[MAX_PROCTITLE]; | ||
82 | size_t used; | ||
83 | |||
84 | #if SPT_TYPE == SPT_PSTAT | ||
85 | union pstun pst; | ||
86 | #endif /* SPT_TYPE == SPT_PSTAT */ | ||
87 | |||
88 | va_start(ap, fmt); | ||
89 | if (fmt != NULL) { | ||
90 | used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname); | ||
91 | if (used >= MAX_PROCTITLE) | ||
92 | used = MAX_PROCTITLE - 1; | ||
93 | (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap); | ||
94 | } else | ||
95 | (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname); | ||
96 | va_end(ap); | ||
97 | used = strlen(buf); | ||
98 | |||
99 | #if SPT_TYPE == SPT_PSTAT | ||
100 | pst.pst_command = buf; | ||
101 | pstat(PSTAT_SETCMD, pst, used, 0, 0); | ||
102 | #endif /* SPT_TYPE == SPT_PSTAT */ | ||
103 | |||
104 | #endif /* SPT_TYPE != SPT_NONE */ | ||
105 | } | ||
106 | #endif /* HAVE_SETPROCTITLE */ | ||