osaf/services/infrastructure/nid/nodeinit.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
There were three loops in nodeinit.c that could potentially become infinite if a system call returns -1. It is fine to try again when e.g. errno == EINTR, since that is a temporary error that will go away eventually. In general however, trying again will not make the error go away and the loop would become infinite. Also made a file descriptor non-blocking to avoid blocking indefinitely in read(). diff --git a/osaf/services/infrastructure/nid/nodeinit.c b/osaf/services/infrastructure/nid/nodeinit.c --- a/osaf/services/infrastructure/nid/nodeinit.c +++ b/osaf/services/infrastructure/nid/nodeinit.c @@ -46,6 +46,8 @@ * any notification. * ************************************************************************/ +#include <unistd.h> +#include <fcntl.h> #include <syslog.h> #include <libgen.h> #include <ctype.h> @@ -621,6 +623,8 @@ int32_t fork_daemon(NID_SPAWN_INFO *serv if(-1 == pipe(filedes)) LOG_ER("Problem creating pipe: %s", strerror(errno)); + else + fcntl(filedes[0], F_SETFL, fcntl(filedes[0], F_GETFL) | O_NONBLOCK); if ((pid = fork()) == 0) { if (nis_fifofd > 0) @@ -641,10 +645,10 @@ int32_t fork_daemon(NID_SPAWN_INFO *serv continue; else if (errno == EPIPE) { LOG_ER("Reader not available to return my PID"); - exit(2); } else { LOG_ER("Problem writing to pipe, err=%s", strerror(errno)); } + exit(2); } setsid(); @@ -691,6 +695,7 @@ int32_t fork_daemon(NID_SPAWN_INFO *serv } if (errno == EINTR) continue; + break; } while (read(filedes[0], &tmp_pid, sizeof(int)) < 0) @@ -1002,7 +1007,7 @@ uint32_t spawn_wait(NID_SPAWN_INFO *serv LOG_ER("Timed-out for response from %s", service->serv_name); return NCSCC_RC_FAILURE; } - + break; } /* Read the message from FIFO and fill in structure. */ ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel