summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lpr
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
committersjg <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
commit62bb1062226d3ce6a2350808256a25508978352d (patch)
tree22b131dceb13c3df96da594fbaadb693504797c7 /usr.sbin/lpr
parent72ab90509b3a51ab361bf710338f2ef44a4e360d (diff)
parent04932445481c2cb89ff69a83b961bdef3d64757e (diff)
downloadFreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.zip
FreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.tar.gz
Merge from head
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r--usr.sbin/lpr/common_source/common.c20
-rw-r--r--usr.sbin/lpr/common_source/lp.cdefs.h17
2 files changed, 29 insertions, 8 deletions
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c
index 93657d9..52d6c9f 100644
--- a/usr.sbin/lpr/common_source/common.c
+++ b/usr.sbin/lpr/common_source/common.c
@@ -757,16 +757,22 @@ fatal(const struct printer *pp, const char *msg, ...)
/*
* Close all file descriptors from START on up.
- * This is a horrific kluge, since getdtablesize() might return
- * ``infinity'', in which case we will be spending a long time
- * closing ``files'' which were never open. Perhaps it would
- * be better to close the first N fds, for some small value of N.
*/
void
closeallfds(int start)
{
- int stop = getdtablesize();
- for (; start < stop; start++)
- close(start);
+ int stop;
+
+ if (USE_CLOSEFROM) /* The faster, modern solution */
+ closefrom(start);
+ else {
+ /* This older logic can be pretty awful on some OS's. The
+ * getdtablesize() might return ``infinity'', and then this
+ * will waste a lot of time closing file descriptors which
+ * had never been open()-ed. */
+ stop = getdtablesize();
+ for (; start < stop; start++)
+ close(start);
+ }
}
diff --git a/usr.sbin/lpr/common_source/lp.cdefs.h b/usr.sbin/lpr/common_source/lp.cdefs.h
index 19b1331..5806f39 100644
--- a/usr.sbin/lpr/common_source/lp.cdefs.h
+++ b/usr.sbin/lpr/common_source/lp.cdefs.h
@@ -1,6 +1,6 @@
/*-
* ------+---------+---------+---------+---------+---------+---------+---------*
- * Copyright (c) 2003 - Garance Alistair Drosehn <gad@FreeBSD.org>.
+ * Copyright (c) 2003,2013 - Garance Alistair Drosehn <gad@FreeBSD.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,21 @@
#endif
/*
+ * FreeBSD added a closefrom() routine in release 8.0. When compiling
+ * `lpr' on other platforms you might want to include bsd-closefrom.c
+ * from the portable-openssh project.
+ */
+#ifndef USE_CLOSEFROM
+# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# define USE_CLOSEFROM 1
+# endif
+#endif
+/* The macro USE_CLOSEFROM must be defined with a value of 0 or 1. */
+#ifndef USE_CLOSEFROM
+# define USE_CLOSEFROM 0
+#endif
+
+/*
* __unused is a compiler-specific trick which can be used to avoid
* warnings about a variable which is defined but never referenced.
* Some lpr files use this, so define a null version if it was not
OpenPOWER on IntegriCloud