]> git.pond.sub.org Git - empserver/commitdiff
Check for mailbox creation failure
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Nov 2011 15:06:01 +0000 (16:06 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 29 Dec 2011 10:47:07 +0000 (11:47 +0100)
Deity command add logs the failure, utility program files reports it
and exits unsuccessfully.  Before, this failure was silently ignored.

src/lib/common/mailbox.c
src/util/files.c

index c749eddd7bda635af6f3355483a05999e800023e..15418ca41d44838fbefba4feca55e97c6c63a8f1 100644 (file)
  *  mailbox.c: Mailbox file access
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2009
+ *     Markus Armbruster, 2009-2011
  */
 
 #include <config.h>
 
 #include <stdio.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -49,11 +50,18 @@ mailbox(char *buf, natid cn)
 
 /*
  * Create an empty telegram file named MBOX.
+ * Return 0 on success, -1 on failure.
  */
 int
 mailbox_create(char *mbox)
 {
-    close(creat(mbox, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
+    int fd;
+
+    fd = creat(mbox, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+    if (fd < 0 || close(fd) < 0) {
+       logerror("Can't create mailbox %s (%s)", mbox, strerror(errno));
+       return -1;
+    }
     return 0;
 }
 
index c5e78a845853b63e25ebdab95b1dec67638d4894..986ab6f6a0ef988441f55f2955c90e328a3dc2ba 100644 (file)
@@ -139,9 +139,11 @@ main(int argc, char *argv[])
        exit(1);
     }
     for (i = 0; i < MAXNOC; i++) {
-       mailbox_create(mailbox(buf, i));
+       if (mailbox_create(mailbox(buf, i)) < 0)
+           exit(1);
     }
-    mailbox_create(annfil);
+    if (mailbox_create(annfil) < 0)
+       exit(1);
 
     nat_reset(&nat, 0, "POGO", "peter", STAT_GOD);
     putnat(&nat);