summaryrefslogtreecommitdiffstats
path: root/urpmi.recover
Commit message (Collapse)AuthorAgeFilesLines
* - all tools:Pascal Rigaux2007-11-221-1/+1
| | | | | | | o exit with code 1 after displaying usage (instead of exit code 0) (urpmi exit code "1" is correctly documented in urpmi's manpage)
* more ngettextPablo Saratxaga2007-02-231-1/+2
|
* perl_checker compliancePascal Rigaux2006-11-091-5/+5
|
* Check if we can open the rpmdb in urpmi.recoverRafael Garcia-Suarez2006-06-141-2/+2
|
* New urpmi.recover option: --list-safeRafael Garcia-Suarez2006-03-231-1/+5
|
* use urpm so we know which version we're usingRafael Garcia-Suarez2006-03-021-0/+1
|
* Add a --disable option to urpmi.recoverRafael Garcia-Suarez2006-02-161-11/+47
|
* Fix description of --list optionRafael Garcia-Suarez2006-02-131-2/+1
|
* No need to open the rpmdb to load macrosRafael Garcia-Suarez2006-02-131-1/+1
|
* If called without arguments, make urpmi.recover print usageRafael Garcia-Suarez2006-02-131-0/+1
|
* Add the _rollback_transaction_on_failure macro (with the default value,Rafael Garcia-Suarez2006-02-131-0/+3
| | | | | disabled) to the urpmi.recover.macros file
* New tool, urpmi.recoverRafael Garcia-Suarez2006-02-101-0/+172
>) = @_; run($name, @args) or die "$name failed\n"; } sub rooted_or_die { my ($root, $name, @args) = @_; rooted($root, $name, @args) or die "$name failed\n"; } sub get_stdout { my ($name, @args) = @_; my @r; run($name, '>', \@r, @args) or return; wantarray() ? @r : join('', @r); } sub rooted_get_stdout { my ($root, $name, @args) = @_; my @r; rooted($root, $name, '>', \@r, @args) or return; wantarray() ? @r : join('', @r); } sub run { raw({}, @_) } sub rooted { my ($root, $name, @args) = @_; raw({ root => $root }, $name, @args); } sub raw { my ($options, $name, @args) = @_; my $root = $options->{root} || ''; my $str = ref($name) ? $name->[0] : $name; my ($stdout_raw, $stdout_mode, $stderr_raw, $stderr_mode); ($stdout_mode, $stdout_raw, @args) = @args if $args[0] =~ /^>>?$/; ($stderr_mode, $stderr_raw, @args) = @args if $args[0] =~ /^2>>?$/; log::l("running: $str @args" . ($root ? " with root $root" : "")); return 1 if $root && $<; $root ? ($root .= '/') : ($root = ''); if (!$root && !$::isStandalone) { require install_any; install_any::check_prog(ref($name) ? $name->[0] : $name); } $ENV{HOME} || $::isInstall or $ENV{HOME} = '/root'; my $tmpdir = sub { my $dir = "$ENV{HOME}/tmp"; -d $dir or mkdir($dir, 0700); $dir; }; my $stdout = $stdout_raw && (ref($stdout_raw) ? $tmpdir->() . "/.drakx-stdout.$$" : "$root$stdout_raw"); my $stderr = $stderr_raw && (ref($stderr_raw) ? $tmpdir->() . "/.drakx-stderr.$$" : "$root$stderr_raw"); if (my $pid = fork()) { if ($options->{detach}) { $pid; } else { my $ok; eval { local $SIG{ALRM} = sub { die "ALARM" }; alarm($options->{timeout} || 10 * 60); waitpid $pid, 0; $ok = $? == 0; alarm 0; }; if ($@) { log::l("ERROR: killing runaway process (process=$str, pid=$pid, args=@args, error=$@)"); kill 9, $pid; return; } if ($stdout_raw && ref($stdout_raw)) { if (ref($stdout_raw) eq 'ARRAY') { @$stdout_raw = cat_($stdout); } else { $$stdout_raw = cat_($stdout); } unlink $stdout; } if ($stderr_raw && ref($stderr_raw)) { if (ref($stderr_raw) eq 'ARRAY') { @$stderr_raw = cat_($stderr); } else { $$stderr_raw = cat_($stderr); } unlink $stderr; } $ok; } } else { if ($stderr && $stderr eq 'STDERR') { } elsif ($stderr) { $stderr_mode =~ s/2//; open STDERR, "$stderr_mode $stderr" or die "run_program can't output in $stderr (mode `$stderr_mode')"; } elsif ($::isInstall) { open STDERR, ">> /tmp/ddebug.log" or open STDOUT, ">> /dev/tty7" or die "run_program can't log, give me access to /tmp/ddebug.log"; } if ($stdout && $stdout eq 'STDOUT') { } elsif ($stdout) { open STDOUT, "$stdout_mode $stdout" or die "run_program can't output in $stdout (mode `$stdout_mode')"; } elsif ($::isInstall) { open STDOUT, ">> /tmp/ddebug.log" or open STDOUT, ">> /dev/tty7" or die "run_program can't log, give me access to /tmp/ddebug.log"; } $root and chroot $root; chdir "/"; if (ref $name) { unless (exec { $name->[0] } $name->[1], @args) { log::l("exec of $name->[0] failed: $!"); c::_exit(128); } } else { unless (exec $name, @args) { log::l("exec of $name failed: $!"); c::_exit(128); } } } } # run in background a sub that give back data through STDOUT a la run_program::get_stdout but w/ arbitrary perl code instead of external program package bg_command; sub new { my ($class, $sub) = @_; my $o = bless {}, $class; if ($o->{pid} = open(my $fd, "-|")) { $o->{fd} = $fd; $o; } else { $sub->(); c::_exit(0); } } sub DESTROY { my ($o) = @_; close $o->{fd} or warn "kid exited $?"; waitpid $o->{pid}, 0; } 1;