From 37f9b486d3099a4b437c648220a50fe46c905ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 16 Jun 2022 16:22:02 +0200 Subject: [PATCH] restorecond: check selinux_restorecon(3) for failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- restorecond/watch.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/restorecond/watch.c b/restorecond/watch.c index 98ff797b47..64bc29c6d3 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; }