Bug 750950 - Kill any zombie processes if database is locked (r=blassey a=blassey)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 11 May 2012 17:09:04 +0100
changeset 94275 7ced703e9e5236a26cb402ef789afa1b7b3e6f43
parent 94274 6fc8256df073e637064b2648689318106f7da1c2
child 94276 7bac62505304eabe93d2e47aa15205bb32418fa9
push id1297
push usermfinkle@mozilla.com
push dateTue, 15 May 2012 20:04:38 +0000
treeherdermozilla-aurora@7ced703e9e52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, blassey
bugs750950
milestone14.0a2
Bug 750950 - Kill any zombie processes if database is locked (r=blassey a=blassey)
mobile/android/base/GeckoAppShell.java
mobile/android/base/db/BrowserProvider.java.in
mobile/android/base/db/DBUtils.java
mobile/android/base/db/TabsProvider.java.in
mozglue/android/nsGeckoUtils.cpp
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -232,18 +232,16 @@ public class GeckoAppShell
     public static native void notifyReadingMessageListFailed(int aError, int aRequestId, long aProcessId);
 
     public static native ByteBuffer allocateDirectBuffer(long size);
     public static native void freeDirectBuffer(ByteBuffer buf);
     public static native void scheduleComposite();
     public static native void schedulePauseComposition();
     public static native void scheduleResumeComposition(int width, int height);
 
-    public static native void unlockDatabaseFile(String databasePath);
-
     public static native SurfaceBits getSurfaceBits(Surface surface);
 
     private static class GeckoMediaScannerClient implements MediaScannerConnectionClient {
         private String mFile = "";
         private String mMimeType = "";
         private MediaScannerConnection mScanner = null;
 
         public GeckoMediaScannerClient(Context aContext, String aFile, String aMimeType) {
--- a/mobile/android/base/db/BrowserProvider.java.in
+++ b/mobile/android/base/db/BrowserProvider.java.in
@@ -16,16 +16,17 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Random;
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 
+import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoBackgroundThread;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.CommonColumns;
 import org.mozilla.gecko.db.BrowserContract.Control;
 import org.mozilla.gecko.db.BrowserContract.History;
--- a/mobile/android/base/db/DBUtils.java
+++ b/mobile/android/base/db/DBUtils.java
@@ -70,20 +70,19 @@ public class DBUtils {
             aValues.put(aNewKey, value);
         }
     }
 
     public static void ensureDatabaseIsNotLocked(SQLiteOpenHelper dbHelper, String databasePath) {
         try {
             dbHelper.getWritableDatabase();
         } catch (Exception e) {
-            Log.d(LOGTAG, "Database is locked, trying to forcefully unlock the database file: " + databasePath);
+            Log.d(LOGTAG, "Database is locked, trying to kill any zombie processes: " + databasePath);
 
-            // Forcefully unlock the database file
-            GeckoAppShell.unlockDatabaseFile(databasePath);
+            GeckoAppShell.killAnyZombies();
 
             // This call should not throw if the forced unlocking
             // actually fixed the situation.
             dbHelper.getWritableDatabase();
 
             // TODO: maybe check if the database is still locked and let the
             // user know that the device needs rebooting?
         }
--- a/mobile/android/base/db/TabsProvider.java.in
+++ b/mobile/android/base/db/TabsProvider.java.in
@@ -6,16 +6,17 @@
 package @ANDROID_PACKAGE_NAME@.db;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoBackgroundThread;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.db.BrowserContract.CommonColumns;
 import org.mozilla.gecko.db.BrowserContract.Clients;
 import org.mozilla.gecko.db.BrowserContract.Tabs;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.DBUtils;
 import org.mozilla.gecko.sync.Utils;
--- a/mozglue/android/nsGeckoUtils.cpp
+++ b/mozglue/android/nsGeckoUtils.cpp
@@ -78,40 +78,8 @@ Java_org_mozilla_gecko_GeckoAppShell_all
 
 extern "C"
 __attribute__ ((visibility("default")))
 void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_freeDirectBuffer(JNIEnv *jenv, jclass, jobject buf)
 {
     free(jenv->GetDirectBufferAddress(buf));
 }
-
-extern "C"
-__attribute__ ((visibility("default")))
-void JNICALL
-Java_org_mozilla_gecko_GeckoAppShell_unlockDatabaseFile(JNIEnv *jenv, jclass, jstring jDatabasePath)
-{
-    const char *databasePath = jenv->GetStringUTFChars(jDatabasePath, NULL);
-    int fd = open(databasePath, O_RDWR);
-    jenv->ReleaseStringUTFChars(jDatabasePath, databasePath);
-
-    // File could not be open, do nothing
-    if (fd < 0) {
-        return;
-    }
-
-    struct flock lock;
-
-    lock.l_type = F_WRLCK;
-    lock.l_whence = SEEK_SET;
-    lock.l_start = 0;
-    lock.l_len = 0;
-
-    int result = fcntl(fd, F_GETLK, &lock);
-
-    // Release any existing lock in the file
-    if (result != -1 && lock.l_type == F_WRLCK) {
-        lock.l_type = F_UNLCK;
-        fcntl(fd, F_SETLK, &lock);
-    }
-
-    close(fd);
-}