+2007-02-05 11:35 Christos Zoulas <christos@zoulas.com>
+
+ * make socket/pipe reading more robust
+
2007-01-25 16:01 Christos Zoulas <christos@zoulas.com>
* Centralize all the tests in file_buffer.
0 string This\ is\ Info\ file GNU Info text
# TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
-0 string \\input TeX document text
-0 string \\section LaTeX document text
-0 string \\setlength LaTeX document text
-0 string \\documentstyle LaTeX document text
-0 string \\chapter LaTeX document text
-0 string \\documentclass LaTeX 2e document text
-0 string \\relax LaTeX auxiliary file
-0 string \\contentsline LaTeX table of contents
-0 string %\ -*-latex-*- LaTeX document text
+0 search/400 \\input TeX document text
+0 search/400 \\section LaTeX document text
+0 search/400 \\setlength LaTeX document text
+0 search/400 \\documentstyle LaTeX document text
+0 search/400 \\chapter LaTeX document text
+0 search/400 \\documentclass LaTeX 2e document text
+0 search/400 \\relax LaTeX auxiliary file
+0 search/400 \\contentsline LaTeX table of contents
+0 search/400 %\ -*-latex-*- LaTeX document text
# Tex document, from Hendrik Scholz <hendrik@scholz.net>
0 string \\ifx TeX document text
# Index and glossary files
-0 string \\indexentry LaTeX raw index file
-0 string \\begin{theindex} LaTeX sorted index
-0 string \\glossaryentry LaTeX raw glossary
-0 string \\begin{theglossary} LaTeX sorted glossary
-0 string This\ is\ makeindex Makeindex log file
+0 search/400 \\indexentry LaTeX raw index file
+0 search/400 \\begin{theindex} LaTeX sorted index
+0 search/400 \\glossaryentry LaTeX raw glossary
+0 search/400 \\begin{theglossary} LaTeX sorted glossary
+0 search/400 This\ is\ makeindex Makeindex log file
# End of TeX
# RTF - Rich Text Format
0 string {\\rtf text/rtf
+# TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
+0 search/400 \\input text/x-tex
+0 search/400 \\section text/x-tex
+0 search/400 \\setlength text/x-tex
+0 search/400 \\documentstyle text/x-tex
+0 search/400 \\chapter text/x-tex
+0 search/400 \\documentclass text/x-tex
+
#------------------------------------------------------------------------------
# animation: file(1) magic for animation/movie formats
#
#endif
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.47 2007/01/16 14:56:45 ljt Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.48 2007/01/25 21:05:46 christos Exp $")
#endif
private struct {
* `safe' read for sockets and pipes.
*/
protected ssize_t
-sread(int fd, void *buf, size_t n)
+sread(int fd, void *buf, size_t n, int canbepipe)
{
- int rv;
+ int rv, cnt;
#ifdef FIONREAD
int t = 0;
#endif
goto nocheck;
#ifdef FIONREAD
- if ((ioctl(fd, FIONREAD, &t) < 0) || (t == 0)) {
+ if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1) || (t == 0)) {
#ifdef FD_ZERO
- for (;;) {
+ for (cnt = 0;; cnt++) {
fd_set check;
struct timeval tout = {0, 100 * 1000};
+ int rv;
FD_ZERO(&check);
FD_SET(fd, &check);
* Avoid soft deadlock: do not read if there
* is nothing to read from sockets and pipes.
*/
- if (select(fd + 1, &check, NULL, NULL, &tout) <= 0) {
+ rv = select(fd + 1, &check, NULL, NULL, &tout);
+ if (rv == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
+ } else if (rv == 0 && cnt >= 5) {
return 0;
- }
- break;
+ } else
+ break;
}
#endif
(void)ioctl(fd, FIONREAD, &t);
if (swrite(tfd, startbuf, nbytes) != (ssize_t)nbytes)
r = 1;
else {
- while ((r = sread(fd, buf, sizeof(buf))) > 0)
+ while ((r = sread(fd, buf, sizeof(buf), 1)) > 0)
if (swrite(tfd, buf, (size_t)r) != r)
break;
}
n = 0;
goto err;
}
- if ((r = sread(fdout[0], *newch, HOWMANY)) <= 0) {
+ if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
#ifdef DEBUG
(void)fprintf(stderr, "Read failed (%s)\n",
strerror(errno));
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.86 2007/01/18 05:29:33 ljt Exp $
+ * @(#)$File: file.h,v 1.87 2007/01/25 21:05:47 christos Exp $
*/
#ifndef __file_h__
protected void file_showstr(FILE *, const char *, size_t);
protected size_t file_mbswidth(const char *);
protected const char *file_getbuffer(struct magic_set *);
-protected ssize_t sread(int, void *, size_t);
+protected ssize_t sread(int, void *, size_t, int);
#ifdef ENABLE_CONDITIONALS
protected int file_check_mem(struct magic_set *, unsigned int);
#endif
#endif
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.25 2007/01/16 14:58:48 ljt Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.26 2007/01/25 21:05:47 christos Exp $")
#endif /* lint */
#ifndef HAVE_VSNPRINTF
#endif
/* try compression stuff */
- if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0 ||
+ if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 ||
(m = file_zmagic(ms, fd, inname, buf, nb)) == 0) {
/* Check if we have a tar file */
- if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0 ||
+ if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 ||
(m = file_is_tar(ms, buf, nb)) == 0) {
/* try tests in /etc/magic (or surrogate magic file) */
- if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0 ||
+ if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 ||
(m = file_softmagic(ms, buf, nb)) == 0) {
/* try known keywords, check whether it is ASCII */
- if ((ms->flags & MAGIC_NO_CHECK_ASCII) == 0 ||
+ if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 ||
(m = file_ascmagic(ms, buf, nb)) == 0) {
/* abandon hope, all ye who remain here */
if (file_printf(ms, ms->flags & MAGIC_MIME ?
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.37 2007/01/16 14:58:48 ljt Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.38 2007/01/25 21:05:47 christos Exp $")
#endif /* lint */
#ifdef __EMX__
ssize_t r = 0;
while ((r = sread(fd, (void *)&buf[nbytes],
- (size_t)(HOWMANY - nbytes))) > 0) {
+ (size_t)(HOWMANY - nbytes), 1)) > 0) {
nbytes += r;
if (r < PIPE_BUF) break;
}