qemud: prevent recursive closure of clients.

+ add android/hw-qemud-pipe.h

Change-Id: Icf7b316137cd9f1ce46e4c3642addccea6222a24
diff --git a/android/hw-qemud-pipe.h b/android/hw-qemud-pipe.h
new file mode 100644
index 0000000..540e02b
--- /dev/null
+++ b/android/hw-qemud-pipe.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _ANDROID_HW_QEMUD_PIPE_H
+#define _ANDROID_HW_QEMUD_PIPE_H
+
+void init_qemud_pipes(void);
+void android_hw_opengles_init(void);
+
+#endif /* _ANDROID_HW_QEMUD_PIPE_H */
diff --git a/android/hw-qemud.c b/android/hw-qemud.c
index e1cd119..e91ec78 100644
--- a/android/hw-qemud.c
+++ b/android/hw-qemud.c
@@ -532,7 +532,7 @@
     }
 
     /* packetize the payload for the serial MTU */
-    while (len > 0) 
+    while (len > 0)
     {
         avail = len;
         if (avail > MAX_SERIAL_PAYLOAD)
@@ -600,6 +600,7 @@
     /* framing support */
     int               framing;
     ABool             need_header;
+    ABool             closing;
     QemudSink         header[1];
     uint8_t           header0[FRAME_HEADER_SIZE];
     QemudSink         payload[1];
@@ -661,7 +662,7 @@
 
         if (len >= 0 && msglen == len + FRAME_HEADER_SIZE) {
             if (c->clie_recv)
-                c->clie_recv( c->clie_opaque, 
+                c->clie_recv( c->clie_opaque,
                               msg+FRAME_HEADER_SIZE,
                               msglen-FRAME_HEADER_SIZE, c );
             return;
@@ -724,6 +725,11 @@
 {
     QemudClient*  c = opaque;
 
+    if (c->closing) {  /* recursive call, exit immediately */
+        return;
+    }
+    c->closing = 1;
+
     /* remove from current list */
     qemud_client_remove(c);
 
diff --git a/android/hw-qemud.h b/android/hw-qemud.h
index 18eec6f..cd05737 100644
--- a/android/hw-qemud.h
+++ b/android/hw-qemud.h
@@ -90,12 +90,12 @@
  * (see below).
  */
 extern QemudClient*  qemud_client_new( QemudService*     service,
-                                       int               channel_id,
-                                       void*             clie_opaque,
-                                       QemudClientRecv   clie_recv,
-                                       QemudClientClose  clie_close,
-                                       QemudClientSave   clie_save,
-                                       QemudClientLoad   clie_load );
+                                        int               channel_id,
+                                        void*             clie_opaque,
+                                        QemudClientRecv   clie_recv,
+                                        QemudClientClose  clie_close,
+                                        QemudClientSave   clie_save,
+                                        QemudClientLoad   clie_load );
 
 /* Enable framing on a given client channel.
  */