valeriyvdovin / rpms / systemd

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