Check for mailbox creation failure

Deity command add logs the failure, utility program files reports it
and exits unsuccessfully.  Before, this failure was silently ignored.
This commit is contained in:
Markus Armbruster 2011-11-26 16:06:01 +01:00
parent c4337f7aec
commit cda63a40d8
2 changed files with 14 additions and 4 deletions

View file

@ -27,12 +27,13 @@
* mailbox.c: Mailbox file access * mailbox.c: Mailbox file access
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2009 * Markus Armbruster, 2009-2011
*/ */
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@ -49,11 +50,18 @@ mailbox(char *buf, natid cn)
/* /*
* Create an empty telegram file named MBOX. * Create an empty telegram file named MBOX.
* Return 0 on success, -1 on failure.
*/ */
int int
mailbox_create(char *mbox) 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; return 0;
} }

View file

@ -139,9 +139,11 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
for (i = 0; i < MAXNOC; i++) { 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); nat_reset(&nat, 0, "POGO", "peter", STAT_GOD);
putnat(&nat); putnat(&nat);