summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-08-06 01:13:20 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-08-06 01:13:20 +0000
commit2f851c1d0a0abf911d070010946cb4e7d3c4e63b (patch)
tree8d09298aaf8dd5166838e4e8dc26930cf17cd3ea /src
parentfc2796ba7980447e364fe88b4bd58bde3113e555 (diff)
be a bit more paranoid about killling off child process from
terminology. SVN revision: 74892
Diffstat (limited to 'src')
-rw-r--r--src/bin/termpty.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index a762d5f..9de673d 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -4,6 +4,8 @@
4#include "termptyesc.h" 4#include "termptyesc.h"
5#include "termptyops.h" 5#include "termptyops.h"
6#include <sys/types.h> 6#include <sys/types.h>
7#include <signal.h>
8#include <sys/wait.h>
7#include <sys/stat.h> 9#include <sys/stat.h>
8#include <stdlib.h> 10#include <stdlib.h>
9#include <fcntl.h> 11#include <fcntl.h>
@@ -151,6 +153,8 @@ _cb_exe_exit(void *data, int type __UNUSED__, void *event)
151 ty->exit_code = ev->exit_code; 153 ty->exit_code = ev->exit_code;
152 if (ty->cb.exited.func) ty->cb.exited.func(ty->cb.exited.data); 154 if (ty->cb.exited.func) ty->cb.exited.func(ty->cb.exited.data);
153 155
156 ty->pid = -1;
157
154 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit); 158 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit);
155 ty->hand_exe_exit = NULL; 159 ty->hand_exe_exit = NULL;
156 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); 160 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd);
@@ -354,6 +358,41 @@ err:
354void 358void
355termpty_free(Termpty *ty) 359termpty_free(Termpty *ty)
356{ 360{
361 if (ty->pid >= 0)
362 {
363 int i;
364
365 // in case someone stopped the child - cont it
366 kill(ty->pid, SIGCONT);
367 // signpipe for shells
368 kill(ty->pid, SIGPIPE);
369 // try 400 time (sleeping for 1ms) to check for death of child
370 for (i = 0; i < 400; i++)
371 {
372 int status = 0;
373
374 // poll exit of child pid
375 if (waitpid(ty->pid, &status, WNOHANG) == ty->pid)
376 {
377 // if child exited - break loop and mark pid as done
378 ty->pid = -1;
379 break;
380 }
381 // after 100ms set sigint
382 if (i == 100) kill(ty->pid, SIGINT);
383 // after 200ms send term signal
384 else if (i == 200) kill(ty->pid, SIGTERM);
385 // after 300ms send quit signal
386 else if (i == 300) kill(ty->pid, SIGQUIT);
387 usleep(1000); // sleep 1ms
388 }
389 // so 400ms and child not gone - KILL!
390 if (ty->pid >= 0)
391 {
392 kill(ty->pid, SIGKILL);
393 ty->pid = -1;
394 }
395 }
357 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit); 396 if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit);
358 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); 397 if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd);
359 if (ty->prop.title) eina_stringshare_del(ty->prop.title); 398 if (ty->prop.title) eina_stringshare_del(ty->prop.title);