* Start a new thread and fork() for image viewer (broken/disabled; for
authorMichael Hampton <io_error@uncensored.citadel.org>
Sun, 21 Dec 2003 19:07:28 +0000 (19:07 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Sun, 21 Dec 2003 19:07:28 +0000 (19:07 +0000)
  refernce only)

citadel/ChangeLog
citadel/messages.c

index 114f06e95ee1cbd1c95438e318ccfd3c3bee1a92..68d30c3a646836c9766a22f6333ef04f8dcf9180 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 613.6  2003/12/21 19:07:28  error
+ * Start a new thread and fork() for image viewer (broken/disabled; for
+   refernce only)
+
  Revision 613.5  2003/12/21 01:23:12  nbryant
  added some additional comments to citadel.rc concerning possible image viewers
 
@@ -5178,4 +5182,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 3911c42438551cb947364314c9d7ccdf7edddea5..971afbf1bb67b786850b3cc56140d8feabafac8d 100644 (file)
 # endif
 #endif
 
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
 #include <stdarg.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
@@ -94,6 +98,8 @@ char imagecmd[SIZ];
 int has_images = 0;                            /* Current msg has images */
 struct parts *last_message_parts = NULL;       /* Parts from last msg */
 
+
+
 void ka_sigcatch(int signum)
 {
        alarm(S_KEEPALIVE);
@@ -1301,6 +1307,41 @@ void list_urls(CtdlIPC *ipc)
        scr_printf("\n");
 }
 
+
+/*
+ * Image viewer thread (for background image viewing)
+ */
+void *image_view_thread(void *filename)
+{
+       char cmd[SIZ];
+       pid_t childpid;
+       int retcode;
+
+       snprintf(cmd, sizeof cmd, imagecmd, (char *)filename);
+       childpid = fork();
+       if (childpid < 0) {
+               color(BRIGHT_RED);
+               perror("Cannot fork");
+               color(DIM_WHITE);
+               unlink((char *)filename);
+               return ((void *) childpid);
+       }
+
+       if (childpid == 0) {
+               execlp("/bin/sh", "sh", "-c", cmd, NULL);
+               exit(127);
+       }
+
+       if (childpid > 0) {
+               waitpid(childpid, &retcode, 0);
+               unlink((char *)filename);
+               return ((void *)retcode);
+       }
+
+       return ((void *)-1);
+}
+
+
 /*
  * View an image attached to a message
  */
@@ -1344,6 +1385,9 @@ void image_view(CtdlIPC *ipc, unsigned long msg)
                                char tmp[PATH_MAX];
                                char buf[SIZ];
                                void *file = NULL; /* The downloaded file */
+#ifdef THREADED_CLIENT
+                               pthread_t *ivthread = NULL;
+#endif
                                int r;
 
                                // view image
@@ -1360,10 +1404,14 @@ void image_view(CtdlIPC *ipc, unsigned long msg)
                                        strcpy(tmp, tmpnam(NULL));
                                        save_buffer(file, len, tmp);
                                        free(file);
+                                       #if 0
+                                       pthread_create(ivthread, NULL, image_view_thread, tmp);
+                                       #endif
                                        snprintf(buf, sizeof buf, imagecmd, tmp);
                                        system(buf);
                                        unlink(tmp);
                                }
+                               break;
                        }
                }
        }