Skip to content

Commit

Permalink
libsemanage: avoid strerror(3)
Browse files Browse the repository at this point in the history
Use the %m printf modifier to format errno in a thread safe way.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Nov 21, 2024
1 parent b56d915 commit b592a3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions libsemanage/src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ void semanage_msg_default_handler(void *varg __attribute__ ((unused)),
vfprintf(stream, fmt, ap);
va_end(ap);

if (errsv && errsv != ENOMEM)
fprintf(stream, " (%s).", strerror(errsv));
if (errsv && errsv != ENOMEM) {
errno = errsv;
fprintf(stream, " (%m).");
}

fprintf(stream, "\n");
}
Expand Down
4 changes: 2 additions & 2 deletions libsemanage/src/semanage_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,8 @@ static int semanage_rename(semanage_handle_t * sh, const char *src, const char *
return retval;

/* we can't use rename() due to filesystem limitation, lets try to copy files manually */
WARN(sh, "WARNING: rename(%s, %s) failed: %s, fall back to non-atomic semanage_copy_dir_flags()",
src, dst, strerror(errno));
WARN(sh, "WARNING: rename(%s, %s) failed: %m, fall back to non-atomic semanage_copy_dir_flags()",
src, dst);
if (semanage_copy_dir_flags(src, dst, 1) == -1) {
return -1;
}
Expand Down

0 comments on commit b592a3f

Please sign in to comment.