]> git.sur5r.net Git - openldap/blob - servers/ldapd/setproctitle.c
Updates from devel including anonymous modify deny
[openldap] / servers / ldapd / setproctitle.c
1 #ifndef NOSETPROCTITLE
2 /*
3  * Copyright (c) 1990,1991 Regents of the University of Michigan.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that this notice is preserved and that due credit is given
8  * to the University of Michigan at Ann Arbor. The name of the University
9  * may not be used to endorse or promote products derived from this
10  * software without specific prior written permission. This software
11  * is provided ``as is'' without express or implied warranty.
12  */
13
14 char    **Argv;         /* pointer to original (main's) argv */
15 int     Argc;           /* original argc */
16
17 /*
18  * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
19  * this clobbers the original argv...
20  */
21
22 /* VARARGS */
23 setproctitle( fmt, a, b, c )
24 char *fmt;
25 {
26         static char *endargv = (char *)0;
27         char    *s;
28         int             i;
29         char    buf[ 1024 ];
30
31         if ( endargv == (char *)0 ) {
32                 /* set pointer to end of original argv */
33                 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
34         }
35         sprintf( buf, fmt, a, b, c );
36         /* make ps print "([prog name])" */
37         s = Argv[0];
38         *s++ = '-';
39         i = strlen( buf );
40         if ( i > endargv - s - 2 ) {
41                 i = endargv - s - 2;
42                 buf[ i ] = '\0';
43         }
44         strcpy( s, buf );
45         s += i;
46         while ( s < endargv ) *s++ = ' ';
47 }
48 #endif /* NOSETPROCTITLE */