|
|
2ff057 |
#include "system.h"
|
|
|
2ff057 |
|
|
|
2ff057 |
#include <errno.h>
|
|
|
2ff057 |
#include <sys/resource.h>
|
|
|
2ff057 |
#if defined(__linux__)
|
|
|
2ff057 |
#include <sys/syscall.h> /* For ionice */
|
|
|
2ff057 |
#endif
|
|
|
2ff057 |
|
|
|
2ff057 |
#include <rpm/rpmlog.h>
|
|
|
2ff057 |
#include "lib/rpmplugin.h"
|
|
|
2ff057 |
|
|
|
2ff057 |
#include "debug.h"
|
|
|
2ff057 |
|
|
|
2ff057 |
/*
|
|
|
2ff057 |
* In general we want scriptlets to run with the same priority as rpm
|
|
|
2ff057 |
* itself. However on legacy SysV init systems, properties of the
|
|
|
2ff057 |
* parent process can be inherited by the actual daemons on restart,
|
|
|
2ff057 |
* so you can end up with eg nice/ionice'd mysql or httpd, ouch.
|
|
|
2ff057 |
* This plugin resets the scriptlet process priorities after forking, and
|
|
|
2ff057 |
* can be used to counter that effect. Should not be used with systemd
|
|
|
2ff057 |
* because the it's not needed there, and the effect is counter-productive.
|
|
|
2ff057 |
*/
|
|
|
2ff057 |
|
|
|
2ff057 |
static rpmRC prioreset_scriptlet_fork_post(rpmPlugin plugin, const char *path, int type)
|
|
|
2ff057 |
{
|
|
|
2ff057 |
/* Call for resetting nice priority. */
|
|
|
2ff057 |
int ret = setpriority(PRIO_PROCESS, 0, 0);
|
|
|
2ff057 |
if (ret == -1) {
|
|
|
2ff057 |
rpmlog(RPMLOG_WARNING, _("Unable to reset nice value: %s"),
|
|
|
2ff057 |
strerror(errno));
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
/* Call for resetting IO priority. */
|
|
|
2ff057 |
#if defined(__linux__)
|
|
|
2ff057 |
/* Defined at include/linux/ioprio.h */
|
|
|
2ff057 |
const int _IOPRIO_WHO_PROCESS = 1;
|
|
|
2ff057 |
const int _IOPRIO_CLASS_NONE = 0;
|
|
|
2ff057 |
ret = syscall(SYS_ioprio_set, _IOPRIO_WHO_PROCESS, 0, _IOPRIO_CLASS_NONE);
|
|
|
2ff057 |
if (ret == -1) {
|
|
|
2ff057 |
rpmlog(RPMLOG_WARNING, _("Unable to reset I/O priority: %s"),
|
|
|
2ff057 |
strerror(errno));
|
|
|
2ff057 |
}
|
|
|
2ff057 |
#endif
|
|
|
2ff057 |
|
|
|
2ff057 |
return RPMRC_OK;
|
|
|
2ff057 |
}
|
|
|
2ff057 |
|
|
|
2ff057 |
struct rpmPluginHooks_s prioreset_hooks = {
|
|
|
2ff057 |
.scriptlet_fork_post = prioreset_scriptlet_fork_post,
|
|
|
2ff057 |
};
|