diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-08 11:53:00 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-08 11:53:00 +0200 |
commit | b623f5953691b2a0614e6f1f4def86bdbb9a4113 (patch) | |
tree | 18102bd36f7e22eb2ba2b9f880e4cb29346f4cb8 /app/wlib/gtklib/osxhelp.c | |
parent | 359b557176b9bb2ff1aed2082641eed39c358d0d (diff) |
New upstream version 5.2.0Beta2.1upstream/5.2.0Beta2.1
Diffstat (limited to 'app/wlib/gtklib/osxhelp.c')
-rw-r--r-- | app/wlib/gtklib/osxhelp.c | 67 |
1 files changed, 48 insertions, 19 deletions
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 <errno.h> #include <fcntl.h> +#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); } |