summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--helpers/mknod.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/helpers/mknod.c b/helpers/mknod.c
index 9504b09..bafe663 100644
--- a/helpers/mknod.c
+++ b/helpers/mknod.c
@@ -267,8 +267,7 @@ main(int argc, char *argv[])
fd = open(name, O_CREAT | O_EXCL, mode);
if (fd < 0 || close(fd) < 0) {
_errno(_("Failed to create node"));
- free(specials_file_name);
- return EXIT_FAILURE;
+ goto err0;
}
/* Acquire lock ("specials~"). */
@@ -280,9 +279,7 @@ main(int argc, char *argv[])
}
}
_errno(_("Failed to lock specials file"));
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
+ goto err1;
opened:
close(specials_fd);
@@ -290,42 +287,27 @@ main(int argc, char *argv[])
specials_file = fopen(specials_file_name, "a");
if (specials_file == NULL) {
_errno(_("Failed to open specials file stream"));
- unlink(specials_lock_name);
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
+ goto err2;
}
/* If "specials" is empty, write header. */
if (fstat(fileno(specials_file), &stat_buf) != 0) {
_errno(_("Failed to stat specials file"));
- fclose(specials_file);
- unlink(specials_lock_name);
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
+ goto err3;
}
if (stat_buf.st_size == 0) {
if (fputs("version=1\n", specials_file) < 0 ||
fputs("type major minor name\n",
specials_file) < 0) {
_errno(_("Failed to write specials file"));
- fclose(specials_file);
- unlink(specials_lock_name);
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
+ goto err3;
}
}
if (fprintf(specials_file, "%c %8ld %8ld %s\n",
type, major, minor, name + work_area_len) < 0) {
_errno(_("Failed to write specials file"));
- fclose(specials_file);
- unlink(specials_lock_name);
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
+ goto err3;
}
fclose(specials_file);
@@ -333,4 +315,14 @@ main(int argc, char *argv[])
free(specials_file_name);
return EXIT_SUCCESS;
+
+ err3:
+ fclose(specials_file);
+ err2:
+ unlink(specials_lock_name);
+ err1:
+ unlink(name);
+ err0:
+ free(specials_file_name);
+ return EXIT_FAILURE;
}