#include <stdlib.h> /* for malloc */
#include <ctype.h> /* for isprint */
#include <unistd.h> /* for fork/exec */
+#include <sys/types.h> /* for wait */
+#include <sys/wait.h> /* for wait */
#define __USE_GNU
#include <string.h> /* for making strcasestr happy */
// up at all, we've already been here and time to fail
if ( pos == 0 ) {
break; // done, FAIL
- } else if ( pos > PND_PXML_WINDOW_FRACTIONAL ) {
+
+ } else if ( pos > PND_PXML_WINDOW_FRACTIONAL ) { // lots of space to back-seek
pos -= PND_PXML_WINDOW_FRACTIONAL;
readable = PND_PXML_WINDOW_SIZE;
- } else {
+
+ // at some point when back-seeking, we just give up; we could seek through
+ // whole file (and if someone has gone and broken a pnd-file, the behaviour is
+ // 'undefined' .. but lets be kind in case that guy then distributes the broken
+ // file around. So we backseek to a point, but stop after xKB backwards?
+ if ( len - pos > (500*1024) ) {
+ break;
+ }
+
+ } else { // can only backseek less than the window-size
readable = PND_PXML_WINDOW_SIZE - pos;
memset ( b + pos, '\0', PND_PXML_WINDOW_SIZE - pos );
pos = 0;
} else {
// child, do it
execv ( pndrun, argv );
- }
+ }
+
+ // wait until mountscript actually completes
+ int status = 0;
+ waitpid ( f, &status, 0 /* options */ );
return ( 1 );
}