Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/cgdconfig Don't chdir to the config directory; just for...
details: https://anonhg.NetBSD.org/src/rev/02df50a5bf37
branches: trunk
changeset: 341799:02df50a5bf37
user: christos <christos%NetBSD.org@localhost>
date: Sun Nov 22 20:24:19 2015 +0000
description:
Don't chdir to the config directory; just form the parameters file with a
path if needed.
diffstat:
sbin/cgdconfig/cgdconfig.c | 26 +++++---------------------
sbin/cgdconfig/cgdconfig.h | 4 +++-
sbin/cgdconfig/params.c | 15 +++++++++++++--
3 files changed, 21 insertions(+), 24 deletions(-)
diffs (125 lines):
diff -r 18c68cb8158e -r 02df50a5bf37 sbin/cgdconfig/cgdconfig.c
--- a/sbin/cgdconfig/cgdconfig.c Sun Nov 22 18:44:25 2015 +0000
+++ b/sbin/cgdconfig/cgdconfig.c Sun Nov 22 20:24:19 2015 +0000
@@ -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 @@
#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 @@
}
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 @@
return -1;
}
- ret = chdir(CGDCONFIG_DIR);
- if (ret == -1)
- warn("could not chdir to %s", CGDCONFIG_DIR);
-
ret = 0;
lineno = 0;
for (;;) {
diff -r 18c68cb8158e -r 02df50a5bf37 sbin/cgdconfig/cgdconfig.h
--- a/sbin/cgdconfig/cgdconfig.h Sun Nov 22 18:44:25 2015 +0000
+++ b/sbin/cgdconfig/cgdconfig.h Sun Nov 22 20:24:19 2015 +0000
@@ -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_ */
diff -r 18c68cb8158e -r 02df50a5bf37 sbin/cgdconfig/params.c
--- a/sbin/cgdconfig/params.c Sun Nov 22 18:44:25 2015 +0000
+++ b/sbin/cgdconfig/params.c Sun Nov 22 20:24:19 2015 +0000
@@ -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 @@
#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 @@
{
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);
Home |
Main Index |
Thread Index |
Old Index