Skip to content

Commit f0223fa

Browse files
rmetrichstevegrubb
authored andcommitted
rpm-loader: add errno to sendmsg error message + switch from stderr to syslog for diagnostics
The daemon's become_daemon() redirects stderr to /dev/null before spawning the loader. Since the loader used MSG_STDERR, all its diagnostic messages (config errors, RPM load failures, sendmsg errors) were silently lost, making failures impossible to diagnose. Switch to MSG_SYSLOG so messages appear in the journal as fapolicyd-rpm-loader[PID]. Also add strerror_r(errno) to the sendmsg and recvmsg error messages for diagnosability.
1 parent 40026ed commit f0223fa

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/handler/fapolicyd-rpm-loader.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ int sock_fd = 3; // same number dup2’ed by parent
6565
int main(int argc, char * const argv[])
6666
{
6767

68-
set_message_mode(MSG_STDERR, DBG_YES);
68+
set_message_mode(MSG_SYSLOG, DBG_NO);
69+
openlog("fapolicyd-rpm-loader", LOG_PID, LOG_DAEMON);
6970

7071
if (load_daemon_config(&config)) {
7172
free_daemon_config(&config);
@@ -117,7 +118,9 @@ int main(int argc, char * const argv[])
117118
memcpy(CMSG_DATA(c), &memfd, sizeof(int));
118119

119120
if (sendmsg(sock_fd, &_msg, 0) < 0) {
120-
msg(LOG_ERR, "sendmsg failed");
121+
char err_buff[256];
122+
msg(LOG_ERR, "sendmsg failed (%s)",
123+
strerror_r(errno, err_buff, sizeof(err_buff)));
121124
exit(1);
122125
}
123126

src/library/rpm-backend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ static int rpm_load_list(const conf_t *conf)
278278
rc = recvmsg(sv[0], &_msg, 0);
279279
} while (rc < 0 && errno == EINTR);
280280
if (rc < 0) {
281-
msg(LOG_ERR, "recvmsg failed");
281+
char err_buff[BUFFER_SIZE];
282+
msg(LOG_ERR, "recvmsg failed (%s)",
283+
strerror_r(errno, err_buff, BUFFER_SIZE));
282284
close(sv[0]);
283285
while (waitpid(pid, &status, 0) < 0 && errno == EINTR);
284286
posix_spawn_file_actions_destroy(&actions);

0 commit comments

Comments
 (0)