summaryrefslogtreecommitdiff
path: root/src/qmail-tcpok.c
blob: 0e795910e19ea93a1d1875f4046318888ed42e21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <unistd.h>
#include "logmsg.h"
#include "buffer.h"
#include "lock.h"
#include "open.h"
#include "auto_queue.h"
#include "exit.h"
#include "qmail.h"

#define WHO "qmail-tcpok"

char buf[BUFSIZE_LINE]; /* XXX: must match size in tcpto_clean.c, tcpto.c */
buffer bo;

int main()
{
  int fd;
  int i;

  if (chdir(auto_queue) == -1)
    logmsg(WHO,111,FATAL,B("unable to chdir to: ",auto_queue));
  if (chdir("queue") == -1)
    logmsg(WHO,111,FATAL,B("unable to chdir to: ",auto_queue,"/queue"));
  if (chdir("lock") == -1)
    logmsg(WHO,111,FATAL,B("unable to chdir to ",auto_queue,"/queue/lock"));

  fd = open_write("tcpto");
  if (fd == -1)
    logmsg(WHO,111,FATAL,B("unable to write ",auto_queue,"/queue/lock/tcpto"));
  if (lock_ex(fd) == -1)
    logmsg(WHO,111,FATAL,B("unable to lock ",auto_queue,"/queue/lock/tcpto"));

  buffer_init(&bo,write,fd,buf,sizeof(buf));
  for (i = 0; i < sizeof(buf); ++i) 
   buffer_put(&bo,"",1);
  if (buffer_flush(&bo) == -1)
    logmsg(WHO,111,FATAL,B("unable to clear ",auto_queue,"/queue/lock/tcpto"));
  _exit(0);
}