Skip to content

Commit

Permalink
restorecond: check selinux_restorecon(3) for failure
Browse files Browse the repository at this point in the history
    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]>
  • Loading branch information
cgzones committed May 12, 2023
1 parent 9ff1915 commit 3e05a92
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions restorecond/watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3e05a92

Please sign in to comment.