From: Arkadiusz Miƛkiewicz Date: Thu, 8 Dec 2011 10:00:52 +0000 (+0000) Subject: Report better errors. X-Git-Tag: setup-2.9.0~29 X-Git-Url: https://git.pld-linux.org/?a=commitdiff_plain;h=cbc25e753ce750f4dd937695904580e0f83ef22b;p=projects%2Fsetup.git Report better errors. Changed files: joinpasswd.c -> 1.13 --- diff --git a/joinpasswd.c b/joinpasswd.c index 18799f1..fea4a31 100644 --- a/joinpasswd.c +++ b/joinpasswd.c @@ -60,8 +60,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -82,14 +84,23 @@ /* #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++;