Blame SOURCES/BZ-1335587-needs-restarting-add-services-opt.patch

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