summaryrefslogtreecommitdiffstats
path: root/stream/cache2.c
diff options
context:
space:
mode:
authormplayer-svn <svn@mplayerhq.hu>2011-12-01 19:10:15 +0000
committerwm4 <wm4@nowhere>2012-08-03 01:35:39 +0200
commit01a207bef0e36680d8ca7adbd52a769d146eff9e (patch)
tree03cdef70a61d3382bada926167ba7cbdef311325 /stream/cache2.c
parent094acd6884e618aaf92bc53fcba8249224086389 (diff)
downloadmpv-01a207bef0e36680d8ca7adbd52a769d146eff9e.tar.bz2
mpv-01a207bef0e36680d8ca7adbd52a769d146eff9e.tar.xz
cache2: make cache process exit when main process dies
Make cache process detect when the main process disappeared and make it exit on its own in that case. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34371 b3059339-0415-0410-9bf9-f77b7e298cf2 Author: reimar
Diffstat (limited to 'stream/cache2.c')
-rw-r--r--stream/cache2.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/stream/cache2.c b/stream/cache2.c
index 8b88dbcacb..e399068b3f 100644
--- a/stream/cache2.c
+++ b/stream/cache2.c
@@ -70,6 +70,9 @@ typedef struct {
int back_size; // we should keep back_size amount of old bytes for backward seek
int fill_limit; // we should fill buffer only if space>=fill_limit
int seek_limit; // keep filling cache if distance is less that seek limit
+#if FORKED_CACHE
+ pid_t ppid; // parent PID to detect killed parent
+#endif
// filler's pointers:
int eof;
off_t min_filepos; // buffer contain only a part of the file, from min-max pos
@@ -274,6 +277,13 @@ static int cache_execute_control(cache_vars_t *s) {
s->stream_time_pos = pos;
else
s->stream_time_pos = MP_NOPTS_VALUE;
+#if FORKED_CACHE
+ // if parent PID changed, main process was killed -> exit
+ if (s->ppid != getppid()) {
+ mp_msg(MSGT_CACHE, MSGL_WARN, "Parent process disappeared, exiting cache process.\n");
+ return 0;
+ }
+#endif
last = GetTimerMS();
}
if (s->control == -1) return 1;
@@ -341,6 +351,9 @@ static cache_vars_t* cache_init(int size,int sector){
s->fill_limit=8*sector;
s->back_size=s->buffer_size/2;
+#if FORKED_CACHE
+ s->ppid = getpid();
+#endif
return s;
}