setup: joinpasswd.c Report better errors.

arekm arekm at pld-linux.org
Thu Dec 8 11:00:57 CET 2011


Author: arekm                        Date: Thu Dec  8 10:00:57 2011 GMT
Module: setup                         Tag: HEAD
---- Log message:
Report better errors.

---- Files affected:
setup:
   joinpasswd.c (1.12 -> 1.13) 

---- Diffs:

================================================================
Index: setup/joinpasswd.c
diff -u setup/joinpasswd.c:1.12 setup/joinpasswd.c:1.13
--- setup/joinpasswd.c:1.12	Thu Dec  8 10:31:56 2011
+++ setup/joinpasswd.c	Thu Dec  8 11:00:52 2011
@@ -60,8 +60,10 @@
 #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>
@@ -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 @@
 	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 @@
 
 	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 @@
 				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++;
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/setup/joinpasswd.c?r1=1.12&r2=1.13&f=u



More information about the pld-cvs-commit mailing list