From: Ian Campbell Subject: Re: [PATCH OSSTEST] PDU/xenuse: Support xenuse on machine not locked by current user Date: Thu, 17 Oct 2013 11:33:28 +0100 Message-ID: <1382006008.18128.38.camel@kazak.uk.xensource.com> References: <1381939110-30213-1-git-send-email-ian.campbell@citrix.com> <21087.47915.599553.193298@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21087.47915.599553.193298@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Thu, 2013-10-17 at 11:25 +0100, Ian Jackson wrote: > Ian Campbell writes ("[PATCH OSSTEST] PDU/xenuse: Support xenuse on machine not locked by current user"): > > xenuse checks that whoever is trying to reboot a machine "owns" that machine > > via a locking mechanism. This is usually fine doesn't work well when one want... > > I used eval + save/restore the original user so as not to pollute the whole > > process, it might have been better to actually fork? > > Well, I can think of two better ways: > > 1. Perl dynamic scoping ("local"): > > { > local $ENV{USER} = $user; > system_checked($xenuse, "--$onoff", "$mo->{Host}{Name}"); > } > > IMO this is idiomatic Perl. I tried this and it didn't work. I think local causes $ENV to loose its magic properties. That kind of makes sense I think since you can't actually create a local copy of your actual environment so it would have to jump through what I imagine would be some clever hoops to unwind when the local $ENV went out of scope, I've no idea if that's even possible in Perl. > 2. env(1) from coreutils: > > my @cmd = ($xenuse, "--$onoff", "$mo->{Host}{Name}"); > if ($user) { > unshift @cmd, 'env', "'USER=$user"; > } > system_checked(@cmd); I can do this one assuming I'm right about method #1. > > Ian.