From: Zhang Qiang Date: Mon, 16 Dec 2013 08:03:46 +0000 (+0800) Subject: only create pipe if command output needed X-Git-Tag: 0.11^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7417082248a6d9071032e9ad78414ad2fe811170;p=tools%2Fdepanneur.git only create pipe if command output needed This will make my_system more safe via avoid using pipe. Change-Id: I386913ad4ee6be908004351628a47b370e96eae4 --- diff --git a/depanneur b/depanneur index c4a3f6a..7f25f32 100755 --- a/depanneur +++ b/depanneur @@ -274,21 +274,28 @@ sub my_system { my $cmd = shift; debug("my_system: $cmd"); my $ret; + my $pid; my @out = (); + if (wantarray) { + defined($pid=open(PIPE, "-|")) or die "Can not fork: $!\n"; + } else { + defined($pid=fork) or die "Can not fork: $!\n"; + } - defined(my $pid=open(PIPE, "-|")) or die "Can not fork: $!\n"; unless ($pid) { # Child open(STDERR, ">&STDOUT"); exec ($cmd); exit -1; } else { # Parent - while (my $line = ) { - print $line; - push @out, $line if wantarray; + if (wantarray) { + while (my $line = ) { + print $line; + push @out, $line; + } } waitpid ($pid,0); $ret = $?; - close(PIPE); + close(PIPE) if wantarray; return wantarray ? ($ret, @out): $ret; }