To avoid the possibility that smtp-dummy doesn't have chance to listen its bound socket until something tries to send message to it this option can be used for caller to wait until socket is already listening for a connection. --- When test_require_external_prereq() is changed to use associative array to check whether prereq is missing bash script is often so fast that it already waiting for smtp-dummy to exit until socket is listening. i.e sending QUIT to 127.0.0.1:25025 fails since there is no listener. (fork(2) & execve(2) count goes to zero in test_require_external_prereq (from 3 fork()s, 2 execve()s). test/smtp-dummy.c | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c index 3801a5e..40196dd 100644 --- a/test/smtp-dummy.c +++ b/test/smtp-dummy.c @@ -124,9 +124,21 @@ main (int argc, char *argv[]) struct hostent *hostinfo; socklen_t peer_addr_len; int reuse; + int bg; + + /* XXX quick implementation -- fix if more functionality is desired. */ + if (argc >= 2 && strcmp(argv[1], "--background") == 0) { + argc--; + argv[1] = argv[0]; + argv++; + bg = 1; + } + else + bg = 0; if (argc != 2) { - fprintf (stderr, "Usage: %s <output-file>\n", argv[0]); + fprintf (stderr, "Usage: %s [--background] <output-file>\n", + argv[0]); return 1; } @@ -179,6 +191,20 @@ main (int argc, char *argv[]) return 1; } + if (bg) { + switch (fork ()) { + case 0: + break; + case -1: + fprintf (stderr, "Error: fork() failed: %s\n", + strerror (errno)); + close (sock); + return 1; + default: + return 0; + } + } + peer_addr_len = sizeof (peer_addr); peer = accept (sock, (struct sockaddr *) &peer_addr, &peer_addr_len); if (peer == -1) { -- 1.7.7.3