summaryrefslogtreecommitdiff
blob: e18d733fd2789163bab42c14564b2c2cd48a67dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
diff --exclude-from=/home/dang/.diffrc -u -ruN gstreamer-0.10.10.orig/gst/gst.c gstreamer-0.10.10/gst/gst.c
--- gstreamer-0.10.10.orig/gst/gst.c	2006-09-14 10:02:23.000000000 -0400
+++ gstreamer-0.10.10/gst/gst.c	2006-10-17 12:44:43.000000000 -0400
@@ -683,10 +683,16 @@
 {
 #ifdef HAVE_FORK
   pid_t pid;
+  int pfd[2];
 
   /* We fork here, and let the child read and possibly rebuild the registry.
    * After that, the parent will re-read the freshly generated registry. */
   GST_DEBUG ("forking");
+
+  if (pipe (pfd) == -1) {
+    return FALSE;
+  }
+
   pid = fork ();
   if (pid == -1) {
     GST_ERROR ("Failed to fork()");
@@ -695,8 +701,11 @@
 
   if (pid == 0) {
     gboolean res;
+    gchar res_byte;
 
-    /* this is the child */
+    /* this is the child. Close the read pipe */
+    close (pfd[0]);
+    
     GST_DEBUG ("child reading registry cache");
     res = scan_and_update_registry (default_registry, registry_file, TRUE);
     _gst_registry_remove_cache_plugins (default_registry);
@@ -708,38 +717,42 @@
     /* make valgrind happy (yes, you can call it insane) */
     g_free ((char *) registry_file);
 
-    _exit ((res) ? EXIT_SUCCESS : EXIT_FAILURE);
+    /* write a result byte to the pipe */
+    res_byte = res ? '1' : '0';
+    write (pfd[1], &res_byte, 1);
+    _exit (0);
   } else {
-    /* parent */
-    int status;
-    pid_t ret;
+    int ret;
+    gchar res_byte;
+    
+    /* parent. Close write pipe */
+    close (pfd[1]);
+    
+    /* Wait for result from the pipe */
+    GST_DEBUG ("Waiting for data from child");
+    ret = read (pfd[0], &res_byte, 1);
 
-    GST_DEBUG ("parent waiting on child");
-    ret = waitpid (pid, &status, 0);
-    GST_DEBUG ("parent done waiting on child");
     if (ret == -1) {
-      GST_ERROR ("error during waitpid: %s", g_strerror (errno));
+      close (pfd[0]);
       return FALSE;
     }
+    close (pfd[0]);
 
-    if (!WIFEXITED (status)) {
-      if (WIFSIGNALED (status)) {
-        GST_ERROR ("child did not exit normally, terminated by signal %d",
-            WTERMSIG (status));
-      } else {
-        GST_ERROR ("child did not exit normally, status: %d", status);
-      }
+     /* Wait to ensure the child is reaped, but ignore the result */
+    GST_DEBUG ("parent waiting on child");
+    waitpid (pid, NULL, 0);
+    GST_DEBUG ("parent done waiting on child");
+
+    if (ret == 0) {
+      GST_ERROR ("child did not exit normally, terminated by signal");
       return FALSE;
     }
 
-    GST_DEBUG ("child exited normally with return value %d",
-        WEXITSTATUS (status));
-
-    if (WEXITSTATUS (status) == EXIT_SUCCESS) {
-      GST_DEBUG ("parent reading registry cache");
+    if (res_byte == '1') {
+      GST_DEBUG ("Child succeeded. Parent reading registry cache");
       gst_registry_xml_read_cache (default_registry, registry_file);
     } else {
-      GST_DEBUG ("parent re-scanning registry");
+      GST_DEBUG ("Child failed. Parent re-scanning registry, ignoring errors.");
       scan_and_update_registry (default_registry, registry_file, FALSE);
     }
   }