commit fab97782ee64666612c06e19e09d6ee3f8f462e4
parent 5d83f81723bd0765756aeb7d1fb203ac3199a0d2
Author: Kyle Milz <krwmilz@gmail.com>
Date: Sat, 11 Sep 2021 20:41:09 +0000
remove n_files_left file counting code
Remove the neat feature of recovering from file descriptor exhaustion.
In reality I don't think we need this for any modern system. The default
limit was set at 32767, which is a lot of files.
Diffstat:
12 files changed, 49 insertions(+), 153 deletions(-)
diff --git a/data.h b/data.h
@@ -23,4 +23,20 @@ struct bitmap {
char *bits; /* pointer to the bits */
};
+/*
+ * AVL tree structures.
+ */
+
+#define AVL_COMMON \
+ const char *key; /* key */ \
+ int key_len; /* length of key */ \
+ int bal; /* AVL balancing information */ \
+ struct avl *left; \
+ struct avl *right
+
+struct avl { /* generic data structure */
+ AVL_COMMON;
+};
+
+
#endif
diff --git a/dvi-init.c b/dvi-init.c
@@ -616,10 +616,8 @@ read_postamble()
fp2->next_size = fontp->next_size;
}
}
- if (fontp->file != NULL) {
- Fclose(fontp->file);
- ++n_files_left;
- }
+ if (fontp->file != NULL)
+ fclose(fontp->file);
if (fontp->filename != NULL)
free((void *) fontp->filename);
@@ -741,7 +739,7 @@ internal_init_dvi()
process_preamble();
find_postamble();
if (!read_postamble()) {
- Fclose(dvi_file);
+ fclose(dvi_file);
dvi_file = NULL;
return False;
}
diff --git a/events.c b/events.c
@@ -47,7 +47,7 @@ NOTE:
#include "http.h"
#include "popups.h" /* WARN, Act_print() */
#include "special.h" /* page_colors */
-#include "util.h" /* prep_fd() */
+#include "util.h" /* xmalloc() */
#include "xdvi.h"
diff --git a/filefind.c b/filefind.c
@@ -1047,7 +1047,6 @@ init_quick_find(root, pos, atom, pos1)
retval = lsrgetline(f, pos1);
if (retval == 0) {
fclose(f);
- ++n_files_left;
return; /* premature end of file */
}
} while (ffline[pos1] == '%');
@@ -1161,7 +1160,6 @@ init_quick_find(root, pos, atom, pos1)
}
fclose(f); /* close the file */
- ++n_files_left;
/* Fill in the requisite entries in *root: we have ls-R. */
root->fullpat = fullpat;
@@ -1410,7 +1408,6 @@ filltree(pos, treepp, atom, slashslash)
treepp = &leaf->next;
}
closedir(f);
- ++n_files_left;
*treepp = NULL;
}
diff --git a/font-open.c b/font-open.c
@@ -387,8 +387,7 @@ getdefaults(f)
}
}
- Fclose(f);
- ++n_files_left;
+ fclose(f);
}
@@ -1124,8 +1123,7 @@ process_gs_fontmap(FILE *f)
}
}
- Fclose(f);
- ++n_files_left;
+ fclose(f);
}
/*
@@ -1180,8 +1178,7 @@ pre_lookup_t1_font(fontname)
if (p_head != NULL)
for (;;) {
if (!fgets_long(mapfile)) { /* if end of file */
- Fclose(mapfile);
- ++n_files_left;
+ fclose(mapfile);
for (;;) {
p_head = p_head->next;
if (p_head == NULL)
@@ -1412,8 +1409,7 @@ read_encoding(encp)
warnx("invalid format in encoding file '%s'; giving up.",
encp->key);
- Fclose(f);
- ++n_files_left;
+ fclose(f);
}
diff --git a/font.h b/font.h
@@ -153,21 +153,6 @@ struct tn *tn_head = NULL;
unsigned char maxchar;
unsigned short current_timestamp = 0;
-/*
- * AVL tree structures.
- */
-
-#define AVL_COMMON \
- const char *key; /* key */ \
- int key_len; /* length of key */ \
- int bal; /* AVL balancing information */ \
- struct avl *left; \
- struct avl *right
-
-struct avl { /* generic data structure */
- AVL_COMMON;
-};
-
/* Data structure for Type 1 fonts -- contents of psfonts.map */
struct avl_t1 {
AVL_COMMON;
diff --git a/ft.c b/ft.c
@@ -322,8 +322,7 @@ load_ft_font(fontp)
warnx("Turning off use of FreeType.");
warnx("Please see the FreeType documentation for details about this.");
free((char *) path);
- Fclose(f);
- ++n_files_left;
+ fclose(f);
return False;
}
}
@@ -348,8 +347,7 @@ load_ft_font(fontp)
warnx("Will try pixel version instead.");
warnx("Please see the FreeType documentation for details about this.");
free((char *) path);
- Fclose(f);
- ++n_files_left;
+ fclose(f);
fontp2->file = NULL;
fontp2->filename = NULL;
return False;
@@ -360,8 +358,7 @@ load_ft_font(fontp)
warnx("Font '%s' is not scalable.", fontp->fontname);
FT_Done_Face(face);
free((char *) path);
- Fclose(f);
- ++n_files_left;
+ fclose(f);
fontp2->file = NULL;
fontp2->filename = NULL;
return False;
@@ -372,8 +369,7 @@ load_ft_font(fontp)
if (!set_transform(ftp, t1p->addinfo)) {
FT_Done_Face(face);
free((char *) path);
- Fclose(f);
- ++n_files_left;
+ fclose(f);
fontp2->file = NULL;
fontp2->filename = NULL;
return False;
diff --git a/popups.c b/popups.c
@@ -1384,10 +1384,8 @@ print_do_it()
free(argv[0]);
free(argv);
- if (pr_save_fileradio == &r1radio2) {
+ if (pr_save_fileradio == &r1radio2)
fclose(f);
- ++n_files_left;
- }
if (print_child.pid == -1) { /* error */
perror("[xdvi] vfork");
@@ -1398,7 +1396,6 @@ print_do_it()
dvips_sig = SIGINT;
(void) close(print_io[1]);
- ++n_files_left;
/* Set up file descriptor for non-blocking I/O */
prep_fd(print_io[0], True);
@@ -1478,7 +1475,6 @@ dvips_ended(status)
read_from_dvips();
clear_io(&print_xio);
(void) close(print_xio.fd);
- ++n_files_left;
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0) {
diff --git a/util.c b/util.c
@@ -29,15 +29,14 @@ NOTE:
#include <sys/file.h> /* this defines FASYNC */
#include <sys/ioctl.h> /* this defines SIOCSPGRP and FIOASYNC */
-#include <ctype.h> /* needed for memicmp() */
+#include <ctype.h> /* tolower() */
#include <err.h>
-#include <errno.h>
+#include <stdlib.h> /* malloc(), realloc() */
#include <string.h> /* strdup(), memcpy() */
#include <strings.h> /* bcopy() */
-#include <pwd.h>
-#include <unistd.h>
+#include <pwd.h> /* getpwuid(), getpwnam() */
+#include <unistd.h> /* getuid(), getpid() */
-#include "font.h" /* struct font */
#include "xdvi.h"
#include "util.h"
@@ -177,91 +176,27 @@ memicmp(s1, s2, n)
}
-/*
- * Close the pixel file for the least recently used font.
- */
-
-static void
-close_a_file()
-{
- struct font *fontp;
- unsigned short oldest = ~0;
- struct font *f = NULL;
-
- if (debug & DBG_OPEN)
- puts("Calling close_a_file()");
-
- for (fontp = font_head; fontp != NULL; fontp = fontp->next)
- if (fontp->file != NULL && fontp->timestamp <= oldest) {
- f = fontp;
- oldest = fontp->timestamp;
- }
- if (f == NULL)
- errx(1, "Can't find an open pixel file to close");
- Fclose(f->file);
- f->file = NULL;
- ++n_files_left;
-}
-
/*
* Open a file in the given mode.
*/
FILE *
-xfopen(filename, type)
- const char *filename;
- const char *type;
+xfopen(const char *filename, const char *type)
{
FILE *f;
- if (n_files_left == 0) close_a_file();
f = fopen(filename, type);
- if (f == NULL && (errno == EMFILE || errno == ENFILE))
- {
- n_files_left = 0;
- close_a_file();
- f = fopen(filename, type);
- }
- if (f != NULL) {
- --n_files_left;
-#ifdef F_SETFD
- (void) fcntl(fileno(f), F_SETFD, 1);
-#endif
- }
- return f;
-}
-
-
-
-/*
- * Plain ordinary open() system call. Don't adjust n_files_left.
- */
-
-int
-xopen(path, flags)
- const char *path;
- int flags;
-{
- int fd;
-
- if (n_files_left == 0)
- close_a_file();
- fd = open(path, flags);
- if (fd == -1 && (errno == EMFILE || errno == ENFILE)) {
- n_files_left = 0;
- close_a_file();
- fd = open(path, flags);
- }
+ if (f != NULL)
+ (void) fcntl(fileno(f), F_SETFD, 1);
- return fd;
+ return f;
}
-
/*
- * Create a pipe, closing a file if necessary.
+ * Create a pipe.
* We use socketpair() instead of pipe() because several operating
* systems don't support SIGPOLL/SIGIO on pipes:
* SGI IRIX 6.5 F_SETOWN not implemented
@@ -269,45 +204,28 @@ xopen(path, flags)
*/
int
-xpipe(fd)
- int *fd;
+xpipe(int *fd)
{
int retval;
- while (n_files_left < 2) close_a_file();
- for (;;) {
- retval = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
- if (retval == 0) {
- n_files_left -= 2;
- break;
- }
- if ((errno != EMFILE && errno != ENFILE))
- break;
- n_files_left = 0;
- close_a_file();
- }
+ retval = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
+
return retval;
}
/*
- * Open a directory for reading, opening a file if necessary.
+ * Open a directory for reading
*/
DIR *
-xopendir(name)
- const char *name;
+xopendir(const char *name)
{
DIR *retval;
- if (n_files_left == 0) close_a_file();
- for (;;) {
- retval = opendir(name);
- if (retval == NULL || (errno != EMFILE && errno != ENFILE)) break;
- n_files_left = 0;
- close_a_file();
- }
- if (retval != NULL) --n_files_left;
+ if ((retval = opendir(name)) == NULL)
+ err(1, "opendir");
+
return retval;
}
@@ -357,8 +275,6 @@ ff_getpw(pp, p_end)
*/
if (count >= 2 && len != 0 && getpwuid(getuid()) != NULL)
return NULL;
-
- close_a_file();
}
}
diff --git a/util.h b/util.h
@@ -1,5 +1,5 @@
-#include <dirent.h>
-#include <stdio.h>
+#include <dirent.h> /* DIR */
+#include <stdio.h> /* FILE */
#include "data.h" /* struct bitmap */
@@ -15,7 +15,6 @@ int memicmp(const char *, const char *, size_t);
void prep_fd(int, Boolean);
FILE *xfopen(const char *, const char *);
-int xopen(const char *, int);
DIR *xopendir(const char *);
int xpipe(int *);
void xputenv(const char *, const char *);
diff --git a/vf.c b/vf.c
@@ -146,7 +146,6 @@ read_VF_index(struct font *fontp, Boolean hushcs)
if (cmnd != POST)
errx(1, "Wrong command byte found in VF macro list: %d", cmnd);
- Fclose(VF_file);
+ fclose(VF_file);
fontp->file = NULL;
- ++n_files_left;
}
diff --git a/xdvi.h b/xdvi.h
@@ -58,7 +58,6 @@ NOTE:
#define Fputs (void) fputs
#define Putc (void) putc
#define Putchar (void) putchar
-#define Fclose (void) fclose
#define Fflush (void) fflush
#define Strcpy (void) strcpy
@@ -91,7 +90,6 @@ int pageno_correct = 1;
long magnification;
double dimconv;
double tpic_conv;
-int n_files_left = 32767; /* for LRU closing of fonts */
unsigned int page_w, page_h;
int scanned_page; /* last page prescanned */