summaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/mknod.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/helpers/mknod.c b/helpers/mknod.c
index 23683d8..e9e9737 100644
--- a/helpers/mknod.c
+++ b/helpers/mknod.c
@@ -251,51 +251,51 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
opened:
- specials_file = fdopen(specials_fd, "a");
+ close(specials_fd);
+
+ specials_file = fopen(specials_file_name, "a");
if (specials_file == NULL) {
_err(_("Failed to open specials file stream"));
- close(specials_fd);
+ unlink(specials_lock_name);
free(specials_file_name);
unlink(name);
return EXIT_FAILURE;
}
- /* If "specials" doesn't exist, write header. */
- if (stat(specials_file_name, &stat_buf) != 0) {
- if (errno != ENOENT) {
- _err(_("Failed to stat specials file"));
- fclose(specials_file);
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
- }
+ /* If "specials" is empty, write header. */
+ if (fstat(fileno(specials_file), &stat_buf) != 0) {
+ _err(_("Failed to stat specials file"));
+ fclose(specials_file);
+ unlink(specials_lock_name);
+ free(specials_file_name);
+ unlink(name);
+ return EXIT_FAILURE;
+ }
+ if (stat_buf.st_size == 0) {
if (fputs("version=1\n", specials_file) < 0 ||
fputs("type major minor name\n",
specials_file) < 0) {
_err(_("Failed to write specials file"));
fclose(specials_file);
+ unlink(specials_lock_name);
free(specials_file_name);
unlink(name);
return EXIT_FAILURE;
}
}
+
if (fprintf(specials_file, "%c %8ld %8ld %s\n", type, major, minor,
name) < 0) {
_err(_("Failed to write specials file"));
fclose(specials_file);
- free(specials_file_name);
- unlink(name);
- return EXIT_FAILURE;
- }
- fclose(specials_file);
-
- if (rename(specials_lock_name, specials_file_name) != 0) {
- _err(_("Failed to move specials file"));
+ unlink(specials_lock_name);
free(specials_file_name);
unlink(name);
return EXIT_FAILURE;
}
+ fclose(specials_file);
+ unlink(specials_lock_name);
free(specials_file_name);
return EXIT_SUCCESS;