From: Philipp Takacs Date: Fri, 30 Jan 2015 01:25:17 +0000 (+0100) Subject: distout and ready_msg return NOTOK on error X-Git-Tag: mmh-0.2-RC1~56^2 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=a26d3f6e071fa5704406317fe50a1805659ed2f8;p=mmh distout and ready_msg return NOTOK on error If distout or ready_msg fails, the cleanup of send is done. --- diff --git a/uip/distsbr.c b/uip/distsbr.c index a9a52b1..42c3ce8 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -16,7 +16,7 @@ static int txtfd = NOTOK; /* ** static prototypes */ -static void ready_msg(char *); +static int ready_msg(char *); int distout(char *drft, char *msgnam, char *backup) @@ -29,18 +29,23 @@ distout(char *drft, char *msgnam, char *backup) strcpy(backup, m_mktemp(toabsdir(invo_name), NULL, NULL)); if (rename(drft, backup) == NOTOK) { - adios(backup, "unable to rename %s to",drft); + advise(backup, "unable to rename %s to",drft); + return NOTOK; } if (!(ifp = fopen(backup, "r"))) { - adios(backup, "unable to read"); + advise(backup, "unable to read"); + return NOTOK; } if (!(ofp = fopen(drft, "w"))) { - adios(drft, "unable to create temporary file"); + advise(drft, "unable to create temporary file"); + return NOTOK; } chmod(drft, m_gmprot()); - ready_msg(msgnam); + if (ready_msg(msgnam) != OK) { + return NOTOK; + } lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ cpydata(hdrfd, fileno(ofp), msgnam, drft); @@ -92,12 +97,13 @@ leave_bad: ; fclose(ofp); unlink(drft); if (rename(backup, drft) == NOTOK) { - adios(drft, "unable to rename %s to", backup); + advise(drft, "unable to rename %s to", backup); } return NOTOK; default: - adios(NULL, "getfld() returned %d", state); + advise(NULL, "getfld() returned %d", state); + return NOTOK; } } @@ -110,7 +116,7 @@ process: ; fclose(ofp); unlink(drft); if (rename(backup, drft) == NOTOK) { - adios(drft, "unable to rename %s to", backup); + advise(drft, "unable to rename %s to", backup); } return NOTOK; } @@ -127,7 +133,7 @@ process: ; } -static void +static int ready_msg(char *msgnam) { int state, out; @@ -144,17 +150,20 @@ ready_msg(char *msgnam) txtfd = NOTOK; } if (!(ifp = fopen(msgnam, "r"))) { - adios(msgnam, "unable to open message"); + advise(msgnam, "unable to open message"); + return NOTOK; } cp = m_mktemp2(NULL, "dist", &hdrfd, NULL); if (!cp) { - adios("distsbr", "unable to create temporary file"); + advise("distsbr", "unable to create temporary file"); + return NOTOK; } fchmod(hdrfd, 0600); strncpy(tmpfil, cp, sizeof(tmpfil)); if ((out = dup(hdrfd)) == NOTOK || !(ofp = fdopen(out, "w"))) { - adios(NULL, "no file descriptors -- you lose big"); + advise(NULL, "no file descriptors -- you lose big"); + return NOTOK; } unlink(tmpfil); @@ -185,13 +194,15 @@ ready_msg(char *msgnam) cp = m_mktemp2(NULL, "dist", &txtfd, NULL); if (!cp) { - adios("distsbr", "unable to create temp file"); + advise("distsbr", "unable to create temp file"); + return NOTOK; } fchmod(txtfd, 0600); strncpy(tmpfil, cp, sizeof(tmpfil)); if ((out = dup(txtfd)) == NOTOK || !(ofp = fdopen(out, "w"))) { - adios(NULL, "no file descriptors -- you lose"); + advise(NULL, "no file descriptors -- you lose"); + return NOTOK; } unlink(tmpfil); fprintf(ofp, "\n%s", buffer); @@ -205,13 +216,16 @@ ready_msg(char *msgnam) case LENERR: case FMTERR: - adios(NULL, "format error in message %s", msgnam); + advise(NULL, "format error in message %s", msgnam); + return NOTOK; default: - adios(NULL, "getfld() returned %d", state); + advise(NULL, "getfld() returned %d", state); + return NOTOK; } } process: ; fclose(ifp); fclose(ofp); + return OK; }