From b623f5953691b2a0614e6f1f4def86bdbb9a4113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Aug 2020 11:53:00 +0200 Subject: New upstream version 5.2.0Beta2.1 --- app/wlib/gtklib/osxhelp.c | 67 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 19 deletions(-) (limited to 'app/wlib/gtklib/osxhelp.c') diff --git a/app/wlib/gtklib/osxhelp.c b/app/wlib/gtklib/osxhelp.c index 829ec94..4ec1f5e 100644 --- a/app/wlib/gtklib/osxhelp.c +++ b/app/wlib/gtklib/osxhelp.c @@ -28,6 +28,7 @@ #include #include +#include "misc.h" #include "gtkint.h" #include "i18n.h" @@ -39,6 +40,7 @@ static pid_t pidOfChild; static int handleOfPipe; extern char *wExecutableName; + /** * Create the fully qualified filename for the help helper * @@ -70,14 +72,21 @@ char *ChildProgramFile(char *parentProgram) void wHelp(const char * topic) { pid_t newPid; - int len; int status; const char html[] = ".html"; + static char *directory; /**< base directory for HTML files */ + char * htmlFile; + + struct { + int length; char *page; - + } buffer; + + if (!CheckHelpTopicExists(topic)) return; + // check whether child already exists if (pidOfChild != 0) { - if (waitpid(pidOfChild, &status, WNOHANG) > 0) { + if (waitpid(pidOfChild, &status, WNOHANG) < 0) { // child exited -> clean up close(handleOfPipe); unlink(HELPCOMMANDPIPE); @@ -88,7 +97,8 @@ void wHelp(const char * topic) // (re)start child if (pidOfChild == 0) { - mkfifo(HELPCOMMANDPIPE, 0666); + unlink(HELPCOMMANDPIPE); + int rc = mkfifo(HELPCOMMANDPIPE, 0666); newPid = fork(); /* New process starts here */ if (newPid > 0) { @@ -107,27 +117,46 @@ void wHelp(const char * topic) } } - if (!handleOfPipe) { - handleOfPipe = open(HELPCOMMANDPIPE, O_WRONLY); - - if (handleOfPipe < 0) { - kill(pidOfChild, SIGKILL); /* tidy up on next call */ - } + buffer.page = malloc(sizeof(int)+strlen(topic) + strlen(html) + 1); + if (!buffer.page) { + return; } - page = malloc(strlen(topic) + strlen(html) + 1); + strcpy(buffer.page, topic); + strcat(buffer.page, html); + buffer.length = strlen(buffer.page); - if (!page) { - return; + if (buffer.length>255) { + printf("Help Topic too long %s", buffer.page); + return; } - strcpy(page, topic); - strcat(page, html); - len = strlen(page); + if (!handleOfPipe) { + handleOfPipe = open(HELPCOMMANDPIPE, O_WRONLY); + + if (handleOfPipe < 0) { + if (pidOfChild) + kill(pidOfChild, SIGKILL); /* tidy up on next call */ + handleOfPipe = 0; + return; + } + + } + + int written = 0; + int towrite = sizeof(int); + + while (written < towrite){ + written += write(handleOfPipe, &buffer.length, sizeof(int)); + } + written =0; + towrite = strlen(buffer.page); + while (written < towrite){ + written += write(handleOfPipe, buffer.page+written, towrite-written); + } - write(handleOfPipe, &len, sizeof(int)); - write(handleOfPipe, page, strlen(page)+1); + fsync(handleOfPipe); - free(page); + free(buffer.page); } -- cgit v1.2.3