1 /*	$NetBSD: cleanup_final.c,v 1.1.1.1 2009/06/23 10:08:43 tron Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	cleanup_final 3
6 /* SUMMARY
7 /*	finalize queue file
8 /* SYNOPSIS
9 /*	#include "cleanup.h"
10 /*
11 /*	void	cleanup_final(state)
12 /*	CLEANUP_STATE *state;
13 /* DESCRIPTION
14 /*	cleanup_final() performs final queue file content (not
15 /*	attribute) updates so that the file is ready to be closed.
16 /* LICENSE
17 /* .ad
18 /* .fi
19 /*	The Secure Mailer license must be distributed with this software.
20 /* AUTHOR(S)
21 /*	Wietse Venema
22 /*	IBM T.J. Watson Research
23 /*	P.O. Box 704
24 /*	Yorktown Heights, NY 10598, USA
25 /*--*/
26 
27 /* System library. */
28 
29 #include <sys_defs.h>
30 #include <errno.h>
31 
32 /* Utility library. */
33 
34 #include <msg.h>
35 
36 /* Global library. */
37 
38 #include <cleanup_user.h>
39 #include <rec_type.h>
40 
41 /* Application-specific. */
42 
43 #include "cleanup.h"
44 
45 /* cleanup_final - final queue file content updates */
46 
47 void    cleanup_final(CLEANUP_STATE *state)
48 {
49     const char *myname = "cleanup_final";
50 
51     /*
52      * vstream_fseek() would flush the buffer anyway, but the code just reads
53      * better if we flush first, because it makes seek error handling more
54      * straightforward.
55      */
56     if (vstream_fflush(state->dst)) {
57 	if (errno == EFBIG) {
58 	    msg_warn("%s: queue file size limit exceeded", state->queue_id);
59 	    state->errs |= CLEANUP_STAT_SIZE;
60 	} else {
61 	    msg_warn("%s: write queue file: %m", state->queue_id);
62 	    state->errs |= CLEANUP_STAT_WRITE;
63 	}
64 	return;
65     }
66 
67     /*
68      * Update the preliminary message size and count fields with the actual
69      * values.
70      */
71     if (vstream_fseek(state->dst, 0L, SEEK_SET) < 0)
72 	msg_fatal("%s: vstream_fseek %s: %m", myname, cleanup_path);
73     cleanup_out_format(state, REC_TYPE_SIZE, REC_TYPE_SIZE_FORMAT,
74 	    (REC_TYPE_SIZE_CAST1) (state->xtra_offset - state->data_offset),
75 		       (REC_TYPE_SIZE_CAST2) state->data_offset,
76 		       (REC_TYPE_SIZE_CAST3) state->rcpt_count,
77 		       (REC_TYPE_SIZE_CAST4) state->qmgr_opts,
78 		       (REC_TYPE_SIZE_CAST5) state->cont_length);
79 }
80