valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0232-sysv-generator-fix-wrong-Overwriting-existing-symlin.patch

1ff636
From c59c376b2623330a70ab692844ca00eb58f67576 Mon Sep 17 00:00:00 2001
1ff636
From: Martin Pitt <martin.pitt@ubuntu.com>
1ff636
Date: Thu, 19 Feb 2015 11:06:24 +0100
1ff636
Subject: [PATCH] sysv-generator: fix wrong "Overwriting existing symlink"
1ff636
 warnings
1ff636
1ff636
Fix result testing of is_symlink() to ignore negative results, which happen if
1ff636
the file name does not exist at all. In this case we do not want a warning and
1ff636
unlink the non-existing link.
1ff636
1ff636
https://bugs.debian.org/778700
1ff636
(cherry picked from commit 4e5589836c9e143796c3f3d81e67ab7a9209e2b0)
1ff636
1ff636
Apparently this was missed for some reason and did not end up in
1ff636
stable previously.
1ff636
1ff636
Cherry-picked from: 4e55898
1ff636
Resolves: #1222517
1ff636
---
1ff636
 src/sysv-generator/sysv-generator.c | 2 +-
1ff636
 test/sysv-generator-test.py         | 7 +++++++
1ff636
 2 files changed, 8 insertions(+), 1 deletion(-)
1ff636
1ff636
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
181b3f
index cfc4a99e4..3c6cb8f10 100644
1ff636
--- a/src/sysv-generator/sysv-generator.c
1ff636
+++ b/src/sysv-generator/sysv-generator.c
1ff636
@@ -166,7 +166,7 @@ static int generate_unit_file(SysvStub *s) {
1ff636
         /* We might already have a symlink with the same name from a Provides:,
1ff636
          * or from backup files like /etc/init.d/foo.bak. Real scripts always win,
1ff636
          * so remove an existing link */
1ff636
-        if (is_symlink(unit)) {
1ff636
+        if (is_symlink(unit) > 0) {
1ff636
                 log_warning("Overwriting existing symlink %s with real service", unit);
1ff636
                 (void) unlink(unit);
1ff636
         }
1ff636
diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py
181b3f
index 509899e0a..e716d705c 100644
1ff636
--- a/test/sysv-generator-test.py
1ff636
+++ b/test/sysv-generator-test.py
1ff636
@@ -178,6 +178,8 @@ class SysvGeneratorTest(unittest.TestCase):
1ff636
         self.assertEqual(s.get('Service', 'ExecStop'),
1ff636
                          '%s stop' % init_script)
1ff636
 
1ff636
+        self.assertNotIn('Overwriting', err)
1ff636
+
1ff636
     def test_simple_enabled_all(self):
1ff636
         '''simple service without dependencies, enabled in all runlevels'''
1ff636
 
1ff636
@@ -185,6 +187,7 @@ class SysvGeneratorTest(unittest.TestCase):
1ff636
         err, results = self.run_generator()
1ff636
         self.assertEqual(list(results), ['foo.service'])
1ff636
         self.assert_enabled('foo.service', [2, 3, 4, 5])
1ff636
+        self.assertNotIn('Overwriting', err)
1ff636
 
1ff636
     def test_simple_enabled_some(self):
1ff636
         '''simple service without dependencies, enabled in some runlevels'''
1ff636
@@ -270,6 +273,7 @@ class SysvGeneratorTest(unittest.TestCase):
1ff636
         for f in ['bar.service', 'baz.service']:
1ff636
             self.assertEqual(os.readlink(os.path.join(self.out_dir, f)),
1ff636
                              'foo.service')
1ff636
+        self.assertNotIn('Overwriting', err)
1ff636
 
1ff636
     def test_same_provides_in_multiple_scripts(self):
1ff636
         '''multiple init.d scripts provide the same name'''
1ff636
@@ -289,6 +293,9 @@ class SysvGeneratorTest(unittest.TestCase):
1ff636
         self.add_sysv('bar', {'Provides': 'bar'}, enable=True)
1ff636
         err, results = self.run_generator()
1ff636
         self.assertEqual(sorted(results), ['bar.service', 'foo.service'])
1ff636
+        # we do expect an overwrite here, bar.service should overwrite the
1ff636
+        # alias link from foo.service
1ff636
+        self.assertIn('Overwriting', err)
1ff636
 
1ff636
     def test_nonexecutable_script(self):
1ff636
         '''ignores non-executable init.d script'''