Annotation of src/usr.bin/cvs/config.c, Revision 1.12
1.12 ! tobias 1: /* $OpenBSD: config.c,v 1.11 2007/10/18 12:13:20 tobias 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.9 otto 18: #include <sys/param.h>
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: {
33: FILE *fp;
34: size_t len;
1.3 joris 35: struct rlimit rl;
1.1 joris 36: const char *errstr;
1.12 ! tobias 37: char *p, *buf, *ep, *lbuf, *opt, *val, fpath[MAXPATHLEN];
1.1 joris 38:
1.8 xsa 39: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
40: current_cvsroot->cr_dir, CVS_PATH_CONFIG);
1.6 xsa 41:
42: cvs_log(LP_TRACE, "cvs_parse_configfile(%s)", fpath);
1.1 joris 43:
1.10 xsa 44: if ((fp = fopen(fpath, "r")) == NULL) {
45: if (errno != ENOENT)
46: cvs_log(LP_ERRNO, "%s", CVS_PATH_CONFIG);
47: return;
48: }
1.1 joris 49:
50: lbuf = NULL;
51: while ((buf = fgetln(fp, &len))) {
52: if (buf[len - 1] == '\n') {
53: buf[len - 1] = '\0';
54: } else {
55: lbuf = xmalloc(len + 1);
1.7 otto 56: memcpy(lbuf, buf, len);
57: lbuf[len] = '\0';
1.1 joris 58: buf = lbuf;
59: }
60:
1.2 joris 61: p = buf;
62: while (*p == ' ')
63: p++;
64:
65: if (p[0] == '#' || p[0] == '\0') {
66: if (lbuf != NULL)
67: xfree(lbuf);
68: continue;
69: }
70:
71: opt = p;
1.1 joris 72: if ((val = strrchr(opt, '=')) == NULL)
73: fatal("cvs_parse_configfile: bad option '%s'", opt);
74:
75: *(val++) = '\0';
76:
77: if (!strcmp(opt, "tag")) {
1.11 tobias 78: if (cvs_tagname != NULL)
79: xfree(cvs_tagname);
1.1 joris 80: cvs_tagname = xstrdup(val);
81: } else if (!strcmp(opt, "umask")) {
1.12 ! tobias 82: cvs_umask = strtol(val, &ep, 8);
! 83:
! 84: if (val == ep || *ep != '\0')
! 85: fatal("cvs_parse_configfile: umask %s is "
! 86: "invalid", val);
! 87: if (cvs_umask < 0 || cvs_umask > 07777)
! 88: fatal("cvs_parse_configfile: umask %s is "
! 89: "invalid", val);
1.3 joris 90: } else if (!strcmp(opt, "dlimit")) {
91: if (getrlimit(RLIMIT_DATA, &rl) != -1) {
92: rl.rlim_cur = (int)strtonum(val, 0, INT_MAX,
93: &errstr);
94: if (errstr != NULL)
95: fatal("cvs_parse_configfile: %s: %s",
96: val, errstr);
97: rl.rlim_cur = rl.rlim_cur * 1024;
98: (void)setrlimit(RLIMIT_DATA, &rl);
99: }
1.1 joris 100: } else {
101: cvs_log(LP_ERR, "ignoring unknown option '%s'", opt);
102: }
103:
104: if (lbuf != NULL)
105: xfree(lbuf);
106: }
107:
108: (void)fclose(fp);
109: }