aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-06-10 13:47:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-06-10 13:47:17 +0200
commit52de9c7141f3dc6dbb801a9d1d1429238917ee4a (patch)
treebd485f06b066b723d4299c129a61211707c75dea
parentcfc212cdfff27c6a7b9d9743f87c4da70f97558c (diff)
downloadbusybox-w32-52de9c7141f3dc6dbb801a9d1d1429238917ee4a.tar.gz
busybox-w32-52de9c7141f3dc6dbb801a9d1d1429238917ee4a.tar.bz2
busybox-w32-52de9c7141f3dc6dbb801a9d1d1429238917ee4a.zip
lpr: don't send 0-byte print jobs (compat)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--printutils/lpr.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/printutils/lpr.c b/printutils/lpr.c
index 748879542..70cda7717 100644
--- a/printutils/lpr.c
+++ b/printutils/lpr.c
@@ -89,6 +89,10 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
89 unsigned opts; 89 unsigned opts;
90 int fd; 90 int fd;
91 91
92 queue = getenv("PRINTER");
93 if (!queue)
94 queue = "lp";
95
92 // parse options 96 // parse options
93 // TODO: set opt_complementary: s,d,f are mutually exclusive 97 // TODO: set opt_complementary: s,d,f are mutually exclusive
94 opts = getopt32(argv, 98 opts = getopt32(argv,
@@ -98,16 +102,7 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
98 ); 102 );
99 argv += optind; 103 argv += optind;
100 104
101 // if queue is not specified -> use $PRINTER 105 {
102 if (!(opts & OPT_P))
103 queue = getenv("PRINTER");
104 // if queue is still not specified ->
105 if (!queue) {
106 // ... queue defaults to "lp"
107 // server defaults to "localhost"
108 queue = "lp";
109 // if queue is specified ->
110 } else {
111 // queue name is to the left of '@' 106 // queue name is to the left of '@'
112 char *s = strchr(queue, '@'); 107 char *s = strchr(queue, '@');
113 if (s) { 108 if (s) {
@@ -186,6 +181,17 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
186 dfd = xopen(*argv, O_RDONLY); 181 dfd = xopen(*argv, O_RDONLY);
187 } 182 }
188 183
184 st.st_size = 0; /* paranoia: fstat may theoretically fail */
185 fstat(dfd, &st);
186
187 /* Apparently, some servers are buggy and won't accept 0-sized jobs.
188 * Standard lpr works around it by refusing to send such jobs:
189 */
190 if (st.st_size == 0) {
191 bb_error_msg("nothing to print");
192 continue;
193 }
194
189 /* "The name ... should start with ASCII "cfA", 195 /* "The name ... should start with ASCII "cfA",
190 * followed by a three digit job number, followed 196 * followed by a three digit job number, followed
191 * by the host name which has constructed the file." 197 * by the host name which has constructed the file."
@@ -210,7 +216,7 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
210 , (opts & LPR_m) ? user : "" 216 , (opts & LPR_m) ? user : ""
211 , remote_filename 217 , remote_filename
212 ); 218 );
213 // delete possible "\nX\n" patterns 219 // delete possible "\nX\n" (that is, one-char) patterns
214 c = controlfile; 220 c = controlfile;
215 while ((c = strchr(c, '\n')) != NULL) { 221 while ((c = strchr(c, '\n')) != NULL) {
216 if (c[1] && c[2] == '\n') { 222 if (c[1] && c[2] == '\n') {
@@ -239,8 +245,6 @@ int lpqr_main(int argc UNUSED_PARAM, char *argv[])
239 // send data file, with name "dfaXXX" 245 // send data file, with name "dfaXXX"
240 if (opts & LPR_V) 246 if (opts & LPR_V)
241 bb_error_msg("sending data file"); 247 bb_error_msg("sending data file");
242 st.st_size = 0; /* paranoia: fstat may theoretically fail */
243 fstat(dfd, &st);
244 fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename); 248 fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename);
245 get_response_or_say_and_die(fd, "sending data file"); 249 get_response_or_say_and_die(fd, "sending data file");
246 if (bb_copyfd_size(dfd, fd, st.st_size) != st.st_size) { 250 if (bb_copyfd_size(dfd, fd, st.st_size) != st.st_size) {