From owner-freebsd-stable@FreeBSD.ORG Fri Jun 20 19:23:57 2014 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AD8B7247 for ; Fri, 20 Jun 2014 19:23:57 +0000 (UTC) Received: from isis.morrow.me.uk (isis.morrow.me.uk [204.109.63.142]) by mx1.freebsd.org (Postfix) with ESMTP id 89728221D for ; Fri, 20 Jun 2014 19:23:57 +0000 (UTC) Received: from anubis.morrow.me.uk (host86-182-12-173.range86-182.btcentralplus.com [86.182.12.173]) (Authenticated sender: mauzo) by isis.morrow.me.uk (Postfix) with ESMTPSA id B602F45031; Fri, 20 Jun 2014 19:16:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.8.3 isis.morrow.me.uk B602F45031 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=morrow.me.uk; s=dkim201101; t=1403291818; bh=Zcdu7rxrjPDbeFAjPwbVeE769toOm01jaZrdtc/RaVM=; h=Date:From:To:Subject:In-Reply-To; b=11j3/lLF3Qv0FxQmvXtQeWyShFuQzcyO3pdhdb5avgCtusCYH1EZUrxciHXwzRFTQ XznbP1DKI9EIBZ7kx4yahsdVGTgLHXenkDPrISHA4m98K/vHONxUpu2jEB3BLV+1vV tEdm2S/Yhoxf6H07v5H2SmzX0A3NWhN9/YREh65Q= X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.98.1 at isis.morrow.me.uk Received: by anubis.morrow.me.uk (Postfix, from userid 5001) id D7EAF14270; Fri, 20 Jun 2014 20:16:50 +0100 (BST) Date: Fri, 20 Jun 2014 20:16:50 +0100 From: Ben Morrow To: lists@jnielsen.net, freebsd-stable@freebsd.org Subject: Re: freebsd-update from script without tty Message-ID: <20140620191647.GA22531@anubis.morrow.me.uk> Mail-Followup-To: lists@jnielsen.net, freebsd-stable@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <295AB5F0-1601-4AF6-BCE1-FD592DE26FB1@jnielsen.net> X-Newsgroups: gmane.os.freebsd.stable User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jun 2014 19:23:57 -0000 Quoth John Nielsen : > > I have a script that builds virtual FreeBSD disk images. After it > populates the base system it runs "freebsd-update -b ${MOUNTPOINT} ..." > to update the image with the latest security patch release. > > If I run the script from a terminal it works fine. However if I try to > run it from our user-friendly web interface (which spawns the script in > the background with no tty) the freebsd-update step fails: > > # UNAME_r=10.0-RELEASE freebsd-update -b /mnt/chroot fetch > freebsd-update fetch should not be run non-interactively. > Run freebsd-update cron instead. > > I understand and appreciate the use case for 'freebsd-update cron' but > in this case my script is running because a user requested and is > waiting for it, and a delay of up to an hour won't really fly. > > Can anyone suggest a workaround? The obvious answer would be to run it on a pty. If you can't easily do this from your script directly, something like this might do: #!/usr/bin/perl use IO::Pty; use IO::Select; my $pt = IO::Pty->new; my $sl = $pt->slave; unless (my $kid = fork) { close $pt; open STDIN, "<&", $sl; open STDOUT, ">&", $sl; open STDERR, ">&", $sl; close $sl; exec @ARGV; } close $sl; my $sel = IO::Select->new($pt); $pt->blocking(0); $/ = \4096; $| = 1; while (1) { $sel->can_read; $_ = <$pt>; defined or last; print; } waitpid $kid, 0; exit $?>>8 ? $?>>8 : $? ? 1 : 0; Add proper error checking / signal handling / etc. to taste. Ben