summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac10
-rw-r--r--helpers/mknod.c38
2 files changed, 24 insertions, 24 deletions
diff --git a/configure.ac b/configure.ac
index 28e5d94..bb5bad8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,12 +43,12 @@ test -d "${srcdir}/.git" || CFLAGS="${save_CFLAGS}"
funcs_missing=false
AC_CHECK_FUNCS(
[\
- calloc execve fclose fdopen feof ferror fopen fprintf fputc \
- fputs fread free fscanf fseek fwrite getgrgid getpwuid \
+ calloc execve fclose feof ferror fopen fprintf fputc fputs \
+ fread free fscanf fseek fstat fwrite getgrgid getpwuid \
localtime lstat malloc memcmp memcpy memset mkdir mkfifo open \
- printf puts readlink rename scandir sleep snprintf sprintf \
- stat strchr strcmp strcpy strftime strlen strncpy strtol \
- unlink vfprintf
+ printf puts readlink scandir sleep snprintf sprintf stat \
+ strchr strcmp strcpy strftime strlen strncpy strtol unlink \
+ vfprintf
],
[],
[funcs_missing=true])
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;