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

Annotation of src/usr.bin/cvs/config.c, Revision 1.17

1.17    ! nicm        1: /*     $OpenBSD: config.c,v 1.16 2015/01/16 06:40:07 deraadt Exp $     */
1.1       joris       2: /*
                      3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17:
1.16      deraadt    18: #include <sys/types.h>
1.9       otto       19: #include <sys/dirent.h>
                     20: #include <sys/resource.h>
                     21:
                     22: #include <errno.h>
1.12      tobias     23: #include <limits.h>
1.9       otto       24: #include <stdlib.h>
                     25: #include <string.h>
1.1       joris      26:
                     27: #include "cvs.h"
                     28: #include "config.h"
                     29:
                     30: void
                     31: cvs_parse_configfile(void)
                     32: {
1.13      joris      33:        cvs_log(LP_TRACE, "cvs_parse_configfile()");
                     34:        cvs_read_config(CVS_PATH_CONFIG, config_parse_line);
                     35: }
                     36:
1.15      joris      37: int
1.14      joris      38: config_parse_line(char *line, int lineno)
1.13      joris      39: {
                     40:        struct rlimit rl;
                     41:        const char *errstr;
                     42:        char *val, *opt, *ep;
                     43:
                     44:        opt = line;
                     45:        if ((val = strrchr(opt, '=')) == NULL)
                     46:                fatal("cvs_parse_configfile: bad option '%s'", opt);
                     47:
                     48:        *(val++) = '\0';
                     49:
                     50:        if (!strcmp(opt, "tag")) {
1.17    ! nicm       51:                free(cvs_tagname);
1.13      joris      52:                cvs_tagname = xstrdup(val);
                     53:        } else if (!strcmp(opt, "umask")) {
                     54:                cvs_umask = strtol(val, &ep, 8);
                     55:
                     56:                if (val == ep || *ep != '\0')
                     57:                        fatal("cvs_parse_configfile: umask %s is "
                     58:                            "invalid", val);
                     59:                if (cvs_umask < 0 || cvs_umask > 07777)
                     60:                        fatal("cvs_parse_configfile: umask %s is "
                     61:                            "invalid", val);
                     62:        } else if (!strcmp(opt, "dlimit")) {
                     63:                if (getrlimit(RLIMIT_DATA, &rl) != -1) {
                     64:                        rl.rlim_cur = (int)strtonum(val, 0, INT_MAX,
                     65:                            &errstr);
                     66:                        if (errstr != NULL)
                     67:                                fatal("cvs_parse_configfile: %s: %s",
                     68:                                    val, errstr);
                     69:                        rl.rlim_cur = rl.rlim_cur * 1024;
                     70:                        (void)setrlimit(RLIMIT_DATA, &rl);
                     71:                }
                     72:        } else {
                     73:                cvs_log(LP_ERR, "ignoring unknown option '%s'", opt);
                     74:        }
1.15      joris      75:
                     76:        return (0);
1.13      joris      77: }
                     78:
                     79: void
1.15      joris      80: cvs_read_config(char *name, int (*cb)(char *, int))
1.13      joris      81: {
1.1       joris      82:        FILE *fp;
                     83:        size_t len;
1.14      joris      84:        int lineno;
1.16      deraadt    85:        char *p, *buf, *lbuf, fpath[PATH_MAX];
1.1       joris      86:
1.8       xsa        87:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
1.13      joris      88:            current_cvsroot->cr_dir, name);
1.6       xsa        89:
1.13      joris      90:        if ((fp = fopen(fpath, "r")) == NULL)
1.10      xsa        91:                return;
1.1       joris      92:
                     93:        lbuf = NULL;
1.14      joris      94:        lineno = 0;
1.13      joris      95:        while ((buf = fgetln(fp, &len)) != NULL) {
1.14      joris      96:                lineno++;
1.1       joris      97:                if (buf[len - 1] == '\n') {
                     98:                        buf[len - 1] = '\0';
                     99:                } else {
                    100:                        lbuf = xmalloc(len + 1);
1.7       otto      101:                        memcpy(lbuf, buf, len);
                    102:                        lbuf[len] = '\0';
1.1       joris     103:                        buf = lbuf;
                    104:                }
                    105:
1.2       joris     106:                p = buf;
1.13      joris     107:                while (*p == ' ' || *p == '\t')
1.2       joris     108:                        p++;
                    109:
1.13      joris     110:                if (p[0] == '#' || p[0] == '\0')
1.2       joris     111:                        continue;
                    112:
1.15      joris     113:                if (cb(p, lineno) < 0)
                    114:                        break;
1.13      joris     115:        }
1.1       joris     116:
1.17    ! nicm      117:        free(lbuf);
1.1       joris     118:        (void)fclose(fp);
                    119: }