summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/osxhelp.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 21:26:53 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 21:26:53 +0200
commitdf247efec654e512242e4f4f1b0212034f9e01fe (patch)
tree25c02e16957f3aa613af30c140fd8e8a3d52fda6 /app/wlib/gtklib/osxhelp.c
parentd0b6a8a4ec298024f14f704f9e40a6f9d324ccf3 (diff)
parenta5ade52caa489cf0a713e0f02b764000d203140e (diff)
Merge branch 'release/debian/1%5.2.0Beta2.1-1' into masterdebian/1%5.2.0Beta2.1-1
Diffstat (limited to 'app/wlib/gtklib/osxhelp.c')
-rw-r--r--app/wlib/gtklib/osxhelp.c67
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);
}