setproctitle(); no reason to have this code spread into N utils...

This commit is contained in:
cgd 1994-04-14 03:13:39 +00:00
parent d94cf8ceb8
commit 6e0cf55f61
3 changed files with 156 additions and 3 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.21 (Berkeley) 5/24/91
# $Id: Makefile.inc,v 1.37 1994/04/09 01:31:24 mycroft Exp $
# $Id: Makefile.inc,v 1.38 1994/04/14 03:13:39 cgd Exp $
# gen sources
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/gen ${.CURDIR}/gen
@ -16,7 +16,7 @@ SRCS+= alarm.c assert.c clock.c confstr.c ctermid.c ctime.c ctype_.c \
msgctl.c msgget.c msgsnd.c msgrcv.c \
mktemp.c nice.c nlist.c pause.c popen.c psignal.c pwcache.c raise.c \
scandir.c semconfig.c semctl.c semget.c semop.c setjmperr.c setmode.c \
shmat.c shmctl.c shmdt.c shmget.c siginterrupt.c \
setproctitle.c shmat.c shmctl.c shmdt.c shmget.c siginterrupt.c \
siglist.c signal.c signame.c sigsetops.c sleep.c syslog.c \
termios.c time.c times.c timezone.c tolower_.c ttyname.c ttyslot.c \
toupper_.c \
@ -57,7 +57,7 @@ MAN3+= alarm.0 clock.0 ctermid.0 ctime.0 ctype.0 cuserid.0 \
isalpha.0 isascii.0 isblank.0 iscntrl.0 isdigit.0 isgraph.0 isinf.0 \
islower.0 isprint.0 ispunct.0 isspace.0 isupper.0 isxdigit.0 \
ldexp.0 lsearch.0 modf.0 nice.0 nlist.0 pause.0 popen.0 psignal.0 \
pwcache.0 raise.0 scandir.0 setjmp.0 setmode.0 \
pwcache.0 raise.0 scandir.0 setjmp.0 setmode.0 setproctitle.0 \
siginterrupt.0 signal.0 sigsetops.0 sleep.0 syslog.0 tcgetpgrp.0 \
tcsendbreak.0 tcsetattr.0 tcsetpgrp.0 time.0 times.0 timezone.0 \
tolower.0 toupper.0 ttyname.0 tzset.0 \

View File

@ -0,0 +1,73 @@
.\"
.\" Copyright (c) 1994 Christopher G. Demetriou
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by Christopher G. Demetriou.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: setproctitle.3,v 1.1 1994/04/14 03:13:42 cgd Exp $
.\"
.Dd "April 13, 1994"
.Dt SETPROCTITLE 3
.Os NetBSD 0.9a
.Sh NAME
.Nm setproctitle
.Nd set process title
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Ft void
.Fn setproctitle "const char *fmt" "..."
.Sh DESCRIPTION
The
.Fn setproctitle
function sets the invoking process's title.
The process title is set to the last component of the program
name, followed by a colon and the formatted string specified
by
.Va fmt .
If
.Va fmt
is NULL, the colon and formatted string are omitted.
The length of a process title is limited to 2048 bytes.
.Sh EXAMPLES
Set the process title to the program name, with no further information:
.Bd -literal -offset indent
setproctitle(NULL);
.Ed
.Pp
Set the process title to the program name, an informational string,
and the process id:
.Bd -literal -offset indent
setproctitle("foo! (%s)", getpid());
.Ed
.Sh SEE ALSO
.Xr ps 1 ,
.Xr w 1 ,
.Xr printf 3
.Sh HISTORY
The
.Fn setproctitle
function first appeared in
.Nx 0.9a .

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 1994 Christopher G. Demetriou
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christopher G. Demetriou.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$Id: setproctitle.c,v 1.1 1994/04/14 03:13:43 cgd Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/exec.h>
#include <vm/vm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#define MAX_PROCTITLE 2048
extern char *__progname; /* Program name, from crt0. */
void
#if __STDC__
setproctitle(const char *fmt, ...)
#else
setproctitle(fmt, va_alist)
const char *fmt;
va_dcl
#endif
{
va_list ap;
static char buf[MAX_PROCTITLE];
int used;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
if (fmt != NULL) {
used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname);
(void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap);
} else
(void)snprintf(buf, MAX_PROCTITLE, "%s", __progname);
va_end(ap);
PS_STRINGS->ps_nargvstr = 1;
PS_STRINGS->ps_argvstr = buf;
}