Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 62CA4429E25 for ; Tue, 13 Dec 2011 01:02:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PnJ1Cjn91Gd1 for ; Tue, 13 Dec 2011 01:01:59 -0800 (PST) Received: from mail-gw3.nixu.fi (mail-gw3.nixu.fi [193.209.237.7]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 0AED4429E26 for ; Tue, 13 Dec 2011 01:01:58 -0800 (PST) Received: from pps.filterd (mail-gw3 [127.0.0.1]) by mail-gw3.nixu.fi (8.14.4/8.14.4) with SMTP id pBD90UGW025406; Tue, 13 Dec 2011 11:01:47 +0200 Received: from taco2.nixu.fi (taco2.nixu.fi [194.197.118.31]) by mail-gw3.nixu.fi with ESMTP id 114cs0t045-1 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Tue, 13 Dec 2011 11:01:47 +0200 Received: from taco2.nixu.fi (localhost [127.0.0.1]) by taco2.nixu.fi (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id pBD91kb8022818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 13 Dec 2011 11:01:46 +0200 Received: (from too@localhost) by taco2.nixu.fi (8.14.3/8.14.3/Submit) id pBD91jnC022817; Tue, 13 Dec 2011 11:01:45 +0200 From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH 1/2] test/smtp-dummy: add --background option for going background after listen(2) Date: Tue, 13 Dec 2011 11:01:22 +0200 Message-Id: <1323766883-17607-1-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <20111212161800.GO2760@mit.edu> References: <20111212161800.GO2760@mit.edu> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.5.7110, 1.0.211, 0.0.0000 definitions=2011-12-13_03:2011-12-13, 2011-12-12, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1012030000 definitions=main-1112130013 Cc: Tomi Ollila X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Dec 2011 09:02:00 -0000 To avoid the possibility that smtp-dummy doesn't have chance to bind its listening socket until something tries to send message to it this option makes caller wait until socket is already listening for connections. In case this --background option is used, the pid of running smtp-dummy is printed on stdout. --- Resent after whitespace-cleanup in patch 1/2 (this patch). test/smtp-dummy.c | 35 ++++++++++++++++++++++++++++++++++- 1 files changed, 34 insertions(+), 1 deletions(-) diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c index 3801a5e..9126c00 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 \n", argv[0]); + fprintf (stderr, "Usage: %s [--background] \n", + argv[0]); return 1; } @@ -179,7 +191,27 @@ main (int argc, char *argv[]) return 1; } + if (bg) { + int pid = fork (); + if (pid > 0) { + printf ("%d\n", pid); + return 0; + } + if (pid < 0) { + fprintf (stderr, "Error: fork() failed: %s\n", + strerror (errno)); + close (sock); + return 1; + } + /* Reached if pid == 0. */ + /* Close stdout so that the one interested in pid value will + also get EOF. */ + close (1); + /* dup2() will re-reserve fd 1 (opportunistically, in case fd 2 + is open. If that was not open we don't care fd 1 either.) */ + dup2 (2, 1); + } + peer_addr_len = sizeof (peer_addr); peer = accept (sock, (struct sockaddr *) &peer_addr, &peer_addr_len); if (peer == -1) { -- 1.7.7.3