unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test/smtp-dummy: add --background option for backgrounding after listen(2)
@ 2011-12-12 14:57 Tomi Ollila
  2011-12-12 16:18 ` Austin Clements
  0 siblings, 1 reply; 7+ messages in thread
From: Tomi Ollila @ 2011-12-12 14:57 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-12-19 21:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12 14:57 [PATCH] test/smtp-dummy: add --background option for backgrounding after listen(2) Tomi Ollila
2011-12-12 16:18 ` Austin Clements
2011-12-12 22:29   ` [PATCH 1/2] test/smtp-dummy: add --background option for going background " Tomi Ollila
2011-12-12 22:29     ` [PATCH 2/2] test/test-lib.sh: launch smtp-dummy with --background and finally kill(1) it Tomi Ollila
2011-12-13  9:01   ` [PATCH 1/2] test/smtp-dummy: add --background option for going background after listen(2) Tomi Ollila
2011-12-13  9:01     ` [PATCH 2/2] test/test-lib.sh: launch smtp-dummy with --background and finally kill(1) it Tomi Ollila
2011-12-19 21:28     ` [PATCH 1/2] test/smtp-dummy: add --background option for going background after listen(2) Dmitry Kurochkin

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).