Hi Lon and Steven,

i found a bug in liblogsys and i have no idea how to fix it.

In attachment there is the smallest test case i could write.

Build with:  gcc -Wall -O0 -ggdb test.c -L/usr/lib/openais -llogsys
or similar.. please keep liblogsys shared as it should be in the final application.

The problem is that logsys init doesn't survive a fork() used to daemonize (like many applications do).

The expected result in the simplified test case is that child will print its won pid (works fine with printf) but it doesn't with log_printf.

Applied to a larger scale (i was porting ccsd to logsys) other problematics appear because the hang in futex will make the child unkillable if not by kill -9 meaning.

I will need a quick fix for this one otherwise i am blocked again on another transition.

Thanks
Fabio

--
I'm going to make him an offer he can't refuse.
#include <openais/service/logsys.h>

#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

LOGSYS_DECLARE_SYSTEM (NULL,
	LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_DISPLAY_DEBUG,
	NULL,
	LOG_DAEMON);

LOGSYS_DECLARE_SUBSYS ("TEST", LOG_INFO);

int main(int argc, char *argv[]) {
	pid_t cpid, w;
	int status;

	if(argc > 1)
		logsys_config_subsys_set("TEST", LOGSYS_TAG_LOG, LOG_DEBUG);

	log_printf(LOG_DEBUG, "Entering daemon mode.\n");

	cpid = fork();
	if (cpid == -1) {
		perror("fork");
		exit(EXIT_FAILURE);
	}

	if (cpid == 0) {	/* Code executed by child */
		log_printf(LOG_INFO, "Child PID is %ld\n", (long) getpid());
		pause();
	} else {		/* Code executed by parent */
		do {
			w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
			if (w == -1) {
				perror("waitpid");
				exit(EXIT_FAILURE);
			}

			if (WIFEXITED(status)) {
				log_printf(LOG_INFO, "exited, status=%d\n", WEXITSTATUS(status));
			} else if (WIFSIGNALED(status)) {
				log_printf(LOG_INFO, "killed by signal %d\n", WTERMSIG(status));
			} else if (WIFSTOPPED(status)) {
				log_printf(LOG_INFO, "stopped by signal %d\n", WSTOPSIG(status));
			} else if (WIFCONTINUED(status)) {
				log_printf(LOG_INFO, "continued\n");
			}
		} while (!WIFEXITED(status) && !WIFSIGNALED(status));
		exit(EXIT_SUCCESS);
	}

	return 0;
}
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to