AmendHub

Download:

jcs

/

subtext

/

amendments

/

564

binkp: Handle packet tossing better

On what looks like a permanent error (not malloc or network), assume
the file is bad and skip it, moving it to the "bad" folder and now
sending mail to the sysop.

jcs made amendment 564 12 months ago
--- binkp.c Tue Nov 21 21:23:01 2023 +++ binkp.c Thu Nov 23 13:52:56 2023 @@ -55,7 +55,7 @@ void binkp_ingest(void); bool binkp_zip_decider(char *filename, size_t size); void binkp_fidopkt_processor(char *filename, unsigned char *data, size_t size); -size_t binkp_buffer_file(Str255 path, char **data); +ssize_t binkp_buffer_file(Str255 path, char **data); void binkp_toss_inbox(void); void binkp_deliver_outbox(void); @@ -545,7 +545,7 @@ binkp_read_frame(void) SUBTEXT_CREATOR, 'BINK'); } if (error) { - warn("failed creating %s: %d", + warn("Failed creating %s: %d", PtoCstr(binkpc->cur_incoming_file.pfilename), error); CtoPstr(binkpc->cur_incoming_file.pfilename); goto failed_read; @@ -554,7 +554,7 @@ binkp_read_frame(void) error = FSOpen(binkpc->cur_incoming_file.pfilename, 0, &binkpc->cur_incoming_file.frefnum); if (error) { - warn("failed opening %s: %d", + warn("Failed opening %s: %d", PtoCstr(binkpc->cur_incoming_file.pfilename), error); CtoPstr(binkpc->cur_incoming_file.pfilename); goto failed_read; @@ -563,7 +563,7 @@ binkp_read_frame(void) len = binkpc->cur_incoming_file.size; error = Allocate(binkpc->cur_incoming_file.frefnum, &len); if (error) { - warn("failed setting %s to size %ld: %d", + warn("Failed setting %s to size %ld: %d", PtoCstr(binkpc->cur_incoming_file.pfilename), binkpc->cur_incoming_file.size, error); CtoPstr(binkpc->cur_incoming_file.pfilename); @@ -708,8 +708,8 @@ binkp_toss_inbox(void) Str255 file_name_c, path, done_path; short dir_id, error, zret; unsigned long started = Time, elapsed; - size_t data_size; - char *data; + ssize_t data_size; + char *data, *errmail; bool bad; binkp_fidopkt_skipped = 0; @@ -767,7 +767,10 @@ binkp_toss_inbox(void) data_size = binkp_buffer_file(path, &data); if (data_size == 0) binkp_temp_fail = true; - else { + else if (data_size == -1) { + logger_printf("[binkp] Permanent failure, skipping file"); + bad = true; + } else { binkp_fidopkt_processor((char *)file_name_c, (unsigned char *)data, data_size); xfree(&data); @@ -796,6 +799,20 @@ binkp_toss_inbox(void) PtoCstr(binkp_bad_dir); snprintf((char *)done_path, sizeof(done_path), "%s:%s", binkp_bad_dir, file_name_c); + + errmail = xmalloc(512); + if (errmail != NULL) { + snprintf(errmail, 512, + "A permanent error occurred while tossing file " + "\"%s\" and it\r\n" + "has been moved to the \"bad\" folder for further " + "inspection:\r\n\r\n%s", + file_name_c, done_path); + + mail_to_sysop("Failed tossing file", errmail); + xfree(&errmail); + } + CtoPstr(done_path); CtoPstr(binkp_bad_dir); } else { @@ -817,17 +834,13 @@ try_rename: cmpbr.ioVRefNum = 0; error = PBCatMove(&cmpbr, false); if (error == dupFNErr) { - if ((error = FSDelete(done_path, 0)) != 0) { - logger_printf("[binkp] Failed deleting %s: %d", + if ((error = FSDelete(done_path, 0)) != 0) + panic("[binkp] Failed deleting %s: %d", PtoCstr(done_path), error); - break; - } goto try_rename; } else if (error) { - logger_printf("[binkp] Failed moving %s to %s: %d", + panic("[binkp] Failed moving %s to %s: %d", PtoCstr(path), PtoCstr(done_path), error); - CtoPstr(done_path); - break; } } } @@ -921,7 +934,7 @@ next_message: xfree(&header); } -size_t +ssize_t binkp_buffer_file(Str255 path, char **data) { struct stat sb; @@ -929,8 +942,11 @@ binkp_buffer_file(Str255 path, char **data) short error, frefnum; if (FStat(path, &sb) != 0) - return 0; + return -1; + if (sb.st_size == 0) + return -1; + *data = xmalloc(sb.st_size); if (*data == NULL) return 0; @@ -938,7 +954,7 @@ binkp_buffer_file(Str255 path, char **data) error = FSOpen(path, 0, &frefnum); if (error) { xfree(data); - return 0; + return -1; } count = sb.st_size; @@ -946,7 +962,7 @@ binkp_buffer_file(Str255 path, char **data) FSClose(frefnum); if (error && error != eofErr) { xfree(data); - return 0; + return -1; } return count;