3
@@ -167,6 +167,7 @@ static const char rcsid[] = "$OpenBSD: i
5
#include <rpc/pmap_clnt.h>
7
+#include "setproctitle.h"
9
size_t strlcpy(char *, const char *, size_t);
11
@@ -331,7 +332,7 @@ fd_grow(fd_set **fdsp, int *bytes, int f
12
struct sigaction sa, sapipe;
15
-main(int argc, char *argv[])
16
+main(int argc, char *argv[], char *envp[])
19
int readablen = 0, ch;
20
@@ -342,6 +343,8 @@ main(int argc, char *argv[])
21
progname = strrchr(argv[0], '/');
22
progname = progname ? progname + 1 : argv[0];
24
+ initsetproctitle(argc, argv, envp);
26
while ((ch = getopt(argc, argv, "dR:")) != -1)
33
+ * setproctitle implementation for linux.
34
+ * Stolen from sendmail 8.7.4 and bashed around by David A. Holland
38
+ * Copyright (c) 1983, 1995 Eric P. Allman
39
+ * Copyright (c) 1988, 1993
40
+ * The Regents of the University of California. All rights reserved.
42
+ * Redistribution and use in source and binary forms, with or without
43
+ * modification, are permitted provided that the following conditions
45
+ * 1. Redistributions of source code must retain the above copyright
46
+ * notice, this list of conditions and the following disclaimer.
47
+ * 2. Redistributions in binary form must reproduce the above copyright
48
+ * notice, this list of conditions and the following disclaimer in the
49
+ * documentation and/or other materials provided with the distribution.
50
+ * 3. All advertising materials mentioning features or use of this software
51
+ * must display the following acknowledgement:
52
+ * This product includes software developed by the University of
53
+ * California, Berkeley and its contributors.
54
+ * 4. Neither the name of the University nor the names of its contributors
55
+ * may be used to endorse or promote products derived from this software
56
+ * without specific prior written permission.
58
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70
+ * From: @(#)conf.c 8.243 (Berkeley) 11/20/95
72
+char setproctitle_rcsid[] =
73
+ "$Id: setproctitle.c,v 1.3 1997/05/19 12:58:15 dholland Exp $";
81
+#include "setproctitle.h"
83
+** SETPROCTITLE -- set process title for ps
86
+** fmt -- a printf style format string.
87
+** a, b, c -- possible parameters to fmt.
93
+** Clobbers argv of our main procedure so ps(1) will
94
+** display the title.
99
+** Pointers for setproctitle.
100
+** This allows "ps" listings to give more useful information.
103
+static char **Argv = NULL; /* pointer to argument vector */
104
+static char *LastArgv = NULL; /* end of argv */
105
+static char Argv0[128]; /* program name */
108
+initsetproctitle(int argc, char **argv, char **envp)
114
+ ** Move the environment so setproctitle can use the space at
115
+ ** the top of memory.
118
+ for (i = 0; envp[i] != NULL; i++)
120
+ __environ = (char **) malloc(sizeof (char *) * (i + 1));
121
+ for (i = 0; envp[i] != NULL; i++)
122
+ __environ[i] = strdup(envp[i]);
123
+ __environ[i] = NULL;
126
+ ** Save start and extent of argv for setproctitle.
131
+ LastArgv = envp[i - 1] + strlen(envp[i - 1]);
133
+ LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
135
+ tmp = strrchr(argv[0], '/');
136
+ if (!tmp) tmp = argv[0];
138
+ strncpy(Argv0, tmp, sizeof(Argv0));
139
+ /* remember to take away one or we go outside the array space */
140
+ Argv0[sizeof(Argv0) - 1] = 0;
144
+setproctitle(const char *fmt, ...)
148
+ static char buf[2048];
153
+ /* print progname: heading for grep */
154
+ /* This can't overflow buf due to the relative size of Argv0. */
155
+ (void) strcpy(p, Argv0);
156
+ (void) strcat(p, ": ");
159
+ /* print the argument string */
161
+ (void) vsnprintf(p, sizeof(buf) - (p - buf), fmt, ap);
166
+ if (i > LastArgv - Argv[0] - 2)
168
+ i = LastArgv - Argv[0] - 2;
171
+ (void) strcpy(Argv[0], buf);
173
+ while (p < LastArgv)
181
+/* Call this from main. */
182
+void initsetproctitle(int argc, char **argv, char **envp);
184
+void setproctitle(const char *fmt, ...);