--- openjdk/jdk/make/launchers/Makefile.launcher.orig	2008-07-09 12:49:00.000000000 -0400
+++ openjdk/jdk/make/launchers/Makefile.launcher	2008-07-09 12:49:40.000000000 -0400
@@ -148,6 +148,16 @@
   endif
 endif
 
+# pluginappletviewer only
+ifeq ($(PROGRAM), pluginappletviewer)
+  OTHER_CPPFLAGS += -DUSE_UMASK=\"077\"
+endif
+
+# javaws only
+ifeq ($(PROGRAM), javaws)
+  OTHER_CPPFLAGS += -DUSE_UMASK=\"077\"
+endif
+
 # GUI tools
 ifeq ($(GUI_TOOL),true)
   ifneq ($(PLATFORM), windows)
--- openjdk/jdk/src/share/bin/java.c.orig	2008-07-09 12:48:35.000000000 -0400
+++ openjdk/jdk/src/share/bin/java.c	2008-07-09 12:36:11.000000000 -0400
@@ -56,6 +56,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include <jni.h>
 #include <jvm.h>
@@ -69,6 +70,8 @@
 #define FULL_VERSION JDK_MAJOR_VERSION "." JDK_MINOR_VERSION
 #endif
 
+#define MAXMASK 4095 /* Same as octal 07777 */
+
 /*
  * The following environment variable is used to influence the behavior
  * of the jre exec'd through the SelectVersion routine.  The command line
@@ -184,6 +187,10 @@
 
 int JNICALL JavaMain(void * args); /* entry point                  */
 
+/* umask things */
+static int FindUMask(int *, char ***, int *);
+static int VerifyMask(char *, int*);
+
 struct JavaMainArgs {
   int     argc;
   char ** argv;
@@ -307,6 +314,26 @@
     SetClassPath(s);
 #endif
 
+#ifdef USE_UMASK
+	/* Set umask */
+	int mask;
+    // Check to see if we can find a umask on the command line.
+    if (FindUMask(&argc, &argv, &mask) < 0)
+    {
+        // We didn't find a umask, so fall back to the default one.
+        char * defaultMask = (char *) JLI_MemAlloc(5 * sizeof(char));
+        strcpy(defaultMask, USE_UMASK);
+        int converted;
+        VerifyMask(defaultMask, &converted);
+        JLI_MemFree(defaultMask);
+		umask(converted); /* from sys/stat.h */
+    }
+    else
+    {
+		umask(mask);
+    }
+#endif
+
     /*
      *  Parse command line options; if the return value of
      *  ParseArguments is false, the program should exit.
@@ -2011,3 +2038,87 @@
     }
     DoSplashSetFileJarName(file_name, jar_name);
 }
+
+/**
+ * Searches argv to find any parameters that start with "-umask=".
+ * Sets maskToSet with the mask if a -umask is found, and if the mask
+ * supplied is valid. Returns 1 if a valid mask was found and set,
+ * -1 otherwise.
+ */
+int FindUMask(int *pargc, char *** pargv, int *maskToSet)
+{
+    int found_mask = -1;
+
+    // our handles to the original list
+    int argc = *pargc;
+    char **argv = *pargv;
+
+    // the new set
+    int nargc = argc;
+    char ** nargv = (char **) JLI_MemAlloc((nargc + 1) * sizeof(char *));
+
+    // set the original set to the new set
+    *pargv = nargv;
+    *pargc = nargc;
+
+    char *maskString = (char *) JLI_MemAlloc(6 * sizeof(char *));
+	int i;
+    for (i = 0; i < argc; i++)
+    {
+        char *arg = argv[i];
+        if (strncmp(arg, "-umask=",7) == 0)
+        {
+            strncpy(maskString, arg+7, 5);
+
+            if (VerifyMask(maskString, maskToSet) < 0)
+            {
+                printf("Invalid umask %s, application stopped.\n", maskString);
+                exit(1);
+            }
+
+            found_mask = 1;
+            nargc--;
+            (*pargc)--;
+        }
+        else
+        {
+            *nargv++ = arg;
+        }
+    }
+
+    JLI_MemFree(maskString);
+
+    return found_mask;
+}
+
+/**
+ * Takes an octal mask in string form, and converts it to
+ * decimal form in convertedMask. The decimal form can then be
+ * easily passed to umask(). Returns 1 if the mask is valid, -1 otherwise.
+ */
+int VerifyMask(char * maskString, int * convertedMask)
+{
+    // Borrowed from coreutils modechange.c
+    if ('0' <= *maskString && *maskString < '8')
+    {
+        unsigned int decimal_mode = 0;
+
+        do {
+            decimal_mode = 8 * decimal_mode + *maskString++ - '0';
+        } while ('0' <= *maskString && *maskString < '8');
+
+        if (decimal_mode > MAXMASK)
+            return -1;
+        else if (*maskString)
+            return -1;
+        else
+            *convertedMask = decimal_mode;
+
+        return 1;
+    }
+    else
+    {
+        return -1;
+    }
+
+}
