]> git.sur5r.net Git - openldap/blob - libraries/liblutil/setproctitle.c
Fix ldaps / TLS processing...
[openldap] / libraries / liblutil / setproctitle.c
1 /* $OpenLDAP$ */
2 #include "portable.h"
3
4 #ifndef HAVE_SETPROCTITLE
5
6 #include <stdio.h>
7
8 #include <ac/stdlib.h>
9
10 #include <ac/setproctitle.h>
11 #include <ac/string.h>
12 #include <ac/stdarg.h>
13
14 /*
15  * Copyright (c) 1990,1991 Regents of the University of Michigan.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that this notice is preserved and that due credit is given
20  * to the University of Michigan at Ann Arbor. The name of the University
21  * may not be used to endorse or promote products derived from this
22  * software without specific prior written permission. This software
23  * is provided ``as is'' without express or implied warranty.
24  */
25
26 char    **Argv;         /* pointer to original (main's) argv */
27 int     Argc;           /* original argc */
28
29 /*
30  * takes a printf-style format string (fmt) and up to three parameters (a,b,c)
31  * this clobbers the original argv...
32  */
33
34 /* VARARGS */
35 void setproctitle( const char *fmt, ... )
36 {
37         static char *endargv = (char *)0;
38         char    *s;
39         int             i;
40         char    buf[ 1024 ];
41         va_list ap;
42
43         va_start(ap, fmt);
44
45 #ifdef HAVE_VSNPRINTF
46         buf[sizeof(buf) - 1] = '\0';
47         vsnprintf( buf, sizeof(buf)-1, fmt, ap );
48 #elif HAVE_VPRINTF
49         vsprintf( buf, fmt, ap ); /* hope it's not too long */
50 #else
51         /* use doprnt() */
52         chokeme = "choke me!  I don't have a doprnt() manual handy";
53 #endif
54
55         va_end(ap);
56
57         if ( endargv == (char *)0 ) {
58                 /* set pointer to end of original argv */
59                 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
60         }
61         /* make ps print "([prog name])" */
62         s = Argv[0];
63         *s++ = '-';
64         i = strlen( buf );
65         if ( i > endargv - s - 2 ) {
66                 i = endargv - s - 2;
67                 buf[ i ] = '\0';
68         }
69         strcpy( s, buf );
70         s += i;
71         while ( s < endargv ) *s++ = ' ';
72 }
73 #endif /* NOSETPROCTITLE */