summaryrefslogtreecommitdiffstats
path: root/src/wth-receiver-comm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wth-receiver-comm.c')
-rw-r--r--src/wth-receiver-comm.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/wth-receiver-comm.c b/src/wth-receiver-comm.c
index e6c0266..0527ecd 100644
--- a/src/wth-receiver-comm.c
+++ b/src/wth-receiver-comm.c
@@ -34,12 +34,16 @@
** **
** **
*******************************************************************************/
+#include <sys/types.h>
+#include <signal.h>
#include "wth-receiver-comm.h"
#include "wth-receiver-surface.h"
#include "wth-receiver-seat.h"
#include "wth-receiver-buffer.h"
+#include <waltham-util.h>
+
extern uint16_t tcp_port;
extern const char *my_app_id;
@@ -59,9 +63,17 @@ static void
wthp_ivi_surface_destroy(struct wthp_ivi_surface * ivi_surface)
{
struct ivisurface *ivisurf = wth_object_get_user_data((struct wth_object *)ivi_surface);
-
- if (ivisurf->surf->ivi_app_id)
- free(ivisurf->surf->ivi_app_id);
+ struct client *client = ivisurf->appid->client;
+
+ if (client) {
+ client->pid_destroying = true;
+ fprintf(stdout, "client pid_destroying to true for client %p pid %d\n",
+ client, client->pid);
+ if (kill(client->pid, SIGINT) < 0) {
+ fprintf(stderr, "Failed to send SIGINT to child %d\n",
+ client->pid);
+ }
+ }
free(ivisurf);
}
@@ -80,34 +92,42 @@ wthp_ivi_app_id_surface_create(struct wthp_ivi_app_id *ivi_application,
struct wthp_surface * wthp_surface,
struct wthp_ivi_surface *obj)
{
- struct surface *surface = wth_object_get_user_data((struct wth_object *)wthp_surface);
-
- /* we destroy it wthp_ivi_surface_implementation:: */
- if (my_app_id) {
- surface->ivi_app_id = strdup(my_app_id);
- surface->shm_window->app_id = surface->ivi_app_id;
- }
-
- struct ivisurface *ivisurf;
+ struct surface *surface =
+ wth_object_get_user_data((struct wth_object *)wthp_surface);
+ struct application_id *appid =
+ wth_object_get_user_data((struct wth_object *) ivi_application);
+ pid_t cpid;
- ivisurf = zalloc(sizeof *ivisurf);
+ struct ivisurface *ivisurf = zalloc(sizeof *ivisurf);
if (!ivisurf) {
return;
}
ivisurf->obj = obj;
ivisurf->surf = surface;
+ ivisurf->appid = appid;
wthp_ivi_surface_set_interface(obj,
&wthp_ivi_surface_implementation, ivisurf);
- if (my_app_id)
- wth_receiver_weston_main(surface->shm_window, my_app_id, tcp_port);
- else
- wth_receiver_weston_main(surface->shm_window, app_id, tcp_port);
+ cpid = fork();
+ if (cpid == -1) {
+ fprintf(stderr, "Failed to fork()\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (cpid == 0) {
+ if (my_app_id)
+ wth_receiver_weston_main(surface->shm_window, my_app_id, tcp_port);
+ else
+ wth_receiver_weston_main(surface->shm_window, app_id, tcp_port);
+ } else {
+ /* this is parent, in wthp_ivi_surface_destroy() we mark that the
+ * client should be waited for so wait4() will be blocked.
+ */
+ appid->client->pid = cpid;
+ }
- while (!surface->shm_window->ready)
- usleep(1);
}
static const struct wthp_ivi_app_id_interface wthp_ivi_app_id_implementation = {
@@ -387,6 +407,7 @@ client_create(struct receiver *srv, struct wth_connection *conn)
disp = wth_connection_get_display(c->connection);
wth_display_set_interface(disp, &display_implementation, c);
+ fprintf(stdout, "Client %p created\n", c);
return c;
}
@@ -444,7 +465,6 @@ receiver_accept_client(struct receiver *srv)
wth_error("Failed to accept a connection.\n");
return;
}
-
client = client_create(srv, conn);
if (!client) {
wth_error("Failed client_create().\n");