Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 3 | * bare bones version of lpr & lpq: BSD printing utilities |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 4 | * |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com> |
| 6 | * |
| 7 | * Original idea and code: |
| 8 | * Walter Harms <WHarms@bfs.de> |
| 9 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 10 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 11 | * |
Denis Vlasenko | 6d8112c | 2008-02-24 22:08:57 +0000 | [diff] [blame] | 12 | * See RFC 1179 for protocol description. |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 13 | */ |
Denys Vlasenko | 854bb68 | 2015-10-19 00:45:46 +0200 | [diff] [blame] | 14 | //config:config LPR |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 15 | //config: bool "lpr (9.9 kb)" |
Denys Vlasenko | 854bb68 | 2015-10-19 00:45:46 +0200 | [diff] [blame] | 16 | //config: default y |
| 17 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 18 | //config: lpr sends files (or standard input) to a print spooling daemon. |
Denys Vlasenko | 854bb68 | 2015-10-19 00:45:46 +0200 | [diff] [blame] | 19 | //config: |
| 20 | //config:config LPQ |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 21 | //config: bool "lpq (9.9 kb)" |
Denys Vlasenko | 854bb68 | 2015-10-19 00:45:46 +0200 | [diff] [blame] | 22 | //config: default y |
| 23 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 24 | //config: lpq is a print spool queue examination and manipulation program. |
Denys Vlasenko | 854bb68 | 2015-10-19 00:45:46 +0200 | [diff] [blame] | 25 | |
Denys Vlasenko | 205d48e | 2017-01-29 14:57:33 +0100 | [diff] [blame] | 26 | // APPLET_ODDNAME:name main location suid_type help |
Denys Vlasenko | 854bb68 | 2015-10-19 00:45:46 +0200 | [diff] [blame] | 27 | //applet:IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq)) |
| 28 | //applet:IF_LPR(APPLET_ODDNAME(lpr, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpr)) |
| 29 | |
| 30 | //kbuild:lib-$(CONFIG_LPR) += lpr.o |
| 31 | //kbuild:lib-$(CONFIG_LPQ) += lpr.o |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 32 | |
| 33 | //usage:#define lpr_trivial_usage |
| 34 | //usage: "-P queue[@host[:port]] -U USERNAME -J TITLE -Vmh [FILE]..." |
| 35 | /* -C CLASS exists too, not shown. |
| 36 | * CLASS is supposed to be printed on banner page, if one is requested */ |
| 37 | //usage:#define lpr_full_usage "\n\n" |
Denys Vlasenko | 6642676 | 2011-06-05 03:58:28 +0200 | [diff] [blame] | 38 | //usage: " -P lp service to connect to (else uses $PRINTER)" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 39 | //usage: "\n -m Send mail on completion" |
| 40 | //usage: "\n -h Print banner page too" |
| 41 | //usage: "\n -V Verbose" |
| 42 | //usage: |
| 43 | //usage:#define lpq_trivial_usage |
| 44 | //usage: "[-P queue[@host[:port]]] [-U USERNAME] [-d JOBID]... [-fs]" |
| 45 | //usage:#define lpq_full_usage "\n\n" |
Denys Vlasenko | 6642676 | 2011-06-05 03:58:28 +0200 | [diff] [blame] | 46 | //usage: " -P lp service to connect to (else uses $PRINTER)" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 47 | //usage: "\n -d Delete jobs" |
| 48 | //usage: "\n -f Force any waiting job to be printed" |
| 49 | //usage: "\n -s Short display" |
| 50 | |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 51 | #include "libbb.h" |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 52 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 53 | /* |
| 54 | * LPD returns binary 0 on success. |
| 55 | * Otherwise it returns error message. |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 56 | */ |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 57 | static void get_response_or_say_and_die(int fd, const char *errmsg) |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 58 | { |
Denis Vlasenko | 394eebe | 2008-02-25 20:30:24 +0000 | [diff] [blame] | 59 | ssize_t sz; |
| 60 | char buf[128]; |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 61 | |
Denis Vlasenko | 394eebe | 2008-02-25 20:30:24 +0000 | [diff] [blame] | 62 | buf[0] = ' '; |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 63 | sz = safe_read(fd, buf, 1); |
Denis Vlasenko | 394eebe | 2008-02-25 20:30:24 +0000 | [diff] [blame] | 64 | if ('\0' != buf[0]) { |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 65 | // request has failed |
Denis Vlasenko | 394eebe | 2008-02-25 20:30:24 +0000 | [diff] [blame] | 66 | // try to make sure last char is '\n', but do not add |
| 67 | // superfluous one |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 68 | sz = full_read(fd, buf + 1, 126); |
Denis Vlasenko | 394eebe | 2008-02-25 20:30:24 +0000 | [diff] [blame] | 69 | bb_error_msg("error while %s%s", errmsg, |
| 70 | (sz > 0 ? ". Server said:" : "")); |
| 71 | if (sz > 0) { |
| 72 | // sz = (bytes in buf) - 1 |
| 73 | if (buf[sz] != '\n') |
| 74 | buf[++sz] = '\n'; |
| 75 | safe_write(STDERR_FILENO, buf, sz + 1); |
| 76 | } |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 77 | xfunc_die(); |
| 78 | } |
| 79 | } |
| 80 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 81 | int lpqr_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 82 | int lpqr_main(int argc UNUSED_PARAM, char *argv[]) |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 83 | { |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 84 | enum { |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 85 | OPT_P = 1 << 0, // -P queue[@host[:port]]. If no -P is given use $PRINTER, then "lp@localhost:515" |
| 86 | OPT_U = 1 << 1, // -U username |
| 87 | |
| 88 | LPR_V = 1 << 2, // -V: be verbose |
Denis Vlasenko | 42cc304 | 2008-03-24 02:05:58 +0000 | [diff] [blame] | 89 | LPR_h = 1 << 3, // -h: want banner printed |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 90 | LPR_C = 1 << 4, // -C class: job "class" (? supposedly printed on banner) |
| 91 | LPR_J = 1 << 5, // -J title: the job title for the banner page |
| 92 | LPR_m = 1 << 6, // -m: send mail back to user |
| 93 | |
| 94 | LPQ_SHORT_FMT = 1 << 2, // -s: short listing format |
| 95 | LPQ_DELETE = 1 << 3, // -d: delete job(s) |
| 96 | LPQ_FORCE = 1 << 4, // -f: force waiting job(s) to be printed |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 97 | }; |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 98 | char tempfile[sizeof("/tmp/lprXXXXXX")]; |
| 99 | const char *job_title; |
| 100 | const char *printer_class = ""; // printer class, max 32 char |
| 101 | const char *queue; // name of printer queue |
| 102 | const char *server = "localhost"; // server[:port] of printer queue |
| 103 | char *hostname; |
| 104 | // N.B. IMHO getenv("USER") can be way easily spoofed! |
Denis Vlasenko | 0c68a87 | 2008-12-02 22:56:59 +0000 | [diff] [blame] | 105 | const char *user = xuid2uname(getuid()); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 106 | unsigned job; |
| 107 | unsigned opts; |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 108 | int fd; |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 109 | |
Denys Vlasenko | 52de9c7 | 2012-06-10 13:47:17 +0200 | [diff] [blame] | 110 | queue = getenv("PRINTER"); |
| 111 | if (!queue) |
| 112 | queue = "lp"; |
| 113 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 114 | // parse options |
| 115 | // TODO: set opt_complementary: s,d,f are mutually exclusive |
| 116 | opts = getopt32(argv, |
| 117 | (/*lp*/'r' == applet_name[2]) ? "P:U:VhC:J:m" : "P:U:sdf" |
| 118 | , &queue, &user |
| 119 | , &printer_class, &job_title |
| 120 | ); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 121 | argv += optind; |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 122 | |
Denys Vlasenko | 52de9c7 | 2012-06-10 13:47:17 +0200 | [diff] [blame] | 123 | { |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 124 | // queue name is to the left of '@' |
| 125 | char *s = strchr(queue, '@'); |
| 126 | if (s) { |
| 127 | // server name is to the right of '@' |
| 128 | *s = '\0'; |
| 129 | server = s + 1; |
| 130 | } |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 133 | // do connect |
| 134 | fd = create_and_connect_stream_or_die(server, 515); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 135 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 136 | // |
| 137 | // LPQ ------------------------ |
| 138 | // |
| 139 | if (/*lp*/'q' == applet_name[2]) { |
| 140 | char cmd; |
| 141 | // force printing of every job still in queue |
| 142 | if (opts & LPQ_FORCE) { |
| 143 | cmd = 1; |
| 144 | goto command; |
| 145 | // delete job(s) |
| 146 | } else if (opts & LPQ_DELETE) { |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 147 | fdprintf(fd, "\x5" "%s %s", queue, user); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 148 | while (*argv) { |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 149 | fdprintf(fd, " %s", *argv++); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 150 | } |
| 151 | bb_putchar('\n'); |
| 152 | // dump current jobs status |
| 153 | // N.B. periodical polling should be achieved |
| 154 | // via "watch -n delay lpq" |
| 155 | // They say it's the UNIX-way :) |
| 156 | } else { |
| 157 | cmd = (opts & LPQ_SHORT_FMT) ? 3 : 4; |
| 158 | command: |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 159 | fdprintf(fd, "%c" "%s\n", cmd, queue); |
| 160 | bb_copyfd_eof(fd, STDOUT_FILENO); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 161 | } |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 162 | |
| 163 | return EXIT_SUCCESS; |
| 164 | } |
| 165 | |
| 166 | // |
| 167 | // LPR ------------------------ |
| 168 | // |
| 169 | if (opts & LPR_V) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 170 | bb_simple_error_msg("connected to server"); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 171 | |
| 172 | job = getpid() % 1000; |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 173 | hostname = safe_gethostname(); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 174 | |
| 175 | // no files given on command line? -> use stdin |
| 176 | if (!*argv) |
| 177 | *--argv = (char *)"-"; |
| 178 | |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 179 | fdprintf(fd, "\x2" "%s\n", queue); |
| 180 | get_response_or_say_and_die(fd, "setting queue"); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 181 | |
| 182 | // process files |
| 183 | do { |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 184 | unsigned cflen; |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 185 | int dfd; |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 186 | struct stat st; |
| 187 | char *c; |
| 188 | char *remote_filename; |
| 189 | char *controlfile; |
| 190 | |
| 191 | // if data file is stdin, we need to dump it first |
| 192 | if (LONE_DASH(*argv)) { |
| 193 | strcpy(tempfile, "/tmp/lprXXXXXX"); |
Alexander Shishkin | 6722737 | 2010-10-22 13:27:16 +0200 | [diff] [blame] | 194 | dfd = xmkstemp(tempfile); |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 195 | bb_copyfd_eof(STDIN_FILENO, dfd); |
| 196 | xlseek(dfd, 0, SEEK_SET); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 197 | *argv = (char*)bb_msg_standard_input; |
| 198 | } else { |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 199 | dfd = xopen(*argv, O_RDONLY); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Denys Vlasenko | 52de9c7 | 2012-06-10 13:47:17 +0200 | [diff] [blame] | 202 | st.st_size = 0; /* paranoia: fstat may theoretically fail */ |
| 203 | fstat(dfd, &st); |
| 204 | |
| 205 | /* Apparently, some servers are buggy and won't accept 0-sized jobs. |
| 206 | * Standard lpr works around it by refusing to send such jobs: |
| 207 | */ |
| 208 | if (st.st_size == 0) { |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 209 | bb_simple_error_msg("nothing to print"); |
Denys Vlasenko | 52de9c7 | 2012-06-10 13:47:17 +0200 | [diff] [blame] | 210 | continue; |
| 211 | } |
| 212 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 213 | /* "The name ... should start with ASCII "cfA", |
| 214 | * followed by a three digit job number, followed |
| 215 | * by the host name which has constructed the file." |
| 216 | * We supply 'c' or 'd' as needed for control/data file. */ |
| 217 | remote_filename = xasprintf("fA%03u%s", job, hostname); |
| 218 | |
| 219 | // create control file |
| 220 | // TODO: all lines but 2 last are constants! How we can use this fact? |
| 221 | controlfile = xasprintf( |
| 222 | "H" "%.32s\n" "P" "%.32s\n" /* H HOST, P USER */ |
| 223 | "C" "%.32s\n" /* C CLASS - printed on banner page (if L cmd is also given) */ |
| 224 | "J" "%.99s\n" /* J JOBNAME */ |
| 225 | /* "class name for banner page and job name |
| 226 | * for banner page commands must precede L command" */ |
| 227 | "L" "%.32s\n" /* L USER - print banner page, with given user's name */ |
| 228 | "M" "%.32s\n" /* M WHOM_TO_MAIL */ |
| 229 | "l" "d%.31s\n" /* l DATA_FILE_NAME ("dfAxxx") */ |
| 230 | , hostname, user |
| 231 | , printer_class /* can be "" */ |
| 232 | , ((opts & LPR_J) ? job_title : *argv) |
| 233 | , (opts & LPR_h) ? user : "" |
| 234 | , (opts & LPR_m) ? user : "" |
| 235 | , remote_filename |
| 236 | ); |
Denys Vlasenko | 52de9c7 | 2012-06-10 13:47:17 +0200 | [diff] [blame] | 237 | // delete possible "\nX\n" (that is, one-char) patterns |
Denis Vlasenko | f99afb5 | 2008-02-24 23:32:36 +0000 | [diff] [blame] | 238 | c = controlfile; |
| 239 | while ((c = strchr(c, '\n')) != NULL) { |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 240 | if (c[1] && c[2] == '\n') { |
Denys Vlasenko | 0c62f20 | 2012-04-27 15:03:34 +0200 | [diff] [blame] | 241 | overlapping_strcpy(c, c+2); |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 242 | } else { |
| 243 | c++; |
| 244 | } |
Denis Vlasenko | f99afb5 | 2008-02-24 23:32:36 +0000 | [diff] [blame] | 245 | } |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 246 | |
| 247 | // send control file |
| 248 | if (opts & LPR_V) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 249 | bb_simple_error_msg("sending control file"); |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 250 | /* "Acknowledgement processing must occur as usual |
| 251 | * after the command is sent." */ |
Denys Vlasenko | 0c62f20 | 2012-04-27 15:03:34 +0200 | [diff] [blame] | 252 | cflen = (unsigned)strlen(controlfile); |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 253 | fdprintf(fd, "\x2" "%u c%s\n", cflen, remote_filename); |
| 254 | get_response_or_say_and_die(fd, "sending control file"); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 255 | /* "Once all of the contents have |
| 256 | * been delivered, an octet of zero bits is sent as |
| 257 | * an indication that the file being sent is complete. |
| 258 | * A second level of acknowledgement processing |
| 259 | * must occur at this point." */ |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 260 | full_write(fd, controlfile, cflen + 1); /* writes NUL byte too */ |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 261 | get_response_or_say_and_die(fd, "sending control file"); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 262 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 263 | // send data file, with name "dfaXXX" |
| 264 | if (opts & LPR_V) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 265 | bb_simple_error_msg("sending data file"); |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 266 | fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename); |
Denis Vlasenko | c445758 | 2008-07-22 19:15:30 +0000 | [diff] [blame] | 267 | get_response_or_say_and_die(fd, "sending data file"); |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 268 | if (bb_copyfd_size(dfd, fd, st.st_size) != st.st_size) { |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 269 | // We're screwed. We sent less bytes than we advertised. |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 270 | bb_simple_error_msg_and_die("local file changed size?!"); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 271 | } |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 272 | write(fd, "", 1); // send ACK |
| 273 | get_response_or_say_and_die(fd, "sending data file"); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 274 | |
| 275 | // delete temporary file if we dumped stdin |
| 276 | if (*argv == (char*)bb_msg_standard_input) |
| 277 | unlink(tempfile); |
| 278 | |
| 279 | // cleanup |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 280 | close(fd); |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 281 | free(remote_filename); |
| 282 | free(controlfile); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 283 | |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 284 | // say job accepted |
| 285 | if (opts & LPR_V) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 286 | bb_simple_error_msg("job accepted"); |
Denis Vlasenko | fe66a0e | 2008-02-27 14:35:21 +0000 | [diff] [blame] | 287 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 288 | // next, please! |
| 289 | job = (job + 1) % 1000; |
| 290 | } while (*++argv); |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 291 | |
Denis Vlasenko | 4f82bdb | 2008-02-24 18:44:20 +0000 | [diff] [blame] | 292 | return EXIT_SUCCESS; |
Denis Vlasenko | 68444b9 | 2008-02-22 22:24:48 +0000 | [diff] [blame] | 293 | } |