[BACK]Return to setargs.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rdist

Annotation of src/usr.bin/rdist/setargs.c, Revision 1.2

1.1       dm          1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. All advertising materials mentioning features or use of this software
                     14:  *    must display the following acknowledgement:
                     15:  *     This product includes software developed by the University of
                     16:  *     California, Berkeley and its contributors.
                     17:  * 4. Neither the name of the University nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
                     32:  */
                     33:
                     34: #ifndef lint
                     35: static char RCSid[] =
                     36: "$Id: setargs.c,v 6.4 1994/02/10 01:04:50 mcooper Exp mcooper $";
                     37:
                     38: static char sccsid[] = "@(#)setargs.c";
                     39:
                     40: static char copyright[] =
                     41: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
                     42:  All rights reserved.\n";
                     43: #endif /* not lint */
                     44:
                     45: #include "defs.h"
                     46:
                     47: #if    defined(SETARGS)
                     48:
                     49: /*
                     50:  * Set process argument functions
                     51:  */
                     52:
                     53: #define MAXUSERENVIRON                 40
                     54: char                         **Argv = NULL;
                     55: char                          *LastArgv = NULL;
                     56: char                          *UserEnviron[MAXUSERENVIRON+1];
                     57:
                     58: /*
                     59:  * Settup things for using setproctitle()
                     60:  */
                     61: setargs_settup(argc, argv, envp)
                     62:        int                     argc;
                     63:        char                  **argv;
                     64:        char                  **envp;
                     65: {
                     66:        register int            i;
                     67:        extern char           **environ;
                     68:
                     69:        /* Remember the User Environment */
                     70:
                     71:        for (i = 0; i < MAXUSERENVIRON && envp[i] != NULL; i++)
                     72:                UserEnviron[i] = strdup(envp[i]);
                     73:        UserEnviron[i] = NULL;
                     74:        environ = UserEnviron;
                     75:
                     76:        /* Save start and extent of argv for setproctitle */
                     77:        Argv = argv;
                     78:        if (i > 0)
                     79:                LastArgv = envp[i-1] + strlen(envp[i-1]);
                     80:        else
                     81:                LastArgv = argv[argc-1] + strlen(argv[argc-1]);
                     82: }
                     83:
                     84: /*
                     85:  * Set process title
                     86:  */
                     87: extern void _setproctitle(msg)
                     88:         char *msg;
                     89: {
                     90:        register int i;
                     91:        char *p;
                     92:
                     93:        p = Argv[0];
                     94:
                     95:        /* Make ps print "(program)" */
                     96:        *p++ = '-';
                     97:
                     98:        i = strlen(msg);
                     99:        if (i > LastArgv - p - 2) {
                    100:                i = LastArgv - p - 2;
                    101:                msg[i] = '\0';
                    102:        }
                    103:        (void) strcpy(p, msg);
                    104:        p += i;
                    105:        while (p < LastArgv) {
                    106:                *p++ = ' ';
                    107:        }
                    108: }
                    109:
                    110: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
                    111: /*
                    112:  * Varargs front-end to _setproctitle()
                    113:  */
                    114: extern void setproctitle(va_alist)
                    115:        va_dcl
                    116: {
                    117:        static char buf[BUFSIZ];
                    118:        va_list args;
                    119:        char *fmt;
                    120:
                    121:        va_start(args);
                    122:        fmt = va_arg(args, char *);
                    123:        (void) vsprintf(buf, fmt, args);
                    124:        va_end(args);
                    125:
                    126:        _setproctitle(buf);
                    127: }
                    128: #endif /* ARG_VARARGS */
                    129: #if    defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
                    130: /*
                    131:  * Stdarg front-end to _setproctitle()
                    132:  */
                    133: extern void setproctitle(char *fmt, ...)
                    134: {
                    135:        static char buf[BUFSIZ];
                    136:        va_list args;
                    137:
                    138:        va_start(args, fmt);
                    139:        (void) vsprintf(buf, fmt, args);
                    140:        va_end(args);
                    141:
                    142:        _setproctitle(buf);
                    143: }
                    144: #endif /* ARG_STDARG */
                    145: #if    !defined(ARG_TYPE)
                    146: /*
                    147:  * Non-Varargs front-end to _setproctitle()
                    148:  */
                    149: /*VARARGS1*/
                    150: extern void setproctitle(fmt, a1, a2, a3, a4, a5, a6)
                    151:        char *fmt;
                    152: {
                    153:        static char buf[BUFSIZ];
                    154:
                    155:        (void) sprintf(buf, fmt, a1, a2, a3, a4, a5, a6);
                    156:
                    157:        _setproctitle(buf);
                    158: }
                    159: #endif /* !ARG_TYPE */
                    160:
                    161: #endif         /* SETARGS */