1 /* $Cambridge: exim/src/src/enq.c,v 1.2 2005/01/04 10:00:42 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2005 */
8 /* See the file NOTICE for conditions of use and distribution. */
10 /* Functions concerned with serialization. */
18 /*************************************************
19 * Test for host or ETRN serialization *
20 *************************************************/
22 /* This function is called when a host is listed for serialization of
23 connections. It is also called when ETRN is listed for serialization. We open
24 the misc database and look for a record, which implies an existing connection
25 or ETRN run. If not found, create one and return TRUE.
28 key string on which to serialize
30 Returns: TRUE if OK to proceed; FALSE otherwise
35 enq_start(uschar *key)
37 dbdata_serialize *serial_record;
38 dbdata_serialize new_record;
42 DEBUG(D_transport) debug_printf("check serialized: %s\n", key);
44 /* Open and lock the waiting information database. The absence of O_CREAT is
45 deliberate; the dbfn_open() function - which is an Exim function - always tries
46 to create if it can't open a read/write file. It expects only O_RDWR or
47 O_RDONLY as its argument. */
49 dbm_file = dbfn_open(US"misc", O_RDWR, &dbblock, TRUE);
50 if (dbm_file == NULL) return FALSE;
52 /* See if there is a record for this host or queue run; if there is, we cannot
53 proceed with the connection unless the record is very old. */
55 serial_record = dbfn_read(dbm_file, key);
56 if (serial_record != NULL && time(NULL) - serial_record->time_stamp < 6*60*60)
59 DEBUG(D_transport) debug_printf("outstanding serialization record for %s\n",
64 /* We can proceed - insert a new record or update the old one. At present
65 the count field is not used; just set it to 1. */
68 dbfn_write(dbm_file, key, &new_record, (int)sizeof(dbdata_serialize));
75 /*************************************************
76 * Release serialization *
77 *************************************************/
79 /* This function is called when a serialized host's connection or serialized
80 ETRN queue run ends. We open the relevant database and delete its record.
83 key the serialization key
94 DEBUG(D_transport) debug_printf("end serialized: %s\n", key);
96 dbm_file = dbfn_open(US"misc", O_RDWR, &dbblock, TRUE);
97 if (dbm_file == NULL) return;
98 dbfn_delete(dbm_file, key);