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