|
|
fe6837 |
diff -up yum-utils-1.1.31/docs/needs-restarting.1.orig yum-utils-1.1.31/docs/needs-restarting.1
|
|
|
fe6837 |
--- yum-utils-1.1.31/docs/needs-restarting.1.orig 2016-08-04 12:22:33.765295008 +0200
|
|
|
fe6837 |
+++ yum-utils-1.1.31/docs/needs-restarting.1 2016-08-04 12:24:52.076356702 +0200
|
|
|
fe6837 |
@@ -16,6 +16,8 @@ Display a help message, and then quit.
|
|
|
fe6837 |
Show processes for my userid only.
|
|
|
fe6837 |
.IP "\fB\-r, \-\-reboothint\fP"
|
|
|
fe6837 |
Only report whether a full reboot is required (returns 1) or not (returns 0).
|
|
|
fe6837 |
+.IP "\fB\-s, \-\-services\fP"
|
|
|
fe6837 |
+List the affected systemd services only.
|
|
|
fe6837 |
|
|
|
fe6837 |
.PP
|
|
|
fe6837 |
.SH "SEE ALSO"
|
|
|
fe6837 |
diff -up yum-utils-1.1.31/needs-restarting.py.orig yum-utils-1.1.31/needs-restarting.py
|
|
|
fe6837 |
--- yum-utils-1.1.31/needs-restarting.py.orig 2016-08-04 12:22:15.914287046 +0200
|
|
|
fe6837 |
+++ yum-utils-1.1.31/needs-restarting.py 2016-08-04 12:24:22.235343391 +0200
|
|
|
fe6837 |
@@ -65,6 +65,8 @@ def parseargs(args):
|
|
|
fe6837 |
parser.add_option("-r", "--reboothint", default=False, action="store_true",
|
|
|
fe6837 |
help=('only report whether a full reboot is required (returns 1) or not '
|
|
|
fe6837 |
'(returns 0)'))
|
|
|
fe6837 |
+ parser.add_option("-s", "--services", default=False, action="store_true",
|
|
|
fe6837 |
+ help='list the affected systemd services only')
|
|
|
fe6837 |
|
|
|
fe6837 |
(opts, args) = parser.parse_args(args)
|
|
|
fe6837 |
return (opts, args)
|
|
|
fe6837 |
@@ -106,6 +108,31 @@ def get_open_files(pid):
|
|
|
fe6837 |
files.append(filename)
|
|
|
fe6837 |
return files
|
|
|
fe6837 |
|
|
|
fe6837 |
+def get_service(pid):
|
|
|
fe6837 |
+ """Return the systemd service to which the process belongs.
|
|
|
fe6837 |
+
|
|
|
fe6837 |
+ More details:
|
|
|
fe6837 |
+ http://0pointer.de/blog/projects/systemd-for-admins-2.html
|
|
|
fe6837 |
+ https://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions/
|
|
|
fe6837 |
+ """
|
|
|
fe6837 |
+
|
|
|
fe6837 |
+ fname = '/proc/%s/cgroup' % pid
|
|
|
fe6837 |
+ try:
|
|
|
fe6837 |
+ with open(fname, 'r') as f:
|
|
|
fe6837 |
+ groups = f.readlines()
|
|
|
fe6837 |
+ except (IOError, OSError), e:
|
|
|
fe6837 |
+ print >>sys.stderr, "Could not open %s" % fname
|
|
|
fe6837 |
+ return None
|
|
|
fe6837 |
+
|
|
|
fe6837 |
+ for line in groups:
|
|
|
fe6837 |
+ line = line.replace('\n', '')
|
|
|
fe6837 |
+ hid, hsub, cgroup = line.split(':')
|
|
|
fe6837 |
+ if hsub == 'name=systemd':
|
|
|
fe6837 |
+ name = cgroup.split('/')[-1]
|
|
|
fe6837 |
+ if name.endswith('.service'):
|
|
|
fe6837 |
+ return name
|
|
|
fe6837 |
+ return None
|
|
|
fe6837 |
+
|
|
|
fe6837 |
def main(args):
|
|
|
fe6837 |
(opts, args) = parseargs(args)
|
|
|
fe6837 |
|
|
|
fe6837 |
@@ -189,6 +216,13 @@ def main(args):
|
|
|
fe6837 |
|
|
|
fe6837 |
|
|
|
fe6837 |
|
|
|
fe6837 |
+ if opts.services:
|
|
|
fe6837 |
+ names = set([get_service(pid) for pid in needing_restart])
|
|
|
fe6837 |
+ for name in names:
|
|
|
fe6837 |
+ if name is not None:
|
|
|
fe6837 |
+ print name
|
|
|
fe6837 |
+ return 0
|
|
|
fe6837 |
+
|
|
|
fe6837 |
for pid in needing_restart:
|
|
|
fe6837 |
try:
|
|
|
fe6837 |
cmdline = open('/proc/' +pid+ '/cmdline', 'r').read()
|