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