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