Module Name: src
Committed By: christos
Date: Sun Nov 22 20:24:19 UTC 2015
Modified Files:
src/sbin/cgdconfig: cgdconfig.c cgdconfig.h params.c
Log Message:
Don't chdir to the config directory; just form the parameters file with a
path if needed.
To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sbin/cgdconfig/cgdconfig.c
cvs rdiff -u -r1.1 -r1.2 src/sbin/cgdconfig/cgdconfig.h
cvs rdiff -u -r1.26 -r1.27 src/sbin/cgdconfig/params.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/cgdconfig/cgdconfig.c
diff -u src/sbin/cgdconfig/cgdconfig.c:1.39 src/sbin/cgdconfig/cgdconfig.c:1.40
--- src/sbin/cgdconfig/cgdconfig.c:1.39 Sun Dec 14 18:27:14 2014
+++ src/sbin/cgdconfig/cgdconfig.c Sun Nov 22 15:24:19 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.39 2014/12/14 23:27:14 christos Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.40 2015/11/22 20:24:19 christos Exp $ */
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 2002, 2003\
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.39 2014/12/14 23:27:14 christos Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.40 2015/11/22 20:24:19 christos Exp $");
#endif
#include <err.h>
@@ -68,7 +68,6 @@ __RCSID("$NetBSD: cgdconfig.c,v 1.39 201
#include "cgdconfig.h"
#include "prog_ops.h"
-#define CGDCONFIG_DIR "/etc/cgd"
#define CGDCONFIG_CFILE CGDCONFIG_DIR "/cgd.conf"
enum action {
@@ -524,22 +523,11 @@ configure(int argc, char **argv, struct
}
if (argc == 2) {
- char *pfile, *base;
+ char pfile[MAXPATHLEN];
/* make string writable for basename */
- base = strdup(dev);
- if (base == NULL)
- return -1;
-
- if (asprintf(&pfile, "%s/%s",
- CGDCONFIG_DIR, basename(base)) == -1) {
- free(base);
- return -1;
- }
-
- p = params_cget(pfile);
- free(pfile);
- free(base);
+ strlcpy(pfile, dev, sizeof(pfile));
+ p = params_cget(basename(pfile));
} else if (argc == 3) {
p = params_cget(argv[2]);
} else {
@@ -1124,10 +1112,6 @@ do_all(const char *cfile, int argc, char
return -1;
}
- ret = chdir(CGDCONFIG_DIR);
- if (ret == -1)
- warn("could not chdir to %s", CGDCONFIG_DIR);
-
ret = 0;
lineno = 0;
for (;;) {
Index: src/sbin/cgdconfig/cgdconfig.h
diff -u src/sbin/cgdconfig/cgdconfig.h:1.1 src/sbin/cgdconfig/cgdconfig.h:1.2
--- src/sbin/cgdconfig/cgdconfig.h:1.1 Tue Sep 8 18:16:56 2009
+++ src/sbin/cgdconfig/cgdconfig.h Sun Nov 22 15:24:19 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.h,v 1.1 2009/09/08 22:16:56 pooka Exp $ */
+/* $NetBSD: cgdconfig.h,v 1.2 2015/11/22 20:24:19 christos Exp $ */
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,4 +31,6 @@
int cgdconfig(int, char **);
+#define CGDCONFIG_DIR "/etc/cgd"
+
#endif /* _SBIN_CGDCONFIG_H_ */
Index: src/sbin/cgdconfig/params.c
diff -u src/sbin/cgdconfig/params.c:1.26 src/sbin/cgdconfig/params.c:1.27
--- src/sbin/cgdconfig/params.c:1.26 Tue Jun 16 19:18:54 2015
+++ src/sbin/cgdconfig/params.c Sun Nov 22 15:24:19 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: params.c,v 1.26 2015/06/16 23:18:54 christos Exp $ */
+/* $NetBSD: params.c,v 1.27 2015/11/22 20:24:19 christos Exp $ */
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -31,10 +31,12 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: params.c,v 1.26 2015/06/16 23:18:54 christos Exp $");
+__RCSID("$NetBSD: params.c,v 1.27 2015/11/22 20:24:19 christos Exp $");
#endif
#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
#include <err.h>
#include <errno.h>
@@ -46,6 +48,7 @@ __RCSID("$NetBSD: params.c,v 1.26 2015/0
#include "params.h"
#include "pkcs5_pbkdf2.h"
#include "utils.h"
+#include "cgdconfig.h"
#include "extern.h"
static void params_init(struct params *);
@@ -618,6 +621,14 @@ params_cget(const char *fn)
{
struct params *p;
FILE *f;
+ char filename[MAXPATHLEN];
+ struct stat st;
+
+ if (fn[0] != '/' && stat(fn, &st) == -1 && errno == ENOENT) {
+ snprintf(filename, sizeof(filename), "%s/%s",
+ CGDCONFIG_DIR, fn);
+ fn = filename;
+ }
if ((f = fopen(fn, "r")) == NULL) {
warn("failed to open params file \"%s\"", fn);