coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/6] cp: -Z: fix handling of open errors in restorecon()


From: Pádraig Brady
Subject: [PATCH 6/6] cp: -Z: fix handling of open errors in restorecon()
Date: Tue, 4 Dec 2012 16:32:25 +0000

* src/selinux.c (restorecon_private): open() returns -1 on error.
---
 src/selinux.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/selinux.c b/src/selinux.c
index e1c122b..0bb6bcc 100644
--- a/src/selinux.c
+++ b/src/selinux.c
@@ -170,10 +170,10 @@ restorecon_private (char const *path, bool local)
     }
 
   fd = open (path, O_RDONLY | O_NOFOLLOW);
-  if (!fd && (errno != ELOOP))
+  if (fd == -1 && (errno != ELOOP))
     goto quit;
 
-  if (fd)
+  if (fd != -1)
     {
       if (fstat (fd, &sb) < 0)
         goto quit;
@@ -189,7 +189,7 @@ restorecon_private (char const *path, bool local)
   if (!(scontext = context_new (scon)))
     goto quit;
 
-  if (fd)
+  if (fd != -1)
     {
       if (fgetfilecon (fd, &tcon) < 0)
         goto quit;
@@ -210,13 +210,14 @@ restorecon_private (char const *path, bool local)
   if (!(constr = context_str (tcontext)))
     goto quit;
 
-  if (fd)
+  if (fd != -1)
     rc = fsetfilecon (fd, constr);
   else
     rc = lsetfilecon (path, constr);
 
 quit:
-  close (fd);
+  if (fd != -1)
+    close (fd);
   context_free (scontext);
   context_free (tcontext);
   freecon (scon);
-- 
1.7.6.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]