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