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

Annotation of src/usr.bin/cvs/cvs.c, Revision 1.120

1.120   ! xsa         1: /*     $OpenBSD: cvs.c,v 1.119 2007/04/24 13:36:30 sobrado Exp $       */
1.1       jfb         2: /*
1.113     joris       3:  * Copyright (c) 2006, 2007 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.18      tedu        5:  * All rights reserved.
1.1       jfb         6:  *
1.18      tedu        7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
1.1       jfb        10:  *
1.18      tedu       11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
1.1       jfb        13:  * 2. The name of the author may not be used to endorse or promote products
1.18      tedu       14:  *    derived from this software without specific prior written permission.
1.1       jfb        15:  *
                     16:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     17:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     18:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     19:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     20:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     21:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     22:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     23:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     24:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
1.18      tedu       25:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       jfb        26:  */
                     27:
1.117     otto       28: #include <sys/stat.h>
                     29:
                     30: #include <ctype.h>
                     31: #include <errno.h>
                     32: #include <pwd.h>
                     33: #include <stdlib.h>
                     34: #include <string.h>
1.120   ! xsa        35: #include <time.h>
1.117     otto       36: #include <unistd.h>
1.1       jfb        37:
                     38: #include "cvs.h"
1.106     joris      39: #include "remote.h"
1.1       jfb        40:
                     41: extern char *__progname;
                     42:
                     43: /* verbosity level: 0 = really quiet, 1 = quiet, 2 = verbose */
1.105     reyk       44: int verbosity = 1;
1.1       jfb        45:
                     46: /* compression level used with zlib, 0 meaning no compression taking place */
1.98      joris      47: int    cvs_compress = 0;
                     48: int    cvs_readrc = 1;         /* read .cvsrc on startup */
                     49: int    cvs_trace = 0;
                     50: int    cvs_nolog = 0;
                     51: int    cvs_readonly = 0;
1.111     xsa        52: int    cvs_readonlyfs = 0;
1.98      joris      53: int    cvs_nocase = 0; /* set to 1 to disable filename case sensitivity */
                     54: int    cvs_noexec = 0; /* set to 1 to disable disk operations (-n option) */
                     55: int    cvs_error = -1; /* set to the correct error code on failure */
                     56: int    cvs_cmdop;
1.99      joris      57: int    cvs_umask = CVS_UMASK_DEFAULT;
1.106     joris      58: int    cvs_server_active = 0;
1.98      joris      59:
1.99      joris      60: char   *cvs_tagname = NULL;
1.98      joris      61: char   *cvs_defargs;           /* default global arguments from .cvsrc */
                     62: char   *cvs_command;           /* name of the command we are running */
                     63: char   *cvs_rootstr;
                     64: char   *cvs_rsh = CVS_RSH_DEFAULT;
                     65: char   *cvs_editor = CVS_EDITOR_DEFAULT;
                     66: char   *cvs_homedir = NULL;
                     67: char   *cvs_msg = NULL;
                     68: char   *cvs_tmpdir = CVS_TMPDIR_DEFAULT;
1.13      krapht     69:
1.98      joris      70: struct cvsroot *current_cvsroot = NULL;
1.27      jfb        71:
1.98      joris      72: int            cvs_getopt(int, char **);
1.75      xsa        73: void           usage(void);
                     74: static void    cvs_read_rcfile(void);
1.1       jfb        75:
1.98      joris      76: struct cvs_wklhead temp_files;
                     77:
                     78: void sighandler(int);
                     79: volatile sig_atomic_t cvs_quit = 0;
                     80: volatile sig_atomic_t sig_received = 0;
                     81:
                     82: void
                     83: sighandler(int sig)
                     84: {
                     85:        sig_received = sig;
                     86:
                     87:        switch (sig) {
                     88:        case SIGINT:
                     89:        case SIGTERM:
1.107     joris      90:        case SIGPIPE:
1.98      joris      91:                cvs_quit = 1;
                     92:                break;
                     93:        default:
                     94:                break;
                     95:        }
                     96: }
                     97:
                     98: void
                     99: cvs_cleanup(void)
                    100: {
                    101:        cvs_log(LP_TRACE, "cvs_cleanup: removing locks");
                    102:        cvs_worklist_run(&repo_locks, cvs_worklist_unlink);
                    103:
                    104:        cvs_log(LP_TRACE, "cvs_cleanup: removing temp files");
                    105:        cvs_worklist_run(&temp_files, cvs_worklist_unlink);
1.106     joris     106:
                    107:        if (cvs_server_active) {
                    108:                if (cvs_rmdir(cvs_server_path) == -1)
                    109:                        cvs_log(LP_ERR,
                    110:                            "warning: failed to remove server directory: %s",
                    111:                            cvs_server_path);
                    112:                xfree(cvs_server_path);
                    113:        }
1.98      joris     114: }
                    115:
1.1       jfb       116: void
                    117: usage(void)
                    118: {
                    119:        fprintf(stderr,
1.119     sobrado   120:            "usage: %s [-flnQqRrtVvw] [-d root] [-e editor] [-s var=val]\n"
                    121:            "           [-T tmpdir] [-z level] command [...]\n", __progname);
1.1       jfb       122: }
                    123:
                    124: int
                    125: main(int argc, char **argv)
                    126: {
1.17      jfb       127:        char *envstr, *cmd_argv[CVS_CMD_MAXARG], **targv;
                    128:        int i, ret, cmd_argc;
1.1       jfb       129:        struct cvs_cmd *cmdp;
1.79      xsa       130:        struct passwd *pw;
1.80      xsa       131:        struct stat st;
1.100     joris     132:        char fpath[MAXPATHLEN];
1.106     joris     133:        char *root, *rootp;
1.87      joris     134:
                    135:        tzset();
1.1       jfb       136:
1.27      jfb       137:        TAILQ_INIT(&cvs_variables);
1.98      joris     138:        SLIST_INIT(&repo_locks);
                    139:        SLIST_INIT(&temp_files);
1.1       jfb       140:
                    141:        /* check environment so command-line options override it */
                    142:        if ((envstr = getenv("CVS_RSH")) != NULL)
                    143:                cvs_rsh = envstr;
                    144:
                    145:        if (((envstr = getenv("CVSEDITOR")) != NULL) ||
                    146:            ((envstr = getenv("VISUAL")) != NULL) ||
                    147:            ((envstr = getenv("EDITOR")) != NULL))
                    148:                cvs_editor = envstr;
1.76      xsa       149:
                    150:        if ((envstr = getenv("CVSREAD")) != NULL)
                    151:                cvs_readonly = 1;
1.1       jfb       152:
1.111     xsa       153:        if ((envstr = getenv("CVSREADONLYFS")) != NULL) {
                    154:                cvs_readonlyfs = 1;
                    155:                cvs_nolog = 1;
                    156:        }
                    157:
1.79      xsa       158:        if ((cvs_homedir = getenv("HOME")) == NULL) {
1.89      xsa       159:                if ((pw = getpwuid(getuid())) == NULL)
                    160:                        fatal("getpwuid failed");
1.79      xsa       161:                cvs_homedir = pw->pw_dir;
1.85      reyk      162:        }
1.79      xsa       163:
1.80      xsa       164:        if ((envstr = getenv("TMPDIR")) != NULL)
                    165:                cvs_tmpdir = envstr;
                    166:
1.17      jfb       167:        ret = cvs_getopt(argc, argv);
                    168:
                    169:        argc -= ret;
                    170:        argv += ret;
                    171:        if (argc == 0) {
                    172:                usage();
1.98      joris     173:                exit(1);
1.17      jfb       174:        }
1.80      xsa       175:
1.17      jfb       176:        cvs_command = argv[0];
                    177:
1.80      xsa       178:        /*
                    179:         * check the tmp dir, either specified through
                    180:         * the environment variable TMPDIR, or via
                    181:         * the global option -T <dir>
                    182:         */
1.94      xsa       183:        if (stat(cvs_tmpdir, &st) == -1)
                    184:                fatal("stat failed on `%s': %s", cvs_tmpdir, strerror(errno));
                    185:        else if (!S_ISDIR(st.st_mode))
                    186:                fatal("`%s' is not valid temporary directory", cvs_tmpdir);
1.80      xsa       187:
1.74      xsa       188:        if (cvs_readrc == 1) {
1.17      jfb       189:                cvs_read_rcfile();
                    190:
                    191:                if (cvs_defargs != NULL) {
1.94      xsa       192:                        if ((targv = cvs_makeargv(cvs_defargs, &i)) == NULL)
                    193:                                fatal("failed to load default arguments to %s",
1.17      jfb       194:                                    __progname);
                    195:
                    196:                        cvs_getopt(i, targv);
                    197:                        cvs_freeargv(targv, i);
1.88      joris     198:                        xfree(targv);
1.17      jfb       199:                }
                    200:        }
                    201:
                    202:        /* setup signal handlers */
1.98      joris     203:        signal(SIGTERM, sighandler);
                    204:        signal(SIGINT, sighandler);
                    205:        signal(SIGHUP, sighandler);
                    206:        signal(SIGABRT, sighandler);
                    207:        signal(SIGALRM, sighandler);
                    208:        signal(SIGPIPE, sighandler);
1.17      jfb       209:
                    210:        cmdp = cvs_findcmd(cvs_command);
                    211:        if (cmdp == NULL) {
                    212:                fprintf(stderr, "Unknown command: `%s'\n\n", cvs_command);
                    213:                fprintf(stderr, "CVS commands are:\n");
1.67      jfb       214:                for (i = 0; cvs_cdt[i] != NULL; i++)
1.17      jfb       215:                        fprintf(stderr, "\t%-16s%s\n",
1.67      jfb       216:                            cvs_cdt[i]->cmd_name, cvs_cdt[i]->cmd_descr);
1.98      joris     217:                exit(1);
1.17      jfb       218:        }
                    219:
                    220:        cvs_cmdop = cmdp->cmd_op;
                    221:
                    222:        cmd_argc = 0;
                    223:        memset(cmd_argv, 0, sizeof(cmd_argv));
                    224:
                    225:        cmd_argv[cmd_argc++] = argv[0];
                    226:        if (cmdp->cmd_defargs != NULL) {
                    227:                /* transform into a new argument vector */
                    228:                ret = cvs_getargv(cmdp->cmd_defargs, cmd_argv + 1,
                    229:                    CVS_CMD_MAXARG - 1);
1.94      xsa       230:                if (ret < 0)
                    231:                        fatal("main: cvs_getargv failed");
                    232:
1.17      jfb       233:                cmd_argc += ret;
                    234:        }
1.98      joris     235:
1.17      jfb       236:        for (ret = 1; ret < argc; ret++)
                    237:                cmd_argv[cmd_argc++] = argv[ret];
                    238:
1.98      joris     239:        cvs_file_init();
                    240:
1.106     joris     241:        if (cvs_cmdop == CVS_OP_SERVER) {
                    242:                setvbuf(stdin, NULL, _IOLBF, 0);
                    243:                setvbuf(stdout, NULL, _IOLBF, 0);
                    244:
                    245:                cvs_server_active = 1;
                    246:                root = cvs_remote_input();
                    247:                if ((rootp = strchr(root, ' ')) == NULL)
                    248:                        fatal("bad Root request");
                    249:                cvs_rootstr = xstrdup(rootp + 1);
                    250:                xfree(root);
                    251:        }
                    252:
1.98      joris     253:        if ((current_cvsroot = cvsroot_get(".")) == NULL) {
1.71      xsa       254:                cvs_log(LP_ERR,
1.98      joris     255:                    "No CVSROOT specified! Please use the '-d' option");
1.102     david     256:                fatal("or set the CVSROOT environment variable.");
1.17      jfb       257:        }
                    258:
1.106     joris     259:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                    260:                cmdp->cmd(cmd_argc, cmd_argv);
                    261:                cvs_cleanup();
                    262:                return (0);
                    263:        }
1.100     joris     264:
1.116     xsa       265:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
                    266:            current_cvsroot->cr_dir, CVS_PATH_ROOT);
1.110     xsa       267:
1.103     xsa       268:        if (stat(fpath, &st) == -1 && cvs_cmdop != CVS_OP_INIT) {
1.100     joris     269:                if (errno == ENOENT)
1.104     joris     270:                        fatal("repository '%s' does not exist",
1.100     joris     271:                            current_cvsroot->cr_dir);
                    272:                else
                    273:                        fatal("%s: %s", current_cvsroot->cr_dir,
                    274:                            strerror(errno));
                    275:        } else {
                    276:                if (!S_ISDIR(st.st_mode))
                    277:                        fatal("'%s' is not a directory",
                    278:                            current_cvsroot->cr_dir);
                    279:        }
1.99      joris     280:
1.103     xsa       281:        if (cvs_cmdop != CVS_OP_INIT)
                    282:                cvs_parse_configfile();
1.99      joris     283:
                    284:        umask(cvs_umask);
1.98      joris     285:
                    286:        cmdp->cmd(cmd_argc, cmd_argv);
                    287:        cvs_cleanup();
1.17      jfb       288:
1.98      joris     289:        return (0);
1.17      jfb       290: }
                    291:
                    292: int
                    293: cvs_getopt(int argc, char **argv)
                    294: {
                    295:        int ret;
                    296:        char *ep;
1.115     joris     297:        const char *errstr;
1.17      jfb       298:
1.111     xsa       299:        while ((ret = getopt(argc, argv, "b:d:e:fHlnQqRrs:T:tvVwz:")) != -1) {
1.1       jfb       300:                switch (ret) {
1.11      jfb       301:                case 'b':
                    302:                        /*
                    303:                         * We do not care about the bin directory for RCS files
                    304:                         * as this program has no dependencies on RCS programs,
                    305:                         * so it is only here for backwards compatibility.
                    306:                         */
                    307:                        cvs_log(LP_NOTICE, "the -b argument is obsolete");
                    308:                        break;
1.1       jfb       309:                case 'd':
                    310:                        cvs_rootstr = optarg;
                    311:                        break;
                    312:                case 'e':
                    313:                        cvs_editor = optarg;
                    314:                        break;
                    315:                case 'f':
1.17      jfb       316:                        cvs_readrc = 0;
1.1       jfb       317:                        break;
                    318:                case 'l':
                    319:                        cvs_nolog = 1;
                    320:                        break;
                    321:                case 'n':
1.65      xsa       322:                        cvs_noexec = 1;
1.112     xsa       323:                        cvs_nolog = 1;
1.1       jfb       324:                        break;
                    325:                case 'Q':
                    326:                        verbosity = 0;
                    327:                        break;
                    328:                case 'q':
1.105     reyk      329:                        /*
                    330:                         * Be quiet. This is the default in OpenCVS.
                    331:                         */
1.111     xsa       332:                        break;
                    333:                case 'R':
                    334:                        cvs_readonlyfs = 1;
                    335:                        cvs_nolog = 1;
1.1       jfb       336:                        break;
                    337:                case 'r':
                    338:                        cvs_readonly = 1;
                    339:                        break;
1.27      jfb       340:                case 's':
                    341:                        ep = strchr(optarg, '=');
                    342:                        if (ep == NULL) {
                    343:                                cvs_log(LP_ERR, "no = in variable assignment");
1.98      joris     344:                                exit(1);
1.27      jfb       345:                        }
                    346:                        *(ep++) = '\0';
                    347:                        if (cvs_var_set(optarg, ep) < 0)
1.98      joris     348:                                exit(1);
1.80      xsa       349:                        break;
                    350:                case 'T':
                    351:                        cvs_tmpdir = optarg;
1.27      jfb       352:                        break;
1.1       jfb       353:                case 't':
                    354:                        cvs_trace = 1;
1.105     reyk      355:                        break;
                    356:                case 'V':
                    357:                        /* don't override -Q */
                    358:                        if (verbosity)
                    359:                                verbosity = 2;
1.1       jfb       360:                        break;
                    361:                case 'v':
                    362:                        printf("%s\n", CVS_VERSION);
                    363:                        exit(0);
                    364:                        /* NOTREACHED */
1.83      xsa       365:                        break;
                    366:                case 'w':
                    367:                        cvs_readonly = 0;
1.11      jfb       368:                        break;
                    369:                case 'x':
                    370:                        /*
                    371:                         * Kerberos encryption support, kept for compatibility
                    372:                         */
1.1       jfb       373:                        break;
                    374:                case 'z':
1.115     joris     375:                        cvs_compress = strtonum(optarg, 0, 9, &errstr);
                    376:                        if (errstr != NULL)
                    377:                                fatal("cvs_compress: %s", errstr);
1.1       jfb       378:                        break;
                    379:                default:
                    380:                        usage();
1.98      joris     381:                        exit(1);
1.1       jfb       382:                }
                    383:        }
                    384:
1.17      jfb       385:        ret = optind;
1.1       jfb       386:        optind = 1;
1.17      jfb       387:        optreset = 1;   /* for next call */
1.12      jfb       388:
1.1       jfb       389:        return (ret);
                    390: }
                    391:
                    392: /*
1.17      jfb       393:  * cvs_read_rcfile()
1.1       jfb       394:  *
                    395:  * Read the CVS `.cvsrc' file in the user's home directory.  If the file
                    396:  * exists, it should contain a list of arguments that should always be given
                    397:  * implicitly to the specified commands.
                    398:  */
1.42      joris     399: static void
1.17      jfb       400: cvs_read_rcfile(void)
1.1       jfb       401: {
1.79      xsa       402:        char rcpath[MAXPATHLEN], linebuf[128], *lp, *p;
1.116     xsa       403:        int i, linenum;
1.17      jfb       404:        size_t len;
1.1       jfb       405:        struct cvs_cmd *cmdp;
                    406:        FILE *fp;
                    407:
1.116     xsa       408:        linenum = 0;
                    409:
                    410:        i = snprintf(rcpath, MAXPATHLEN, "%s/%s", cvs_homedir, CVS_PATH_RC);
                    411:        if (i < 0 || i >= MAXPATHLEN) {
1.108     xsa       412:                cvs_log(LP_ERRNO, "%s", rcpath);
1.54      xsa       413:                return;
                    414:        }
1.1       jfb       415:
                    416:        fp = fopen(rcpath, "r");
                    417:        if (fp == NULL) {
                    418:                if (errno != ENOENT)
                    419:                        cvs_log(LP_NOTICE, "failed to open `%s': %s", rcpath,
                    420:                            strerror(errno));
                    421:                return;
                    422:        }
                    423:
1.84      xsa       424:        while (fgets(linebuf, (int)sizeof(linebuf), fp) != NULL) {
1.23      xsa       425:                linenum++;
1.17      jfb       426:                if ((len = strlen(linebuf)) == 0)
                    427:                        continue;
                    428:                if (linebuf[len - 1] != '\n') {
1.98      joris     429:                        cvs_log(LP_ERR, "line too long in `%s:%d'", rcpath,
1.23      xsa       430:                                linenum);
1.17      jfb       431:                        break;
                    432:                }
                    433:                linebuf[--len] = '\0';
                    434:
1.70      joris     435:                /* skip any whitespaces */
                    436:                p = linebuf;
                    437:                while (*p == ' ')
1.95      deraadt   438:                        p++;
1.70      joris     439:
                    440:                /* allow comments */
                    441:                if (*p == '#')
                    442:                        continue;
                    443:
                    444:                lp = strchr(p, ' ');
1.1       jfb       445:                if (lp == NULL)
1.17      jfb       446:                        continue;       /* ignore lines with no arguments */
                    447:                *lp = '\0';
1.70      joris     448:                if (strcmp(p, "cvs") == 0) {
1.17      jfb       449:                        /*
                    450:                         * Global default options.  In the case of cvs only,
                    451:                         * we keep the 'cvs' string as first argument because
                    452:                         * getopt() does not like starting at index 0 for
                    453:                         * argument processing.
                    454:                         */
                    455:                        *lp = ' ';
1.88      joris     456:                        cvs_defargs = xstrdup(p);
1.15      deraadt   457:                } else {
1.17      jfb       458:                        lp++;
1.70      joris     459:                        cmdp = cvs_findcmd(p);
1.1       jfb       460:                        if (cmdp == NULL) {
                    461:                                cvs_log(LP_NOTICE,
1.25      xsa       462:                                    "unknown command `%s' in `%s:%d'",
1.70      joris     463:                                    p, rcpath, linenum);
1.1       jfb       464:                                continue;
                    465:                        }
1.17      jfb       466:
1.88      joris     467:                        cmdp->cmd_defargs = xstrdup(lp);
1.1       jfb       468:                }
                    469:        }
1.98      joris     470:
1.1       jfb       471:        if (ferror(fp)) {
1.23      xsa       472:                cvs_log(LP_NOTICE, "failed to read line from `%s'", rcpath);
1.1       jfb       473:        }
                    474:
                    475:        (void)fclose(fp);
1.27      jfb       476: }
                    477:
                    478: /*
                    479:  * cvs_var_set()
                    480:  *
                    481:  * Set the value of the variable <var> to <val>.  If there is no such variable,
                    482:  * a new entry is created, otherwise the old value is overwritten.
                    483:  * Returns 0 on success, or -1 on failure.
                    484:  */
                    485: int
                    486: cvs_var_set(const char *var, const char *val)
                    487: {
                    488:        char *valcp;
                    489:        const char *cp;
                    490:        struct cvs_var *vp;
                    491:
1.97      deraadt   492:        if (var == NULL || *var == '\0') {
1.27      jfb       493:                cvs_log(LP_ERR, "no variable name");
                    494:                return (-1);
                    495:        }
                    496:
                    497:        /* sanity check on the name */
                    498:        for (cp = var; *cp != '\0'; cp++)
                    499:                if (!isalnum(*cp) && (*cp != '_')) {
                    500:                        cvs_log(LP_ERR,
                    501:                            "variable name `%s' contains invalid characters",
                    502:                            var);
                    503:                        return (-1);
                    504:                }
                    505:
                    506:        TAILQ_FOREACH(vp, &cvs_variables, cv_link)
                    507:                if (strcmp(vp->cv_name, var) == 0)
                    508:                        break;
                    509:
1.88      joris     510:        valcp = xstrdup(val);
1.27      jfb       511:        if (vp == NULL) {
1.96      ray       512:                vp = xcalloc(1, sizeof(*vp));
1.27      jfb       513:
1.88      joris     514:                vp->cv_name = xstrdup(var);
1.27      jfb       515:                TAILQ_INSERT_TAIL(&cvs_variables, vp, cv_link);
                    516:
                    517:        } else  /* free the previous value */
1.88      joris     518:                xfree(vp->cv_val);
1.27      jfb       519:
                    520:        vp->cv_val = valcp;
                    521:
                    522:        return (0);
                    523: }
                    524:
                    525: /*
1.118     otto      526:  * cvs_var_unset()
1.27      jfb       527:  *
                    528:  * Remove any entry for the variable <var>.
                    529:  * Returns 0 on success, or -1 on failure.
                    530:  */
                    531: int
                    532: cvs_var_unset(const char *var)
                    533: {
                    534:        struct cvs_var *vp;
                    535:
                    536:        TAILQ_FOREACH(vp, &cvs_variables, cv_link)
                    537:                if (strcmp(vp->cv_name, var) == 0) {
                    538:                        TAILQ_REMOVE(&cvs_variables, vp, cv_link);
1.88      joris     539:                        xfree(vp->cv_name);
                    540:                        xfree(vp->cv_val);
                    541:                        xfree(vp);
1.27      jfb       542:                        return (0);
                    543:                }
                    544:
                    545:        return (-1);
                    546: }
                    547:
                    548: /*
                    549:  * cvs_var_get()
                    550:  *
                    551:  * Get the value associated with the variable <var>.  Returns a pointer to the
                    552:  * value string on success, or NULL if the variable does not exist.
                    553:  */
                    554:
1.75      xsa       555: const char *
1.27      jfb       556: cvs_var_get(const char *var)
                    557: {
                    558:        struct cvs_var *vp;
                    559:
                    560:        TAILQ_FOREACH(vp, &cvs_variables, cv_link)
                    561:                if (strcmp(vp->cv_name, var) == 0)
                    562:                        return (vp->cv_val);
                    563:
                    564:        return (NULL);
1.1       jfb       565: }