Skip to content

Commit

Permalink
WIP syslog_probe: see if LD_PRELOAD survives fork...
Browse files Browse the repository at this point in the history
this isn't it, so what's the problem??
  • Loading branch information
elliefm committed Jul 15, 2024
1 parent bfee684 commit edf3763
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions cassandane/utils/syslog_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
* given string as ident prefix
*/

#include <sys/wait.h>

#include <stdio.h>
#include <syslog.h>
#include <unistd.h>

/* straight outta cyrus */
#define SYSLOG_FACILITY LOG_LOCAL6

int main(int argc, char **argv)
{
char ident[1024];
int pid;

if (argc != 2) {
fprintf(stderr, "Usage: %s prefix\n", argv[0]);
Expand All @@ -21,9 +25,28 @@ int main(int argc, char **argv)

snprintf(ident, sizeof(ident), "%s/syslog_probe", argv[1]);

openlog(ident, LOG_PID, SYSLOG_FACILITY);
syslog(LOG_NOTICE, "the magic word");
closelog();
pid = fork();
if (pid == 0) {
/* child */
openlog(ident, LOG_PID, SYSLOG_FACILITY);
syslog(LOG_NOTICE, "the magic word");
closelog();

return 0;
}
else if (pid > 0) {
/* parent */
int wstatus;

if (wait(&wstatus) && WIFEXITED(wstatus)) {
return WEXITSTATUS(wstatus);
}

return 0;
return -1;
}
else {
/* fork failed */
perror("fork");
return -1;
}
}

0 comments on commit edf3763

Please sign in to comment.