[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.3

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