summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Martínez Moreno <ender@fb.com>2015-03-22 23:38:53 -0700
committerDavid Martínez Moreno <ender@fb.com>2015-03-31 11:43:02 -0700
commit6ca6747b0694895bf1e8840223e6077f9376984e (patch)
treec5cdb7f5b8bb0ef6282ba1c93d2abc65d3ec928d /lib
parentee72c41d8b9994e4b1086c116927e8541a6ba592 (diff)
downloadrpm-6ca6747b0694895bf1e8840223e6077f9376984e.tar.gz
Reset nice and ionice priorities when executing scripts.
Sometimes you may consider running an entire yum upgrade wrapped on nice and ionice to soften the effect of the upcoming I/O and CPU storm on the system. The side effect of that is that restarted services and anything else executed from the pre- and post- rm and installation scripts will be niced and ioniced as well, defeating the whole idea. With this, you are safe to run it, because we will reset nice and ionice values right after fork() to the defaults.
Diffstat (limited to 'lib')
-rw-r--r--lib/rpmscript.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/rpmscript.c b/lib/rpmscript.c
index d8297b929..493f4f26a 100644
--- a/lib/rpmscript.c
+++ b/lib/rpmscript.c
@@ -4,6 +4,10 @@
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
+#include <sys/resource.h>
+#if defined(__linux__)
+#include <sys/syscall.h> /* For ionice */
+#endif
#include <rpm/rpmfileutil.h>
#include <rpm/rpmmacro.h>
@@ -326,6 +330,32 @@ static rpmRC runExtScript(rpmPlugins plugins, ARGV_const_t prefixes,
fclose(in);
dup2(inpipe[0], STDIN_FILENO);
+ /* If RPM was invoked with nice and/or ionice, the scripts that we run
+ * will be also nice'd/ionice'd. This is terrible if you restart any
+ * daemon (e.g. mysqld), so let's reset this to default values before
+ * taking any actions.
+ */
+
+ /* Call for resetting nice priority. */
+ int ret;
+ ret = setpriority(PRIO_PROCESS, 0, 0);
+ if (ret == -1) {
+ rpmlog(RPMLOG_WARNING, _("Unable to reset nice value: %s"),
+ strerror(errno));
+ }
+
+ /* Call for resetting IO priority. */
+ #if defined(__linux__)
+ /* Defined at include/linux/ioprio.h */
+ const int _IOPRIO_WHO_PROCESS = 1;
+ const int _IOPRIO_CLASS_NONE = 0;
+ ret = syscall(SYS_ioprio_set, _IOPRIO_WHO_PROCESS, 0, _IOPRIO_CLASS_NONE);
+ if (ret == -1) {
+ rpmlog(RPMLOG_WARNING, _("Unable to reset I/O priority: %s"),
+ strerror(errno));
+ }
+ #endif
+
/* Run scriptlet post fork hook for all plugins */
if (rpmpluginsCallScriptletForkPost(plugins, *argvp[0], RPMSCRIPTLET_FORK | RPMSCRIPTLET_EXEC) != RPMRC_FAIL) {
doScriptExec(*argvp, prefixes, scriptFd, out);