summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorps <ps@FreeBSD.org>2000-08-01 06:37:09 +0000
committerps <ps@FreeBSD.org>2000-08-01 06:37:09 +0000
commit4b4777407a50f3cf96be2addda75d92b862a174b (patch)
treeb86ecf35aab4f1fca464b0efa495aa70ce177072 /lib/libc/gen
parent7bbd9bfadc01786cc3d3a7964628d21e02528e48 (diff)
downloadFreeBSD-src-4b4777407a50f3cf96be2addda75d92b862a174b.zip
FreeBSD-src-4b4777407a50f3cf96be2addda75d92b862a174b.tar.gz
If the format string passed to setproctitle begins with a '-'
character, skip the program name when setting the process title. Ansified with extreme prejudice. Reviewed by: peter
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/setproctitle.35
-rw-r--r--lib/libc/gen/setproctitle.c33
2 files changed, 14 insertions, 24 deletions
diff --git a/lib/libc/gen/setproctitle.3 b/lib/libc/gen/setproctitle.3
index b2322b3..7fd157f 100644
--- a/lib/libc/gen/setproctitle.3
+++ b/lib/libc/gen/setproctitle.3
@@ -47,6 +47,11 @@ result of a
style expansion of the arguments as specified by the
.Va fmt
argument.
+If the
+.Va fmt
+argument begins with a
+.Dq -
+character, the executable's name is skipped.
.Pp
If
.Va fmt
diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c
index 37b9fab..d0f224b 100644
--- a/lib/libc/gen/setproctitle.c
+++ b/lib/libc/gen/setproctitle.c
@@ -49,24 +49,13 @@ struct old_ps_strings {
#define OLD_PS_STRINGS ((struct old_ps_strings *) \
(USRSTACK - SPARE_USRSPACE - sizeof(struct old_ps_strings)))
-#if defined(__STDC__) /* from other parts of sendmail */
#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
#define SPT_BUFSIZE 2048 /* from other parts of sendmail */
extern char * __progname; /* is this defined in a .h anywhere? */
void
-#if defined(__STDC__)
setproctitle(const char *fmt, ...)
-#else
-setproctitle(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
static struct ps_strings *ps_strings;
static char buf[SPT_BUFSIZE];
@@ -81,24 +70,20 @@ setproctitle(fmt, va_alist)
unsigned long ul_ps_strings;
int oid[4];
-#if defined(__STDC__)
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
if (fmt) {
buf[sizeof(buf) - 1] = '\0';
- /* print program name heading for grep */
- (void) snprintf(buf, sizeof(buf), "%s: ", __progname);
-
- /*
- * can't use return from sprintf, as that is the count of how
- * much it wanted to write, not how much it actually did.
- */
-
- len = strlen(buf);
+ if (fmt[0] == '-') {
+ /* skip program name prefix */
+ fmt++;
+ len = 0;
+ } else {
+ /* print program name heading for grep */
+ (void) snprintf(buf, sizeof(buf), "%s: ", __progname);
+ len = strlen(buf);
+ }
/* print the argument string */
(void) vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
OpenPOWER on IntegriCloud