Skip to content

Commit 33cbfdc

Browse files
committed
restorecond: check selinux_restorecon(3) for failure
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 <[email protected]>
1 parent a8a4812 commit 33cbfdc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

restorecond/watch.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ void watch_list_add(int fd, const char *path)
7171
if (len > 0 &&
7272
strcmp(&globbuf.gl_pathv[i][len], "/..") == 0)
7373
continue;
74-
selinux_restorecon(globbuf.gl_pathv[i],
75-
r_opts.restorecon_flags);
74+
75+
if (selinux_restorecon(globbuf.gl_pathv[i], r_opts.restorecon_flags) < 0) {
76+
if (errno != ENOENT)
77+
syslog(LOG_ERR, "Unable to relabel %s: %s\n",
78+
globbuf.gl_pathv[i], strerror(errno));
79+
}
7680
}
7781
globfree(&globbuf);
7882
}
@@ -138,8 +142,12 @@ int watch_list_find(int wd, const char *file)
138142
0)
139143
exitApp("Error allocating memory.");
140144

141-
selinux_restorecon(path,
142-
r_opts.restorecon_flags);
145+
if (selinux_restorecon(path, r_opts.restorecon_flags) < 0) {
146+
if (errno != ENOENT)
147+
syslog(LOG_ERR, "Unable to relabel %s: %s\n",
148+
path, strerror(errno));
149+
}
150+
143151
free(path);
144152
return 0;
145153
}

0 commit comments

Comments
 (0)