From 8ddc280393f942c8d684c78ec2b34ee13c284e80 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Sun, 8 Apr 2012 22:25:26 -0500 Subject: Clean up exit/die/return mess for exe*() The exe*() functions were inconsistent of where they exited. So, make sure that all exe*() confesses upon errors, and let the calling functions use eval{} to avoid the exception when needed. Change-Id: Ia6e4edb22a83ac32d924b792e8a2eea657a6a149 Reviewed-by: Rohan McGovern --- build | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/build b/build index a4fd74fd..2649c9c1 100755 --- a/build +++ b/build @@ -155,11 +155,10 @@ sub exe print "+ @cmd\n" unless ($self->{quiet}); + # dry-run > 1 means run sub-processes with dry-run too if ($self->{'dry-run'} != 1) { confess "@cmd exited with status $CHILD_ERROR" if (system(@cmd) != 0); } - - return 0; } sub dropPrivileges() @@ -189,29 +188,33 @@ sub dropPrivileges() sub exeHighPriv() { my ($self, @cmd) = @_; - return $self->exe(@cmd); + # confesses upon system() failure + $self->exe(@cmd); } sub exeLowPriv() { my ($self, @cmd) = @_; - if ("$Config{osname}" =~ /mswin/i) { - # Just like exeHighPriv for now - return $self->exe(@cmd); - } else { + if ("$Config{osname}" !~ /mswin/i) { my $ret; my $pid = fork(); die "Couldn't fork" unless defined $pid; if ($pid == 0) { $self->dropPrivileges; - $self->exe(@cmd); - exit 0; + # just exit on error, exception propagated below + eval { $self->exe(@cmd); }; + exit $?; } else { waitpid($pid, 0); - return $?; + # propagate exception upon system() failure in fork + die if ($? != 0); + return; } } + + # Just like exeHighPriv for now, and confesses upon failure + $self->exe(@cmd); } sub which { @@ -422,15 +425,15 @@ sub build_project my $install_command = $self->{'instcmds'}->{$module}; if (!defined $build_command) { if (!-e "$module/Makefile") { - $self->exeLowPriv("cd $module && qmake -r") && die "'cd $module && qmake -r' failed: $?"; + $self->exeLowPriv("cd $module && qmake -r"); } $build_command = "$self->{MAKE} $self->{MAKEOPTS}"; } - $self->exeLowPriv("cd $module && $build_command") && die "'cd $module && $build_command' failed: $?"; + $self->exeLowPriv("cd $module && $build_command"); $install_command = "$self->{MAKE} install" if (!defined $install_command); ### TODO: Should be fixed after the alpha unless ("$Config{osname}" =~ /(dar|ms)win/i) { - $self->exeHighPriv("cd $module && $install_command") && die "'cd $module && $install_command failed: $?"; + $self->exeHighPriv("cd $module && $install_command"); } $self->mark_as_finished($module); return 0; -- cgit v1.2.3