dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
Blob Blame History Raw
From c59c376b2623330a70ab692844ca00eb58f67576 Mon Sep 17 00:00:00 2001
From: Martin Pitt <martin.pitt@ubuntu.com>
Date: Thu, 19 Feb 2015 11:06:24 +0100
Subject: [PATCH] sysv-generator: fix wrong "Overwriting existing symlink"
 warnings

Fix result testing of is_symlink() to ignore negative results, which happen if
the file name does not exist at all. In this case we do not want a warning and
unlink the non-existing link.

https://bugs.debian.org/778700
(cherry picked from commit 4e5589836c9e143796c3f3d81e67ab7a9209e2b0)

Apparently this was missed for some reason and did not end up in
stable previously.

Cherry-picked from: 4e55898
Resolves: #1222517
---
 src/sysv-generator/sysv-generator.c | 2 +-
 test/sysv-generator-test.py         | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index cfc4a99e4a..3c6cb8f10e 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -166,7 +166,7 @@ static int generate_unit_file(SysvStub *s) {
         /* We might already have a symlink with the same name from a Provides:,
          * or from backup files like /etc/init.d/foo.bak. Real scripts always win,
          * so remove an existing link */
-        if (is_symlink(unit)) {
+        if (is_symlink(unit) > 0) {
                 log_warning("Overwriting existing symlink %s with real service", unit);
                 (void) unlink(unit);
         }
diff --git a/test/sysv-generator-test.py b/test/sysv-generator-test.py
index 509899e0a5..e716d705c0 100644
--- a/test/sysv-generator-test.py
+++ b/test/sysv-generator-test.py
@@ -178,6 +178,8 @@ class SysvGeneratorTest(unittest.TestCase):
         self.assertEqual(s.get('Service', 'ExecStop'),
                          '%s stop' % init_script)
 
+        self.assertNotIn('Overwriting', err)
+
     def test_simple_enabled_all(self):
         '''simple service without dependencies, enabled in all runlevels'''
 
@@ -185,6 +187,7 @@ class SysvGeneratorTest(unittest.TestCase):
         err, results = self.run_generator()
         self.assertEqual(list(results), ['foo.service'])
         self.assert_enabled('foo.service', [2, 3, 4, 5])
+        self.assertNotIn('Overwriting', err)
 
     def test_simple_enabled_some(self):
         '''simple service without dependencies, enabled in some runlevels'''
@@ -270,6 +273,7 @@ class SysvGeneratorTest(unittest.TestCase):
         for f in ['bar.service', 'baz.service']:
             self.assertEqual(os.readlink(os.path.join(self.out_dir, f)),
                              'foo.service')
+        self.assertNotIn('Overwriting', err)
 
     def test_same_provides_in_multiple_scripts(self):
         '''multiple init.d scripts provide the same name'''
@@ -289,6 +293,9 @@ class SysvGeneratorTest(unittest.TestCase):
         self.add_sysv('bar', {'Provides': 'bar'}, enable=True)
         err, results = self.run_generator()
         self.assertEqual(sorted(results), ['bar.service', 'foo.service'])
+        # we do expect an overwrite here, bar.service should overwrite the
+        # alias link from foo.service
+        self.assertIn('Overwriting', err)
 
     def test_nonexecutable_script(self):
         '''ignores non-executable init.d script'''