changeset 1992:27d312b0129c

Fixed Bug# 166: Create FIFO pies in temp dir instead of ~/.icedteaplugin
author Deepak Bhole <dbhole@redhat.com>
date Fri, 19 Mar 2010 11:40:06 -0400
parents d8b7563f3f3d
children 20627a528aa1
files ChangeLog plugin/icedteanp/IcedTeaNPPlugin.cc plugin/icedteanp/java/sun/applet/PluginMain.java
diffstat 3 files changed, 52 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Mar 19 11:31:17 2010 -0400
+++ b/ChangeLog	Fri Mar 19 11:40:06 2010 -0400
@@ -1,3 +1,12 @@
+2010-03-19  Deepak Bhole <dbhole@redhat.com>
+
+	* plugin/icedteanp/IcedTeaNPPlugin.cc
+	(start_jvm_if_needed): Create pipes in a temporary dir instead of users
+	home directory. 
+	(plugin_start_appletviewer): Pass pipe names to PluginMain when initializing Java.
+	* plugin/icedteanp/java/sun/applet/PluginMain.java: Receive pipe names
+	during initialization.
+
 2010-03-19  Deepak Bhole <dbhole@redhat.com>
 
 	* Makefile.am: Updated to use the renamed IcedTeaNPPlugin.cc file.
--- a/plugin/icedteanp/IcedTeaNPPlugin.cc	Fri Mar 19 11:31:17 2010 -0400
+++ b/plugin/icedteanp/IcedTeaNPPlugin.cc	Fri Mar 19 11:40:06 2010 -0400
@@ -434,8 +434,8 @@
   // pipe.
 
   // in_pipe_name
-  in_pipe_name = g_strdup_printf ("%s/icedteanp-appletviewer-to-plugin",
-                                         data_directory);
+  in_pipe_name = g_strdup_printf ("%s/%s-icedteanp-appletviewer-to-plugin",
+                                         data_directory, getenv ("USER"));
   if (!in_pipe_name)
     {
       PLUGIN_ERROR ("Failed to create input pipe name.");
@@ -449,7 +449,7 @@
   unlink (in_pipe_name);
 
   PLUGIN_DEBUG_1ARG ("GCJ_New: creating input fifo: %s\n", in_pipe_name);
-  if (mkfifo (in_pipe_name, 0700) == -1 && errno != EEXIST)
+  if (mkfifo (in_pipe_name, 0600) == -1 && errno != EEXIST)
     {
       PLUGIN_ERROR_TWO ("Failed to create input pipe", strerror (errno));
       np_error = NPERR_GENERIC_ERROR;
@@ -461,8 +461,8 @@
   // output pipe.
 
   // out_pipe_name
-  out_pipe_name = g_strdup_printf ("%s/icedteanp-plugin-to-appletviewer",
-                                         data_directory);
+  out_pipe_name = g_strdup_printf ("%s/%s-icedteanp-plugin-to-appletviewer",
+                                         data_directory, getenv ("USER"));
 
   if (!out_pipe_name)
     {
@@ -475,7 +475,7 @@
   unlink (out_pipe_name);
 
   PLUGIN_DEBUG_1ARG ("GCJ_New: creating output fifo: %s\n", out_pipe_name);
-  if (mkfifo (out_pipe_name, 0700) == -1 && errno != EEXIST)
+  if (mkfifo (out_pipe_name, 0600) == -1 && errno != EEXIST)
     {
       PLUGIN_ERROR_TWO ("Failed to create output pipe", strerror (errno));
       np_error = NPERR_GENERIC_ERROR;
@@ -1461,19 +1461,23 @@
 
   if (plugin_debug)
   {
-      command_line = (gchar**) malloc(sizeof(gchar*)*6);
+      command_line = (gchar**) malloc(sizeof(gchar*)*8);
       command_line[0] = g_strdup(appletviewer_executable);
       command_line[1] = g_strdup("-Xdebug");
       command_line[2] = g_strdup("-Xnoagent");
       command_line[3] = g_strdup("-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n");
       command_line[4] = g_strdup("sun.applet.PluginMain");
-      command_line[5] = NULL;
+      command_line[5] = g_strdup(out_pipe_name);
+      command_line[6] = g_strdup(in_pipe_name);
+      command_line[7] = NULL;
    } else
    {
-       command_line = (gchar**) malloc(sizeof(gchar)*3);
+       command_line = (gchar**) malloc(sizeof(gchar)*5);
        command_line[0] = g_strdup(appletviewer_executable);
        command_line[1] = g_strdup("sun.applet.PluginMain");
-       command_line[2] = NULL;
+       command_line[2] = g_strdup(out_pipe_name);
+       command_line[3] = g_strdup(in_pipe_name);
+       command_line[4] = NULL;
    }
 
   if (!g_spawn_async (NULL, command_line, NULL, (GSpawnFlags) G_SPAWN_DO_NOT_REAP_CHILD,
@@ -1963,7 +1967,7 @@
 
   // Make sure the plugin data directory exists, creating it if
   // necessary.
-  data_directory = g_strconcat (getenv ("HOME"), "/.icedteaplugin", NULL);
+  data_directory = g_strconcat (P_tmpdir, NULL);
   if (!data_directory)
     {
       PLUGIN_ERROR ("Failed to create data directory name.");
@@ -1971,20 +1975,34 @@
     }
   NPError np_error = NPERR_NO_ERROR;
   gchar* filename = NULL;
+
+  // If P_tmpdir does not exist, try /tmp directly
+
   if (!g_file_test (data_directory,
                     (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
     {
       int file_error = 0;
 
-      file_error = g_mkdir (data_directory, 0700);
-      if (file_error != 0)
-        {
-          PLUGIN_ERROR_THREE ("Failed to create data directory",
-                              data_directory,
-                              strerror (errno));
-          np_error = NPERR_GENERIC_ERROR;
-          goto cleanup_data_directory;
-        }
+      data_directory = g_strconcat ("/tmp", NULL);
+        if (!data_directory)
+          {
+            PLUGIN_ERROR ("Failed to create data directory name.");
+            return NPERR_OUT_OF_MEMORY_ERROR;
+          }
+
+    }
+
+  // If that doesn't exit, bail
+  if (!g_file_test (data_directory,
+                    (GFileTest) (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
+    {
+      PLUGIN_ERROR_THREE ("Temp directory does not exist: ",
+                          data_directory,
+                          strerror (errno));
+
+      np_error = NPERR_GENERIC_ERROR;
+            goto cleanup_data_directory;
+
     }
 
   // Set appletviewer_executable.
--- a/plugin/icedteanp/java/sun/applet/PluginMain.java	Fri Mar 19 11:31:17 2010 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginMain.java	Fri Mar 19 11:40:06 2010 -0400
@@ -107,9 +107,13 @@
     public static void main(String args[])
 	throws IOException
     {
+        if (args.length != 2 || !(new File(args[0]).exists()) || !(new File(args[1]).exists())) {
+            System.err.println("Invalid pipe names provided. Refusing to proceed.");
+            System.exit(1);
+        }
 
     	try {
-    		PluginMain pm = new PluginMain(System.getProperty("user.home") + "/.icedteaplugin/icedteanp-plugin-to-appletviewer", System.getProperty("user.home") + "/.icedteaplugin/icedteanp-appletviewer-to-plugin");
+    		PluginMain pm = new PluginMain(args[0], args[1]);
     	} catch (Exception e) {
     		e.printStackTrace();
     		System.err.println("Something very bad happened. I don't know what to do, so I am going to exit :(");