]> git.sur5r.net Git - openldap/blob - libraries/liblutil/setproctitle.c
new pthreads detection
[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         buf[sizeof(buf) - 1] = '\0';
46         vsnprintf( buf, sizeof(buf)-1, fmt, ap );
47
48         va_end(ap);
49
50         if ( endargv == (char *)0 ) {
51                 /* set pointer to end of original argv */
52                 endargv = Argv[ Argc-1 ] + strlen( Argv[ Argc-1 ] );
53         }
54         /* make ps print "([prog name])" */
55         s = Argv[0];
56         *s++ = '-';
57         i = strlen( buf );
58         if ( i > endargv - s - 2 ) {
59                 i = endargv - s - 2;
60                 buf[ i ] = '\0';
61         }
62         strcpy( s, buf );
63         s += i;
64         while ( s < endargv ) *s++ = ' ';
65 }
66 #endif /* NOSETPROCTITLE */