# HG changeset patch # User reimar # Date 1322766615 0 # Node ID 3a4adac4e9a5efd9da65faf5fd8a0513c556541a # Parent 6edabf4151e9d89b6a88d8fc6ac6d414f85f3b69 Make cache process detect when the main process disappeared and make it exit on its own in that case. diff -r 6edabf4151e9 -r 3a4adac4e9a5 stream/cache2.c --- a/stream/cache2.c Thu Dec 01 19:09:20 2011 +0000 +++ b/stream/cache2.c Thu Dec 01 19:10:15 2011 +0000 @@ -75,6 +75,9 @@ 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 @@ -279,6 +282,13 @@ 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; @@ -346,6 +356,9 @@ s->fill_limit=8*sector; s->back_size=s->buffer_size/2; +#if FORKED_CACHE + s->ppid = getpid(); +#endif return s; }