Leave nat_ann, nat_tgm alone and return -1 on all errors. Before,
only failed open was handled that way. Failed write and close were
logged and ignored. While there, improve the log messages a bit.
Note: the return value fix has little effect. It makes tele() log the
failure, which is redundant. Everything else goes through wu() and
ignores the value.
struct iovec iov[2];
int fd;
char box[1024];
struct iovec iov[2];
int fd;
char box[1024];
int new_tele = 0;
struct player *other;
int new_tele = 0;
struct player *other;
#else
if ((fd = open(box, O_WRONLY | O_APPEND | O_BINARY, 0)) < 0) {
#endif
#else
if ((fd = open(box, O_WRONLY | O_APPEND | O_BINARY, 0)) < 0) {
#endif
- logerror("telegram 'open' of %s (#%d) failed", box, to);
+ logerror("telegram 'open' of %s failed", box);
memset(&tel, 0, sizeof(tel));
tel.tel_from = from;
(void)time(&tel.tel_date);
memset(&tel, 0, sizeof(tel));
tel.tel_from = from;
(void)time(&tel.tel_date);
iov[1].iov_base = message;
iov[1].iov_len = len;
if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) {
iov[1].iov_base = message;
iov[1].iov_len = len;
if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) {
- logerror("telegram 'write' to #%d failed", to);
- } else
- write_ok = 1;
+ logerror("telegram 'write' to %s failed", box);
+ close(fd);
+ return -1;
+ }
+ if (close(fd) < 0) {
+ logerror("telegram 'write' to %s failed to close.", box);
+ return -1;
+ }
- if (close(fd) == -1) {
- logerror("telegram 'write' to #%d failed to close.", to);
- } else if (write_ok && type == TEL_ANNOUNCE) {
+ if (type == TEL_ANNOUNCE) {
for (to = 0; NULL != (np = getnatp(to)); to++) {
if (np->nat_stat < STAT_SANCT)
continue;
for (to = 0; NULL != (np = getnatp(to)); to++) {
if (np->nat_stat < STAT_SANCT)
continue;
np->nat_ann++;
putnat(np);
}
np->nat_ann++;
putnat(np);
}
new_tele = telegram_is_new(to, &tel);
np->nat_tgms += new_tele || np->nat_tgms == 0;
putnat(np);
new_tele = telegram_is_new(to, &tel);
np->nat_tgms += new_tele || np->nat_tgms == 0;
putnat(np);