File qtcurve-1.8.17-fix_run_command.patch of Package qtcurve-gtk2.openSUSE_13.1_Update

From f55d663fefc51d21e7153da5071485f4d1f07aed Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Sat, 11 Jan 2014 14:35:38 +0100
Subject: [PATCH] gtk2: Fix runCommand SIGCHILD race condition.

The SIGCHILD handler gets replaced which could cause race conditions on
fast machines. This patch resets the SIGCHILD handler to the default
before we call popen() and restores it afterwards.

Fixes issue #41.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
---
 gtk2/style/qt_settings.c | 66 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 53 insertions(+), 13 deletions(-)

Index: QtCurve-Gtk2-1.8.16/style/qt_settings.c
===================================================================
--- QtCurve-Gtk2-1.8.16.orig/style/qt_settings.c	2014-01-11 14:54:18.483858950 +0100
+++ QtCurve-Gtk2-1.8.16/style/qt_settings.c	2014-01-11 14:55:03.923240278 +0100
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <pwd.h>
 #include <sys/types.h>
+#include <signal.h>
 
 #define strcmp_i(A, B) strncmp_i(A, B, -1)
 
@@ -2994,20 +2995,58 @@ void qtSettingsSetColors(GtkStyle *style
 
 bool runCommand(const char* cmd, char** result)
 {
-    FILE* fp = popen(cmd, "r");
-    if(fp)
-    {
-        gulong bufSize=512;
-        size_t currentOffset=0;
-        *result=(char*)(g_malloc(bufSize));
-        while(fgets(*result+currentOffset, bufSize-currentOffset, fp) && result[strlen(*result)-1] != '\n')
-        {
-            currentOffset = bufSize-1;
-            bufSize *= 2;
-            *result = (char*)(g_realloc(*result, bufSize));
+    size_t currentOffset = 0;
+    size_t bufSize = 512;
+    char *tmp;
+    FILE *fp;
+    int rc;
+    struct sigaction oldact;
+    struct sigaction act;
+
+    /* Reset SIGCHILD handler to default */
+    rc = sigaction(SIGCHLD, NULL, &oldact);
+    if (rc < 0) {
+        return false;
+    }
+
+    act.sa_flags = SA_RESETHAND;
+    sigemptyset(&act.sa_mask);
+
+    rc = sigaction(SIGCHLD, &act, NULL);
+    if (rc < 0) {
+        return false;
+    }
+
+    fp = popen(cmd, "r");
+    if (fp == NULL) {
+        return false;
+    }
+
+    *result = (char*)malloc(bufSize);
+    if (*result == NULL) {
+        return false;
+    }
+
+    while(feof(fp) == 0 &&
+          fgets(*result + currentOffset, bufSize - currentOffset, fp) != NULL &&
+          (*result)[strlen(*result) - 1] != '\n') {
+        char *tmp;
+
+        currentOffset = bufSize - 1;
+        bufSize *= 2;
+
+        tmp = (char*)(realloc(*result, bufSize));
+        if (tmp == NULL) {
+            free(*result);
+            *result = NULL;
+            return false;
         }
-        pclose(fp);
-        return true;
+        *result = tmp;
     }
-    return false;
+    pclose(fp);
+
+    /* Sed old SIGCHILD handler */
+    sigaction(SIGCHLD, &oldact, NULL);
+
+    return true;
 }
openSUSE Build Service is sponsored by