From: Ján Kupec Date: Mon, 21 Sep 2009 08:38:04 +0000 (+0200) Subject: 'zypper ps' added X-Git-Tag: 1.2.6~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aab8cd481e978adf430ce138cfcc77b58812c79d;p=platform%2Fupstream%2Fzypper.git 'zypper ps' added --- diff --git a/doc/zypper.8 b/doc/zypper.8 index aec96f8..0bcee27 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -1,4 +1,4 @@ -.TH "zypper" "8" "1.2.4" "zypper" "System Tools" +.TH "zypper" "8" "1.2.5" "zypper" "System Tools" .SH "SYNTAX" .LP zypper [\fI\-\-global\-opts\fR] <\fBcommand\fR> [\fI\-\-command\-opts\fR] [\fBcommand-arguments\fR] @@ -1256,7 +1256,7 @@ of available package types. .TP .B removelock (rl) [options] ... -Remove specified package lock. Specify the lock to remove by its number obtained with 'zypper locks' +Remove specified package lock. Specify the lock to remove by its number obtained with \fBzypper locks\fR or by the package name. .TP @@ -1319,6 +1319,29 @@ of all licenses uses by the installed packages. This command can be useful for companies redistributiong a custom distribution (like appliances) to figure out what licenses they are bound by. +.TP +.B ps +After each upgrade or removal of packages, there may be running processes +on the system which then use files meanwhile deleted by the upgrade. +\fBzypper ps\fR lists these processes, together with the corresponding +deleted files, and a service name hint, in case it's a known service. +The list contains the following information: + +* PID\ \ \ \ \ \ ID of the process +.br +* PPID\ \ \ \ \ ID of the parent process +.br +* UID\ \ \ \ \ \ ID of the user running the process +.br +* Login\ \ \ \ login name of the user running the process +.br +* Command\ \ command used to execute the process +.br +* Service\ \ guessed name of the service. If an init script exists for this + \ \ \ \ \ \ \ \ \ \ service, you can do "rcservicename restart" to restart it. +.br +* Files\ \ \ \ the list of the deleted files + .SH "GLOBAL OPTIONS" @@ -1430,28 +1453,6 @@ This option serves mainly for testing purposes. It will cause zypper to act as if there were no packages installed in the system. Use with caution as you can damage your system using this option. -.SH "NOTES" -.TP -.B Notification About Running Processes Using Deleted Files -After each upgrade or removal of packages Zypper checks whether -there are any runing processes that may be using files recently -deleted by an upgrade or package removal. If such processes are -found, zypper will list them in a table having the following columns: - -* PID\ \ \ \ \ \ ID of the process -.br -* PPID\ \ \ \ \ ID of the parent process -.br -* UID\ \ \ \ \ \ ID of the user running the process -.br -* Login\ \ \ \ login name of the user running the process -.br -* Command\ \ command used to execute the process -.br -* Service\ \ guessed name of the service. If an init script exists for this - \ \ \ \ \ \ \ \ \ \ service, you can do "rcservicename restart" to restart it. -.br -* Files\ \ \ \ the list of the deleted files .SH "FILES" .TP diff --git a/src/Command.cc b/src/Command.cc index ea5c232..b91b9c0 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -67,6 +67,7 @@ const ZypperCommand ZypperCommand::CLEAN_LOCKS(ZypperCommand::CLEAN_LOCKS_e); const ZypperCommand ZypperCommand::TARGET_OS(ZypperCommand::TARGET_OS_e); const ZypperCommand ZypperCommand::VERSION_CMP(ZypperCommand::VERSION_CMP_e); const ZypperCommand ZypperCommand::LICENSES(ZypperCommand::LICENSES_e); +const ZypperCommand ZypperCommand::PS(ZypperCommand::PS_e); const ZypperCommand ZypperCommand::HELP(ZypperCommand::HELP_e); const ZypperCommand ZypperCommand::SHELL(ZypperCommand::SHELL_e); @@ -143,6 +144,7 @@ ZypperCommand::Command ZypperCommand::parse(const std::string & strval_r) _table["targetos"] = _table["tos"] = ZypperCommand::TARGET_OS_e; _table["versioncmp"] = _table["vcmp"] = ZypperCommand::VERSION_CMP_e; _table["licenses"] = ZypperCommand::LICENSES_e; + _table["ps"] = ZypperCommand::PS_e; _table["help"] = _table["?"] = ZypperCommand::HELP_e; _table["shell"] = _table["sh"] = ZypperCommand::SHELL_e; diff --git a/src/Command.h b/src/Command.h index 66241c2..8a04563 100644 --- a/src/Command.h +++ b/src/Command.h @@ -63,6 +63,7 @@ struct ZypperCommand static const ZypperCommand TARGET_OS; static const ZypperCommand VERSION_CMP; static const ZypperCommand LICENSES; + static const ZypperCommand PS; static const ZypperCommand HELP; static const ZypperCommand SHELL; @@ -136,6 +137,7 @@ struct ZypperCommand TARGET_OS_e = 80, VERSION_CMP_e = 81, LICENSES_e = 82, + PS_e = 83, HELP_e = 90, SHELL_e = 91, diff --git a/src/Zypper.cc b/src/Zypper.cc index a83b087..ebe8785 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -2151,6 +2151,26 @@ void Zypper::processCommandOptions() break; } + + case ZypperCommand::PS_e: + { + static struct option options[] = + { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + specific_options = options; + _command_help = _( + "ps\n" + "\n" + "List running processes which use files deleted by recent upgrades.\n" + "\n" + "This command has no additional options.\n" + ); + break; + } + + case ZypperCommand::SHELL_QUIT_e: { static struct option quit_options[] = { @@ -4068,6 +4088,24 @@ void Zypper::doCommand() break; } + + case ZypperCommand::PS_e: + { + if (runningHelp()) { out().info(_command_help, Out::QUIET); return; } + + if (!_arguments.empty()) + { + report_too_many_arguments(_command_help); + setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + return; + } + + list_processes_using_deleted_files(*this); + + break; + } + + // -----------------------------( shell )------------------------------------ case ZypperCommand::SHELL_QUIT_e: diff --git a/src/solve-commit.cc b/src/solve-commit.cc index 978fad2..0ca28e6 100755 --- a/src/solve-commit.cc +++ b/src/solve-commit.cc @@ -20,7 +20,6 @@ #include "utils/misc.h" #include "utils/prompt.h" // Continue? and solver problem prompt #include "utils/pager.h" // to view the summary -#include "Table.h" // for process list in suggest_restart_services #include "Summary.h" #include "solve-commit.h" @@ -373,11 +372,10 @@ ZYppCommitPolicy get_commit_policy(Zypper & zypper) } /** fate #300763 - * This is called after each commit to show running processes that use - * libraries or other files that have been removed since their execution. - * This is particularly useful after zypper remove or zypper update. + * This is called after each commit to notify user about running processes that + * use libraries or other files that have been removed since their execution. */ -static void suggest_restart_services(Zypper & zypper) +static void notify_processes_using_deleted_files(Zypper & zypper) { zypper.out().info( _("Checking for running processes using deleted libraries..."), Out::HIGH); @@ -392,55 +390,12 @@ static void suggest_restart_services(Zypper & zypper) zypper.out().error(e, _("Check failed:")); } - Table t; - t.allowAbbrev(6); - TableHeader th; - // process ID - th << _("PID"); - // parent process ID - th << _("PPID"); - // process user ID - th << _("UID"); - // process login name - th << _("Login"); - // process command name - th << _("Command"); - // "/etc/init.d/ script that might be used to restart the command (guessed) - th << _("Service"); - // "list of deleted files or libraries accessed" - th << _("Files"); - t << th; - - for_( it, checker.begin(), checker.end() ) + if (checker.begin() != checker.end()) { - TableRow tr; - vector::const_iterator fit = it->files.begin(); - tr << it->pid << it->ppid << it->puid << it->login << it->command - << it->service() << (fit != it->files.end() ? *fit : ""); - t << tr; - for (; fit != it->files.end(); ++fit) - { - TableRow tr1; - tr1 << "" << "" << "" << "" << "" << "" << *fit; - t << tr1; - } - } - - if (t.empty()) - { - zypper.out().info(_("No such processes found."), Out::HIGH); - } - else - { - cout << endl; - zypper.out().info(_("The following running processes use deleted files:")); - cout << endl; - cout << t << endl; - zypper.out().info(_("You may wish to restart these processes.")); zypper.out().info(str::form( - _("See '%s' for information about the meaning of values" - " in the above table."), - "man zypper")); + _("There are some running programs that use files deleted by recent upgrade." + " You may wish to restart some of them. Run '%s' to list these programs."), + "zypper ps")); } } @@ -802,7 +757,7 @@ void solve_and_commit (Zypper & zypper) if (summary.packagesToRemove() || summary.packagesToUpgrade() || summary.packagesToDowngrade()) - suggest_restart_services(zypper); + notify_processes_using_deleted_files(zypper); } } // noting to do diff --git a/src/utils/misc.cc b/src/utils/misc.cc index 6fe4ce9..32c881b 100644 --- a/src/utils/misc.cc +++ b/src/utils/misc.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include "zypp/base/String.h" #include "zypp/media/MediaManager.h" #include "zypp/parser/xml/XmlEscape.h" +#include "zypp/misc/CheckAccessDeleted.h" #include "zypp/PoolItem.h" #include "zypp/Product.h" @@ -22,6 +24,7 @@ #include "main.h" #include "Zypper.h" +#include "Table.h" // for process list in suggest_restart_services #include "utils/misc.h" @@ -409,3 +412,69 @@ string asXML(const Pattern & p, bool is_installed) } // ---------------------------------------------------------------------------- + +void list_processes_using_deleted_files(Zypper & zypper) +{ + zypper.out().info( + _("Checking for running processes using deleted libraries..."), Out::HIGH); + zypp::CheckAccessDeleted checker(false); // wait for explicit call to check() + try + { + checker.check(); + } + catch(const zypp::Exception & e) + { + if (zypper.out().verbosity() > Out::NORMAL) + zypper.out().error(e, _("Check failed:")); + } + + Table t; + t.allowAbbrev(6); + TableHeader th; + // process ID + th << _("PID"); + // parent process ID + th << _("PPID"); + // process user ID + th << _("UID"); + // process login name + th << _("Login"); + // process command name + th << _("Command"); + // "/etc/init.d/ script that might be used to restart the command (guessed) + th << _("Service"); + // "list of deleted files or libraries accessed" + th << _("Files"); + t << th; + + for_( it, checker.begin(), checker.end() ) + { + TableRow tr; + vector::const_iterator fit = it->files.begin(); + tr << it->pid << it->ppid << it->puid << it->login << it->command + << it->service() << (fit != it->files.end() ? *fit : ""); + t << tr; + for (; fit != it->files.end(); ++fit) + { + TableRow tr1; + tr1 << "" << "" << "" << "" << "" << "" << *fit; + t << tr1; + } + } + + if (t.empty()) + { + zypper.out().info(_("No processes using deleted files found.")); + } + else + { + zypper.out().info(_("The following running processes use deleted files:")); + cout << endl; + cout << t << endl; + zypper.out().info(_("You may wish to restart these processes.")); + zypper.out().info(str::form( + _("See '%s' for information about the meaning of values" + " in the above table."), + "man zypper")); + } +} diff --git a/src/utils/misc.h b/src/utils/misc.h index f8888c2..a94c4c4 100644 --- a/src/utils/misc.h +++ b/src/utils/misc.h @@ -119,4 +119,12 @@ std::string asXML(const zypp::Product & p, bool is_installed); std::string asXML(const zypp::Pattern & p, bool is_installed); +/** + * fate #300763 + * Used by 'zypper ps' to show running processes that use + * libraries or other files that have been removed since their execution. + * This is particularly useful after 'zypper remove' or 'zypper update'. + */ +void list_processes_using_deleted_files(Zypper & zypper); + #endif /*ZYPPER_UTILS_H*/