From patchwork Fri Jan 16 03:15:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Owen Kirby X-Patchwork-Id: 429678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E0D2B14017F for ; Fri, 16 Jan 2015 14:16:01 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id DD341289C4B; Fri, 16 Jan 2015 04:13:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00 autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 66326281451 for ; Fri, 16 Jan 2015 04:13:32 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .exegin. - helo: .mail-pd0-f170.google. - helo-domain: .google.) FROM/MX_MATCHES_NOT_HELO(DOMAIN)=1; rate: -5.5 Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Fri, 16 Jan 2015 04:13:30 +0100 (CET) Received: by mail-pd0-f170.google.com with SMTP id p10so8578524pdj.1 for ; Thu, 15 Jan 2015 19:15:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding; bh=c5Uh0TnBPyYgV8ED5an+hy9mTCzgpiI0Ccbp8cy1u9w=; b=kIv7+2XIn9Q4oBC81pXlpiU60oFQRRwIEDZMckZNiEIEtICDtPBKJrQ7F+CxwBo/lC 02/o8N+P1QIfe5QOntReJHmS9A9/oxPcE+9GYv34QyeTrAVqjx6+XVGPNp3J1VQ+V9jT XIIMX15+QZ57b0ZsYPIhQWLIQuoJnLlnLjoPJzl6RTnZk0zYC6jYx8MBlmcRRMt5dH9e 1rF97MyZGFdxQbYa0xero8SFqjU+0guh5V1ZnHKWDTpMgzkhjpB9I9y8vZckRlDZpM+e pe9OlNFNzFTHZJLdAgq8us/fO7rg11cp+FXwjy/mS+EUD/LUqiWfkrOdgEafYqfcvOty u3pA== X-Gm-Message-State: ALoCoQkHg7SqCLnmxWtp2TyaRzLsgWj9o4qYIe89YsUlIXEYCzT+NU/jESPLLKYBbHlVzp8GBbeD X-Received: by 10.70.127.173 with SMTP id nh13mr19444721pdb.92.1421378143033; Thu, 15 Jan 2015 19:15:43 -0800 (PST) Received: from [172.16.16.147] ([184.71.143.130]) by mx.google.com with ESMTPSA id qq6sm2654497pbb.20.2015.01.15.19.15.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jan 2015 19:15:42 -0800 (PST) Message-ID: <54B8825C.4030300@exegin.com> Date: Thu, 15 Jan 2015 19:15:40 -0800 From: Owen Kirby User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: "openwrt-devel@lists.openwrt.org" , John Crispin Subject: [OpenWrt-Devel] [PATCH] procd: delay inittab workers until the tty exists. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" If a process with a tty is specified in inittab, delay the worker process until the tty exists. This allows starting consoles with terminals that get delayed until after procd is reads inittab, and it also allows hotplugging USB-to-serial adapters attached long after booting. Signed-off-by: Owen Kirby --- inittab.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/inittab.c b/inittab.c index 623103d..73c113f 100644 --- a/inittab.c +++ b/inittab.c @@ -99,9 +99,15 @@ static void fork_worker(struct init_action *a) if (!a->proc.pid) { p = setsid(); - fd = dev_open(a->id); - if (fd != -1) - { + if (a->id) { + struct timespec tm; + tm.tv_sec = a->respawn / 1000; + tm.tv_nsec = (a->respawn % 1000) * 1000000; + + while ((fd = dev_open(a->id)) == -1) + if (nanosleep(&tm, NULL) == -1) + exit(-1); + dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); @@ -157,7 +163,7 @@ static void askfirst(struct init_action *a) { int i; - if (!dev_exist(a->id) || (console && !strcmp(console, a->id))) { + if (console && !strcmp(console, a->id)) { DEBUG(4, "Skipping %s\n", a->id); return; }