aboutsummaryrefslogtreecommitdiffstats
path: root/sbin/gbde
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2004-02-05 10:57:29 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2004-02-05 10:57:29 +0000
commitfef1e56d1ec276846460508873b744e06be13edf (patch)
tree829b9021fb0c3721c5d9b794d181e53373e5e3bb /sbin/gbde
parentf7644f46f031d8c70a6dba6d4186278c85799656 (diff)
downloadsrc-fef1e56d1ec276846460508873b744e06be13edf.tar.gz
src-fef1e56d1ec276846460508873b744e06be13edf.zip
Don't create a template file if we're not going to let the user edit it.
Notes
Notes: svn path=/head/; revision=125477
Diffstat (limited to 'sbin/gbde')
-rw-r--r--sbin/gbde/gbde.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/sbin/gbde/gbde.c b/sbin/gbde/gbde.c
index d038e7bec137..b90ac35ae308 100644
--- a/sbin/gbde/gbde.c
+++ b/sbin/gbde/gbde.c
@@ -507,25 +507,25 @@ cmd_init(struct g_bde_key *gl, int dfd, const char *f_opt, int i_opt, const char
err(1, "%s", f_opt);
params = properties_read(i);
close (i);
- } else {
+ } else if (i_opt) {
/* XXX: Polish */
- q = strdup("/tmp/temp.XXXXXXXXXX");
+ asprintf(&q, "%stemp.XXXXXXXXXX", _PATH_TMP);
+ if (q == NULL)
+ err(1, "asprintf");
i = mkstemp(q);
if (i < 0)
err(1, "%s", q);
write(i, template, strlen(template));
close (i);
- if (i_opt) {
- p = getenv("EDITOR");
- if (p == NULL)
- p = "vi";
- if (snprintf(cbuf, sizeof(cbuf), "%s %s\n", p, q) >=
- (ssize_t)sizeof(cbuf)) {
- unlink(q);
- errx(1, "EDITOR is too long");
- }
- system(cbuf);
+ p = getenv("EDITOR");
+ if (p == NULL)
+ p = "vi";
+ if (snprintf(cbuf, sizeof(cbuf), "%s %s\n", p, q) >=
+ (ssize_t)sizeof(cbuf)) {
+ unlink(q);
+ errx(1, "EDITOR is too long");
}
+ system(cbuf);
i = open(q, O_RDONLY);
if (i < 0)
err(1, "%s", f_opt);
@@ -533,6 +533,13 @@ cmd_init(struct g_bde_key *gl, int dfd, const char *f_opt, int i_opt, const char
close (i);
unlink(q);
free(q);
+ } else {
+ /* XXX: Hack */
+ i = open(_PATH_DEVNULL, O_RDONLY);
+ if (i < 0)
+ err(1, "%s", _PATH_DEVNULL);
+ params = properties_read(i);
+ close (i);
}
/* <sector_size> */
@@ -620,13 +627,15 @@ cmd_init(struct g_bde_key *gl, int dfd, const char *f_opt, int i_opt, const char
/* <number_of_keys> */
p = property_find(params, "number_of_keys");
- if (p == NULL)
- errx(1, "Missing number_of_keys property");
- nkeys = strtoul(p, &q, 0);
- if (!*p || *q)
- errx(1, "number_of_keys not a proper number");
- if (nkeys < 1 || nkeys > G_BDE_MAXKEYS)
- errx(1, "number_of_keys out of range");
+ if (p != NULL) {
+ nkeys = strtoul(p, &q, 0);
+ if (!*p || *q)
+ errx(1, "number_of_keys not a proper number");
+ if (nkeys < 1 || nkeys > G_BDE_MAXKEYS)
+ errx(1, "number_of_keys out of range");
+ } else {
+ nkeys = 4;
+ }
for (u = 0; u < nkeys; u++) {
for(;;) {
do {