diff mbox series

[RFC,8/9] restorecond: check selinux_restorecon(3) for failure

Message ID 20230512102322.72235-8-cgzones@googlemail.com (mailing list archive)
State New
Delegated to: Petr Lautrbach
Headers show
Series [RFC,1/9] libselinux: annotate interfaces with compiler attributes | expand

Commit Message

Christian Göttsche May 12, 2023, 10:23 a.m. UTC
watch.c: In function ‘watch_list_add’:
    watch.c:74:25: error: ignoring return value of ‘selinux_restorecon’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
       74 |                         selinux_restorecon(globbuf.gl_pathv[i],
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       75 |                                            r_opts.restorecon_flags);
          |                                            ~~~~~~~~~~~~~~~~~~~~~~~~
    watch.c: In function ‘watch_list_find’:
    watch.c:141:33: error: ignoring return value of ‘selinux_restorecon’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
      141 |                                 selinux_restorecon(path,
          |                                 ^~~~~~~~~~~~~~~~~~~~~~~~
      142 |                                                    r_opts.restorecon_flags);
          |                                                    ~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 restorecond/watch.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/restorecond/watch.c b/restorecond/watch.c
index 98ff797b..64bc29c6 100644
--- a/restorecond/watch.c
+++ b/restorecond/watch.c
@@ -71,8 +71,12 @@  void watch_list_add(int fd, const char *path)
 			if (len > 0 &&
 			    strcmp(&globbuf.gl_pathv[i][len], "/..") == 0)
 				continue;
-			selinux_restorecon(globbuf.gl_pathv[i],
-					   r_opts.restorecon_flags);
+
+			if (selinux_restorecon(globbuf.gl_pathv[i], r_opts.restorecon_flags) < 0) {
+				if (errno != ENOENT)
+					syslog(LOG_ERR, "Unable to relabel %s:  %s\n",
+					       globbuf.gl_pathv[i], strerror(errno));
+			}
 		}
 		globfree(&globbuf);
 	}
@@ -138,8 +142,12 @@  int watch_list_find(int wd, const char *file)
 				    0)
 					exitApp("Error allocating memory.");
 
-				selinux_restorecon(path,
-						   r_opts.restorecon_flags);
+				if (selinux_restorecon(path, r_opts.restorecon_flags) < 0) {
+					if (errno != ENOENT)
+						syslog(LOG_ERR, "Unable to relabel %s:  %s\n",
+						       path, strerror(errno));
+				}
+
 				free(path);
 				return 0;
 			}