summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2009-05-29 01:49:57 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2009-05-29 01:49:57 +0000
commit87d5711839a38fd20c41eeeea639be7ec43beac3 (patch)
treeba45f3823e45fb7c963bc1c2bf9605c80ab9510c /sbin
parentb463445cd7d52203a347452777be48abfdb8a4d8 (diff)
Clean up logic around exit values. Make getasciilabel() return 0
for success. Fix a couple of bugs where errors in checklabel() got lost. Make Editor 'q' and 'x' commands exit with 0 (ok) rather than 1. i.e. non-zero exit value now reserved for failure, not a decision to leave the disklabel unchanged. This allows the install script to use the exit value to catch failures to write a disklabel.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/disklabel/disklabel.c24
-rw-r--r--sbin/disklabel/editor.c10
2 files changed, 18 insertions, 16 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index 0b2854472b7..0887246a89f 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.154 2009/05/17 01:17:12 krw Exp $ */
+/* $OpenBSD: disklabel.c,v 1.155 2009/05/29 01:49:56 krw Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -39,7 +39,7 @@ static const char copyright[] =
#endif /* not lint */
#ifndef lint
-static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.154 2009/05/17 01:17:12 krw Exp $";
+static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.155 2009/05/29 01:49:56 krw Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -308,10 +308,9 @@ main(int argc, char *argv[])
lp = makebootarea(bootarea, &lab, f);
if (!(t = fopen(argv[1], "r")))
err(4, "%s", argv[1]);
- if (getasciilabel(t, lp))
+ error = getasciilabel(t, lp);
+ if (error == 0)
error = writelabel(f, bootarea, lp);
- else
- error = 1;
fclose(t);
break;
case SETWRITEABLE:
@@ -329,7 +328,8 @@ main(int argc, char *argv[])
makelabel(argv[1], argc == 3 ? argv[2] : NULL, &lab);
lp = makebootarea(bootarea, &lab, f);
*lp = lab;
- if (checklabel(lp) == 0)
+ error = checklabel(&lab);
+ if (error == 0)
error = writelabel(f, bootarea, lp);
break;
#if NUMBOOT > 0
@@ -343,7 +343,8 @@ main(int argc, char *argv[])
makelabel(argv[1], NULL, &lab);
lp = makebootarea(bootarea, &lab, f);
*lp = tlab;
- if (checklabel(lp) == 0)
+ error = checklabel(&lab);
+ if (error == 0)
error = writelabel(f, bootarea, lp);
break;
}
@@ -1037,7 +1038,7 @@ display(FILE *f, struct disklabel *lp, char unit, int all)
int
edit(struct disklabel *lp, int f)
{
- int first, ch, fd;
+ int first, ch, fd, error = 0;
struct disklabel label;
FILE *fp;
@@ -1066,7 +1067,8 @@ edit(struct disklabel *lp, int f)
break;
}
memset(&label, 0, sizeof(label));
- if (getasciilabel(fp, &label)) {
+ error = getasciilabel(fp, &label);
+ if (error == 0) {
if (cmplabel(lp, &label) == 0) {
puts("No changes.");
fclose(fp);
@@ -1493,7 +1495,7 @@ getasciilabel(FILE *f, struct disklabel *lp)
;
}
errors += checklabel(lp);
- return (errors == 0);
+ return (errors > 0);
}
/*
@@ -1598,7 +1600,7 @@ checklabel(struct disklabel *lp)
warnx("warning, unused partition %c: size %lld offset %lld",
'a' + i, DL_GETPSIZE(pp), DL_GETPOFFSET(pp));
}
- return (errors);
+ return (errors > 0);
}
#if NUMBOOT > 0
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index d958136642b..37ae40d1b17 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.212 2009/05/17 02:49:45 krw Exp $ */
+/* $OpenBSD: editor.c,v 1.213 2009/05/29 01:49:56 krw Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: editor.c,v 1.212 2009/05/17 02:49:45 krw Exp $";
+static char rcsid[] = "$OpenBSD: editor.c,v 1.213 2009/05/29 01:49:56 krw Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -340,7 +340,7 @@ editor(struct disklabel *lp, int f)
case 'q':
if (donothing) {
puts("In no change mode, not writing label.");
- return(1);
+ return(0);
}
/* Save mountpoint info if there is any. */
mpsave(&label);
@@ -355,7 +355,7 @@ editor(struct disklabel *lp, int f)
if (!dflag && !aflag &&
memcmp(lp, &label, sizeof(label)) == 0) {
puts("No label changes.");
- return(1);
+ return(0);
}
do {
arg = getstring("Write new label?",
@@ -454,7 +454,7 @@ editor(struct disklabel *lp, int f)
break;
case 'x':
- return(1);
+ return(0);
break;
case 'z':