}
DEFINE_VWRAPPERF(static, badusage, NORET);
-static void open_screenshot_file(const char *mode) {
+static void open_screenshot_file(int for_write) {
if (!fnmatch("*.gz",o_screenshot_fn,0)) {
- int zfd, pipefds[2];
- sysassert( (zfd= open(o_screenshot_fn, O_WRONLY|O_CREAT|O_TRUNC,
- 0666)) >= 0);
- sysassert(! pipe(pipefds) );
- sysassert( (screenshot_compressor=fork()) != -1 );
- if (!screenshot_compressor) {
- sysassert( dup2(pipefds[0],0)==0 );
- sysassert( dup2(zfd,1)==1 );
- sysassert(! close(zfd) );
- sysassert(! close(pipefds[0]) );
- sysassert(! close(pipefds[1]) );
- execlp("gzip","gzip","-1",(char*)0);
- sysassert(!"execlp gzip for screenshots");
- }
- sysassert(! close(zfd) );
- sysassert(! close(pipefds[0]) );
- sysassert( screenshot_file= fdopen(pipefds[1], "w") );
-
+ int mode= for_write ? O_WRONLY|O_CREAT|O_TRUNC : O_RDONLY;
+ sysassert(! gzopen(o_screenshot_fn, mode, &screenshot_file,
+ &screenshot_compressor, "-1") );
} else {
- screenshot_file= fopen(o_screenshot_fn, mode);
+ screenshot_file= fopen(o_screenshot_fn, for_write ? "w" : "r");
if (!screenshot_file)
fatal("could not open screenshots file `%s': %s",
o_screenshot_fn, strerror(errno));
o_serv_dict_submit, o_flags & ff_dict_submit);
if (!o_screenshot_fn)
- o_screenshot_fn= masprintf("%s/_pages.ppm%s", get_vardir(),
- o_mode & mf_readscreenshot ? "" : ".gz");
+ o_screenshot_fn= masprintf("%s/_pages.ppm.gz", get_vardir());
/* Actually do the work */
}
if (o_mode & mf_screenshot) {
- open_screenshot_file("w");
+ open_screenshot_file(1);
if (o_flags & ff_singlepage) take_one_screenshot();
else take_screenshots();
progress_log("OK for you to move the mouse now, and you can"
" use the YPP client again.");
+ progress("Finishing handling screenshots...");
+ gzclose(&screenshot_file,&screenshot_compressor,"screenshots output");
}
if (o_mode & mf_readscreenshot) {
if ((o_flags & ff_upload) && !(o_flags & ff_testservers))
badusage("must not reuse screenshots for upload to live PCTB database");
- open_screenshot_file("r");
+ open_screenshot_file(0);
if (o_flags & ff_singlepage) read_one_screenshot();
else read_screenshots();
+ gzclose(&screenshot_file,&screenshot_compressor,"screenshots input");
}
if (o_mode & mf_analyse) {
if (o_flags & ff_needisland) {
default: abort();
}
}
- if (screenshot_compressor!=-1) {
- progress("Finishing compressing screenshots...");
- waitpid_check_exitstatus(screenshot_compressor,"screenshots gzip",0);
- }
progress_log("Finished.");
return 0;
}