]> git.pld-linux.org Git - projects/setup.git/commitdiff
Report better errors.
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Thu, 8 Dec 2011 10:00:52 +0000 (10:00 +0000)
committerArkadiusz Miśkiewicz <arekm@maven.pl>
Thu, 8 Dec 2011 10:00:52 +0000 (10:00 +0000)
Changed files:
    joinpasswd.c -> 1.13

joinpasswd.c

index 18799f1a997126344c7d89286ea0afc6a75268cb..fea4a310bd1a1f53f9e74439aaaef56a2173615f 100644 (file)
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
+#include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <stdarg.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 
 /* #define SILENT */
 
-void eputs(const char *msg)
+void eputs(const char *fmt, ...)
 {
-       write(2, msg, strlen(msg));
+       va_list args;
+
+       va_start(args, fmt);
+       vfprintf(stderr, fmt, args);
+       va_end(args);
 }
 
-void fatal(const char *msg)
+void fatal(const char *fmt, ...)
 {
-       eputs(msg);
+       va_list args;
+
+       va_start(args, fmt);
+       eputs(fmt, args);
+       va_end(args);
+
        eputs("\n");
        exit(1);
 }
@@ -271,17 +282,17 @@ int join(const char *old_name, const char *new_name, const char *backup_name)
        lock(old_name);
        old = map_file(old_name, &old_sz);
        if (old == NULL)
-               fatal("cannot mmap old");
+               fatal("cannot mmap file `%s': %m", old_name);
        
        fd = open(backup_name, O_WRONLY|O_CREAT|O_TRUNC, 0600);
        if (fd < 0)
-               fatal("cannot create backup file");
+               fatal("cannot create backup file `%s': %m", backup_name);
        if (write(fd, old, old_sz) < 0)
-               fatal("writting to backup file failed");
+               fatal("writting to backup file `%s' failed: %m", backup_name);
        if (fsync(fd) < 0)
-               fatal("syncing backup file failed");
+               fatal("syncing backup file `%s' failed: %m", backup_name);
        if (close(fd) < 0)
-               fatal("closing backup file failed");
+               fatal("closing backup file `%s' failed: %m", backup_name);
        
 #ifndef SILENT
        eputs("merging content of `");
@@ -293,7 +304,7 @@ int join(const char *old_name, const char *new_name, const char *backup_name)
 
        fd = open(old_name, O_WRONLY|O_APPEND);
        if (fd < 0)
-               fatal("cannot open old file");
+               fatal("cannot open old file `%s': %m", old_name);
        
        for (i = 0; i < new_sz; ) {
                id = new + i;
@@ -317,7 +328,7 @@ int join(const char *old_name, const char *new_name, const char *backup_name)
                                eputs("'\n");
 #endif /* SILENT */
                                if (write(fd, id, line_len) < 0)
-                                       fatal("writting line failed, most likely you will need backup to restore backup file");
+                                       fatal("writting line to `%s' failed, check backup file: %m", old_name);
                        }
                } else if (i < new_sz)
                        i++;
This page took 0.132381 seconds and 4 git commands to generate.