version 1.79, 2014/08/06 15:09:05 |
version 1.82, 2014/09/03 23:21:47 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#ifdef HAVE_CONFIG_H |
|
#include "config.h" |
#include "config.h" |
#endif |
|
|
|
#ifdef HAVE_MMAP |
#include <sys/types.h> |
# include <sys/stat.h> |
#if HAVE_MMAP |
# include <sys/mman.h> |
#include <sys/mman.h> |
|
#include <sys/stat.h> |
#endif |
#endif |
|
#include <sys/wait.h> |
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
Line 214 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 214 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
".so request failed", |
".so request failed", |
|
|
/* system errors */ |
/* system errors */ |
|
"cannot dup file descriptor", |
|
"cannot exec", |
|
"gunzip failed with code", |
|
"cannot fork", |
NULL, |
NULL, |
"cannot stat file", |
"cannot open pipe", |
"cannot read file", |
"cannot read file", |
|
"gunzip died from signal", |
|
"cannot stat file", |
|
"wait failed", |
}; |
}; |
|
|
static const char * const mandoclevels[MANDOCLEVEL_MAX] = { |
static const char * const mandoclevels[MANDOCLEVEL_MAX] = { |
Line 591 read_whole_file(struct mparse *curp, const char *file, |
|
Line 598 read_whole_file(struct mparse *curp, const char *file, |
|
size_t off; |
size_t off; |
ssize_t ssz; |
ssize_t ssz; |
|
|
#ifdef HAVE_MMAP |
#if HAVE_MMAP |
struct stat st; |
struct stat st; |
if (-1 == fstat(fd, &st)) { |
if (-1 == fstat(fd, &st)) { |
curp->file_status = MANDOCLEVEL_SYSERR; |
curp->file_status = MANDOCLEVEL_SYSERR; |
Line 764 mparse_readfd(struct mparse *curp, int fd, const char |
|
Line 771 mparse_readfd(struct mparse *curp, int fd, const char |
|
|
|
mparse_parse_buffer(curp, blk, file); |
mparse_parse_buffer(curp, blk, file); |
|
|
#ifdef HAVE_MMAP |
#if HAVE_MMAP |
if (with_mmap) |
if (with_mmap) |
munmap(blk.buf, blk.sz); |
munmap(blk.buf, blk.sz); |
else |
else |
Line 775 mparse_readfd(struct mparse *curp, int fd, const char |
|
Line 782 mparse_readfd(struct mparse *curp, int fd, const char |
|
perror(file); |
perror(file); |
out: |
out: |
return(curp->file_status); |
return(curp->file_status); |
|
} |
|
|
|
enum mandoclevel |
|
mparse_open(struct mparse *curp, int *fd, const char *file, |
|
pid_t *child_pid) |
|
{ |
|
int pfd[2]; |
|
char *cp; |
|
enum mandocerr err; |
|
|
|
pfd[1] = -1; |
|
curp->file = file; |
|
if ((cp = strrchr(file, '.')) == NULL || |
|
strcmp(cp + 1, "gz")) { |
|
*child_pid = 0; |
|
if ((*fd = open(file, O_RDONLY)) == -1) { |
|
err = MANDOCERR_SYSOPEN; |
|
goto out; |
|
} |
|
return(MANDOCLEVEL_OK); |
|
} |
|
|
|
if (pipe(pfd) == -1) { |
|
err = MANDOCERR_SYSPIPE; |
|
goto out; |
|
} |
|
|
|
switch (*child_pid = fork()) { |
|
case -1: |
|
err = MANDOCERR_SYSFORK; |
|
close(pfd[0]); |
|
close(pfd[1]); |
|
pfd[1] = -1; |
|
break; |
|
case 0: |
|
close(pfd[0]); |
|
if (dup2(pfd[1], STDOUT_FILENO) == -1) { |
|
err = MANDOCERR_SYSDUP; |
|
break; |
|
} |
|
execlp("gunzip", "gunzip", "-c", file, NULL); |
|
err = MANDOCERR_SYSEXEC; |
|
break; |
|
default: |
|
close(pfd[1]); |
|
*fd = pfd[0]; |
|
return(MANDOCLEVEL_OK); |
|
} |
|
|
|
out: |
|
*fd = -1; |
|
*child_pid = 0; |
|
curp->file_status = MANDOCLEVEL_SYSERR; |
|
if (curp->mmsg) |
|
(*curp->mmsg)(err, curp->file_status, file, |
|
0, 0, strerror(errno)); |
|
if (pfd[1] != -1) |
|
exit(1); |
|
return(curp->file_status); |
|
} |
|
|
|
enum mandoclevel |
|
mparse_wait(struct mparse *curp, pid_t child_pid) |
|
{ |
|
int status; |
|
|
|
if (waitpid(child_pid, &status, 0) == -1) { |
|
mandoc_msg(MANDOCERR_SYSWAIT, curp, 0, 0, |
|
strerror(errno)); |
|
curp->file_status = MANDOCLEVEL_SYSERR; |
|
return(curp->file_status); |
|
} |
|
if (WIFSIGNALED(status)) { |
|
mandoc_vmsg(MANDOCERR_SYSSIG, curp, 0, 0, |
|
"%d", WTERMSIG(status)); |
|
curp->file_status = MANDOCLEVEL_SYSERR; |
|
return(curp->file_status); |
|
} |
|
if (WEXITSTATUS(status)) { |
|
mandoc_vmsg(MANDOCERR_SYSEXIT, curp, 0, 0, |
|
"%d", WEXITSTATUS(status)); |
|
curp->file_status = MANDOCLEVEL_SYSERR; |
|
return(curp->file_status); |
|
} |
|
return(MANDOCLEVEL_OK); |
} |
} |
|
|
struct mparse * |
struct mparse * |