[Prevent] Handle unhandled exceptions in wrt-installer.
authorJan Olszak <j.olszak@samsung.com>
Wed, 12 Dec 2012 08:04:48 +0000 (09:04 +0100)
committerJan Olszak <j.olszak@samsung.com>
Wed, 12 Dec 2012 08:04:48 +0000 (09:04 +0100)
[Issue] Unhandled exceptions propagate to main().
[Bug] N/A
[Cause] N/A
[Solution] Catch all exceptions and log them.
[Verification] Build installer.

Change-Id: Ic5f43397c404bdab609884638099b24bbd8a7dc1

src/wrt-installer/wrt_installer.cpp

index fd6f903..297ec7b 100644 (file)
@@ -926,44 +926,48 @@ bool WrtInstaller::popupsEnabled() const
 
 int main(int argc, char *argv[])
 {
-    // Output on stdout will be flushed after every newline character,
-    // even if it is redirected to a pipe. This is useful for running
-    // from a script and parsing output.
-    // (Standard behavior of stdlib is to use full buffering when
-    // redirected to a pipe, which means even after an end of line
-    // the output may not be flushed).
-    setlinebuf(stdout);
-
-    // Check and re-set the file open limitation
-    struct rlimit rlim;
-    if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
-        LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")" );
-        LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")" );
-
-        if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
-            rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
-            rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
-            if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
-                LogError("setrlimit is fail!!");
+    UNHANDLED_EXCEPTION_HANDLER_BEGIN
+    {
+        // Output on stdout will be flushed after every newline character,
+        // even if it is redirected to a pipe. This is useful for running
+        // from a script and parsing output.
+        // (Standard behavior of stdlib is to use full buffering when
+        // redirected to a pipe, which means even after an end of line
+        // the output may not be flushed).
+        setlinebuf(stdout);
+
+        // Check and re-set the file open limitation
+        struct rlimit rlim;
+        if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
+            LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")" );
+            LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")" );
+
+            if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
+                rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
+                rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
+                if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
+                    LogError("setrlimit is fail!!");
+                }
             }
+        } else {
+            LogError("getrlimit is fail!!");
         }
-    } else {
-        LogError("getrlimit is fail!!");
-    }
 
-    // set evas backend type for emulator
-    // popup isn't showed in the emulator,
-    // if backend isn't set to SW backend
-    if (GlobalSettings::IsEmulator()) {
-        if (setenv("ELM_ENGINE", "x11", 1)) {
-            LogDebug("Enable backend");
+        // set evas backend type for emulator
+        // popup isn't showed in the emulator,
+        // if backend isn't set to SW backend
+        if (GlobalSettings::IsEmulator()) {
+            if (setenv("ELM_ENGINE", "x11", 1)) {
+                LogDebug("Enable backend");
+            }
         }
-    }
 
-    WrtInstaller app(argc, argv);
-    int ret = app.Exec();
-    LogDebug("App returned: " << ret);
-    ret = app.getReturnStatus();
-    LogDebug("WrtInstaller returned: " << ret);
-    return ret;
+        WrtInstaller app(argc, argv);
+        int ret = app.Exec();
+        LogDebug("App returned: " << ret);
+        ret = app.getReturnStatus();
+        LogDebug("WrtInstaller returned: " << ret);
+        return ret;
+    }
+    UNHANDLED_EXCEPTION_HANDLER_END
 }