2008-02-23 03:54:48 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2008-02-25 00:14:20 +05:30
|
|
|
* bare bones version of lpr & lpq: BSD printing utilities
|
2008-02-23 03:54:48 +05:30
|
|
|
*
|
2008-02-25 00:14:20 +05:30
|
|
|
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
|
|
|
|
*
|
|
|
|
* Original idea and code:
|
|
|
|
* Walter Harms <WHarms@bfs.de>
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
2008-02-25 00:14:20 +05:30
|
|
|
*
|
2008-02-25 03:38:57 +05:30
|
|
|
* See RFC 1179 for protocol description.
|
2008-02-23 03:54:48 +05:30
|
|
|
*/
|
2015-10-19 04:15:46 +05:30
|
|
|
//config:config LPR
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "lpr (9.9 kb)"
|
2015-10-19 04:15:46 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: lpr sends files (or standard input) to a print spooling daemon.
|
2015-10-19 04:15:46 +05:30
|
|
|
//config:
|
|
|
|
//config:config LPQ
|
2018-12-28 07:50:17 +05:30
|
|
|
//config: bool "lpq (9.9 kb)"
|
2015-10-19 04:15:46 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: lpq is a print spool queue examination and manipulation program.
|
2015-10-19 04:15:46 +05:30
|
|
|
|
2017-01-29 19:27:33 +05:30
|
|
|
// APPLET_ODDNAME:name main location suid_type help
|
2015-10-19 04:15:46 +05:30
|
|
|
//applet:IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq))
|
|
|
|
//applet:IF_LPR(APPLET_ODDNAME(lpr, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpr))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_LPR) += lpr.o
|
|
|
|
//kbuild:lib-$(CONFIG_LPQ) += lpr.o
|
2011-04-11 06:59:49 +05:30
|
|
|
|
|
|
|
//usage:#define lpr_trivial_usage
|
|
|
|
//usage: "-P queue[@host[:port]] -U USERNAME -J TITLE -Vmh [FILE]..."
|
|
|
|
/* -C CLASS exists too, not shown.
|
|
|
|
* CLASS is supposed to be printed on banner page, if one is requested */
|
|
|
|
//usage:#define lpr_full_usage "\n\n"
|
2011-06-05 07:28:28 +05:30
|
|
|
//usage: " -P lp service to connect to (else uses $PRINTER)"
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage: "\n -m Send mail on completion"
|
|
|
|
//usage: "\n -h Print banner page too"
|
|
|
|
//usage: "\n -V Verbose"
|
|
|
|
//usage:
|
|
|
|
//usage:#define lpq_trivial_usage
|
|
|
|
//usage: "[-P queue[@host[:port]]] [-U USERNAME] [-d JOBID]... [-fs]"
|
|
|
|
//usage:#define lpq_full_usage "\n\n"
|
2011-06-05 07:28:28 +05:30
|
|
|
//usage: " -P lp service to connect to (else uses $PRINTER)"
|
2011-04-11 06:59:49 +05:30
|
|
|
//usage: "\n -d Delete jobs"
|
|
|
|
//usage: "\n -f Force any waiting job to be printed"
|
|
|
|
//usage: "\n -s Short display"
|
|
|
|
|
2008-02-23 03:54:48 +05:30
|
|
|
#include "libbb.h"
|
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
/*
|
|
|
|
* LPD returns binary 0 on success.
|
|
|
|
* Otherwise it returns error message.
|
2008-02-23 03:54:48 +05:30
|
|
|
*/
|
2008-02-27 20:05:21 +05:30
|
|
|
static void get_response_or_say_and_die(int fd, const char *errmsg)
|
2008-02-23 03:54:48 +05:30
|
|
|
{
|
2008-02-26 02:00:24 +05:30
|
|
|
ssize_t sz;
|
|
|
|
char buf[128];
|
2008-02-25 00:14:20 +05:30
|
|
|
|
2008-02-26 02:00:24 +05:30
|
|
|
buf[0] = ' ';
|
2008-02-27 20:05:21 +05:30
|
|
|
sz = safe_read(fd, buf, 1);
|
2008-02-26 02:00:24 +05:30
|
|
|
if ('\0' != buf[0]) {
|
2008-02-25 00:14:20 +05:30
|
|
|
// request has failed
|
2008-02-26 02:00:24 +05:30
|
|
|
// try to make sure last char is '\n', but do not add
|
|
|
|
// superfluous one
|
2008-02-27 20:05:21 +05:30
|
|
|
sz = full_read(fd, buf + 1, 126);
|
2008-02-26 02:00:24 +05:30
|
|
|
bb_error_msg("error while %s%s", errmsg,
|
|
|
|
(sz > 0 ? ". Server said:" : ""));
|
|
|
|
if (sz > 0) {
|
|
|
|
// sz = (bytes in buf) - 1
|
|
|
|
if (buf[sz] != '\n')
|
|
|
|
buf[++sz] = '\n';
|
|
|
|
safe_write(STDERR_FILENO, buf, sz + 1);
|
|
|
|
}
|
2008-02-23 03:54:48 +05:30
|
|
|
xfunc_die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
int lpqr_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int lpqr_main(int argc UNUSED_PARAM, char *argv[])
|
2008-02-23 03:54:48 +05:30
|
|
|
{
|
|
|
|
enum {
|
2008-02-25 00:14:20 +05:30
|
|
|
OPT_P = 1 << 0, // -P queue[@host[:port]]. If no -P is given use $PRINTER, then "lp@localhost:515"
|
|
|
|
OPT_U = 1 << 1, // -U username
|
|
|
|
|
|
|
|
LPR_V = 1 << 2, // -V: be verbose
|
2008-03-24 07:35:58 +05:30
|
|
|
LPR_h = 1 << 3, // -h: want banner printed
|
2008-02-25 00:14:20 +05:30
|
|
|
LPR_C = 1 << 4, // -C class: job "class" (? supposedly printed on banner)
|
|
|
|
LPR_J = 1 << 5, // -J title: the job title for the banner page
|
|
|
|
LPR_m = 1 << 6, // -m: send mail back to user
|
|
|
|
|
|
|
|
LPQ_SHORT_FMT = 1 << 2, // -s: short listing format
|
|
|
|
LPQ_DELETE = 1 << 3, // -d: delete job(s)
|
|
|
|
LPQ_FORCE = 1 << 4, // -f: force waiting job(s) to be printed
|
2008-02-23 03:54:48 +05:30
|
|
|
};
|
2008-02-25 00:14:20 +05:30
|
|
|
char tempfile[sizeof("/tmp/lprXXXXXX")];
|
|
|
|
const char *job_title;
|
|
|
|
const char *printer_class = ""; // printer class, max 32 char
|
|
|
|
const char *queue; // name of printer queue
|
|
|
|
const char *server = "localhost"; // server[:port] of printer queue
|
|
|
|
char *hostname;
|
|
|
|
// N.B. IMHO getenv("USER") can be way easily spoofed!
|
2008-12-03 04:26:59 +05:30
|
|
|
const char *user = xuid2uname(getuid());
|
2008-02-25 00:14:20 +05:30
|
|
|
unsigned job;
|
|
|
|
unsigned opts;
|
2008-02-27 20:05:21 +05:30
|
|
|
int fd;
|
2008-02-25 00:14:20 +05:30
|
|
|
|
2012-06-10 17:17:17 +05:30
|
|
|
queue = getenv("PRINTER");
|
|
|
|
if (!queue)
|
|
|
|
queue = "lp";
|
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
// parse options
|
|
|
|
// TODO: set opt_complementary: s,d,f are mutually exclusive
|
|
|
|
opts = getopt32(argv,
|
|
|
|
(/*lp*/'r' == applet_name[2]) ? "P:U:VhC:J:m" : "P:U:sdf"
|
|
|
|
, &queue, &user
|
|
|
|
, &printer_class, &job_title
|
|
|
|
);
|
2008-02-23 03:54:48 +05:30
|
|
|
argv += optind;
|
2008-02-25 00:14:20 +05:30
|
|
|
|
2012-06-10 17:17:17 +05:30
|
|
|
{
|
2008-02-25 00:14:20 +05:30
|
|
|
// queue name is to the left of '@'
|
|
|
|
char *s = strchr(queue, '@');
|
|
|
|
if (s) {
|
|
|
|
// server name is to the right of '@'
|
|
|
|
*s = '\0';
|
|
|
|
server = s + 1;
|
|
|
|
}
|
2008-02-23 03:54:48 +05:30
|
|
|
}
|
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
// do connect
|
|
|
|
fd = create_and_connect_stream_or_die(server, 515);
|
|
|
|
|
|
|
|
//
|
|
|
|
// LPQ ------------------------
|
|
|
|
//
|
|
|
|
if (/*lp*/'q' == applet_name[2]) {
|
|
|
|
char cmd;
|
|
|
|
// force printing of every job still in queue
|
|
|
|
if (opts & LPQ_FORCE) {
|
|
|
|
cmd = 1;
|
|
|
|
goto command;
|
|
|
|
// delete job(s)
|
|
|
|
} else if (opts & LPQ_DELETE) {
|
2008-02-27 20:05:21 +05:30
|
|
|
fdprintf(fd, "\x5" "%s %s", queue, user);
|
2008-02-25 00:14:20 +05:30
|
|
|
while (*argv) {
|
2008-02-27 20:05:21 +05:30
|
|
|
fdprintf(fd, " %s", *argv++);
|
2008-02-25 00:14:20 +05:30
|
|
|
}
|
|
|
|
bb_putchar('\n');
|
|
|
|
// dump current jobs status
|
|
|
|
// N.B. periodical polling should be achieved
|
|
|
|
// via "watch -n delay lpq"
|
|
|
|
// They say it's the UNIX-way :)
|
|
|
|
} else {
|
|
|
|
cmd = (opts & LPQ_SHORT_FMT) ? 3 : 4;
|
|
|
|
command:
|
2008-02-27 20:05:21 +05:30
|
|
|
fdprintf(fd, "%c" "%s\n", cmd, queue);
|
|
|
|
bb_copyfd_eof(fd, STDOUT_FILENO);
|
2008-02-25 00:14:20 +05:30
|
|
|
}
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
//
|
|
|
|
// LPR ------------------------
|
|
|
|
//
|
|
|
|
if (opts & LPR_V)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("connected to server");
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
job = getpid() % 1000;
|
2008-02-27 20:05:21 +05:30
|
|
|
hostname = safe_gethostname();
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
// no files given on command line? -> use stdin
|
|
|
|
if (!*argv)
|
|
|
|
*--argv = (char *)"-";
|
|
|
|
|
2008-02-27 20:05:21 +05:30
|
|
|
fdprintf(fd, "\x2" "%s\n", queue);
|
|
|
|
get_response_or_say_and_die(fd, "setting queue");
|
2008-02-25 00:14:20 +05:30
|
|
|
|
|
|
|
// process files
|
|
|
|
do {
|
2008-07-23 00:45:30 +05:30
|
|
|
unsigned cflen;
|
2008-02-27 20:05:21 +05:30
|
|
|
int dfd;
|
2008-02-25 00:14:20 +05:30
|
|
|
struct stat st;
|
|
|
|
char *c;
|
|
|
|
char *remote_filename;
|
|
|
|
char *controlfile;
|
|
|
|
|
|
|
|
// if data file is stdin, we need to dump it first
|
|
|
|
if (LONE_DASH(*argv)) {
|
|
|
|
strcpy(tempfile, "/tmp/lprXXXXXX");
|
2010-10-22 16:57:16 +05:30
|
|
|
dfd = xmkstemp(tempfile);
|
2008-02-27 20:05:21 +05:30
|
|
|
bb_copyfd_eof(STDIN_FILENO, dfd);
|
|
|
|
xlseek(dfd, 0, SEEK_SET);
|
2008-02-25 00:14:20 +05:30
|
|
|
*argv = (char*)bb_msg_standard_input;
|
|
|
|
} else {
|
2008-02-27 20:05:21 +05:30
|
|
|
dfd = xopen(*argv, O_RDONLY);
|
2008-02-23 03:54:48 +05:30
|
|
|
}
|
2008-02-25 00:14:20 +05:30
|
|
|
|
2012-06-10 17:17:17 +05:30
|
|
|
st.st_size = 0; /* paranoia: fstat may theoretically fail */
|
|
|
|
fstat(dfd, &st);
|
|
|
|
|
|
|
|
/* Apparently, some servers are buggy and won't accept 0-sized jobs.
|
|
|
|
* Standard lpr works around it by refusing to send such jobs:
|
|
|
|
*/
|
|
|
|
if (st.st_size == 0) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("nothing to print");
|
2012-06-10 17:17:17 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
/* "The name ... should start with ASCII "cfA",
|
|
|
|
* followed by a three digit job number, followed
|
|
|
|
* by the host name which has constructed the file."
|
|
|
|
* We supply 'c' or 'd' as needed for control/data file. */
|
|
|
|
remote_filename = xasprintf("fA%03u%s", job, hostname);
|
|
|
|
|
|
|
|
// create control file
|
|
|
|
// TODO: all lines but 2 last are constants! How we can use this fact?
|
|
|
|
controlfile = xasprintf(
|
|
|
|
"H" "%.32s\n" "P" "%.32s\n" /* H HOST, P USER */
|
|
|
|
"C" "%.32s\n" /* C CLASS - printed on banner page (if L cmd is also given) */
|
|
|
|
"J" "%.99s\n" /* J JOBNAME */
|
|
|
|
/* "class name for banner page and job name
|
|
|
|
* for banner page commands must precede L command" */
|
|
|
|
"L" "%.32s\n" /* L USER - print banner page, with given user's name */
|
|
|
|
"M" "%.32s\n" /* M WHOM_TO_MAIL */
|
|
|
|
"l" "d%.31s\n" /* l DATA_FILE_NAME ("dfAxxx") */
|
|
|
|
, hostname, user
|
|
|
|
, printer_class /* can be "" */
|
|
|
|
, ((opts & LPR_J) ? job_title : *argv)
|
|
|
|
, (opts & LPR_h) ? user : ""
|
|
|
|
, (opts & LPR_m) ? user : ""
|
|
|
|
, remote_filename
|
|
|
|
);
|
2012-06-10 17:17:17 +05:30
|
|
|
// delete possible "\nX\n" (that is, one-char) patterns
|
2008-02-25 05:02:36 +05:30
|
|
|
c = controlfile;
|
|
|
|
while ((c = strchr(c, '\n')) != NULL) {
|
2008-07-23 00:45:30 +05:30
|
|
|
if (c[1] && c[2] == '\n') {
|
2012-04-27 18:33:34 +05:30
|
|
|
overlapping_strcpy(c, c+2);
|
2008-07-23 00:45:30 +05:30
|
|
|
} else {
|
|
|
|
c++;
|
|
|
|
}
|
2008-02-25 05:02:36 +05:30
|
|
|
}
|
2008-02-25 00:14:20 +05:30
|
|
|
|
|
|
|
// send control file
|
|
|
|
if (opts & LPR_V)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("sending control file");
|
2008-07-23 00:45:30 +05:30
|
|
|
/* "Acknowledgement processing must occur as usual
|
|
|
|
* after the command is sent." */
|
2012-04-27 18:33:34 +05:30
|
|
|
cflen = (unsigned)strlen(controlfile);
|
2008-07-23 00:45:30 +05:30
|
|
|
fdprintf(fd, "\x2" "%u c%s\n", cflen, remote_filename);
|
|
|
|
get_response_or_say_and_die(fd, "sending control file");
|
2008-02-23 03:54:48 +05:30
|
|
|
/* "Once all of the contents have
|
|
|
|
* been delivered, an octet of zero bits is sent as
|
|
|
|
* an indication that the file being sent is complete.
|
|
|
|
* A second level of acknowledgement processing
|
|
|
|
* must occur at this point." */
|
2008-07-23 00:45:30 +05:30
|
|
|
full_write(fd, controlfile, cflen + 1); /* writes NUL byte too */
|
2008-02-27 20:05:21 +05:30
|
|
|
get_response_or_say_and_die(fd, "sending control file");
|
2008-02-25 00:14:20 +05:30
|
|
|
|
|
|
|
// send data file, with name "dfaXXX"
|
|
|
|
if (opts & LPR_V)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("sending data file");
|
2008-02-27 20:05:21 +05:30
|
|
|
fdprintf(fd, "\x3" "%"OFF_FMT"u d%s\n", st.st_size, remote_filename);
|
2008-07-23 00:45:30 +05:30
|
|
|
get_response_or_say_and_die(fd, "sending data file");
|
2008-02-27 20:05:21 +05:30
|
|
|
if (bb_copyfd_size(dfd, fd, st.st_size) != st.st_size) {
|
2008-02-25 00:14:20 +05:30
|
|
|
// We're screwed. We sent less bytes than we advertised.
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("local file changed size?!");
|
2008-02-25 00:14:20 +05:30
|
|
|
}
|
2008-02-27 20:05:21 +05:30
|
|
|
write(fd, "", 1); // send ACK
|
|
|
|
get_response_or_say_and_die(fd, "sending data file");
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
// delete temporary file if we dumped stdin
|
|
|
|
if (*argv == (char*)bb_msg_standard_input)
|
|
|
|
unlink(tempfile);
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
// cleanup
|
|
|
|
close(fd);
|
|
|
|
free(remote_filename);
|
|
|
|
free(controlfile);
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-27 20:05:21 +05:30
|
|
|
// say job accepted
|
|
|
|
if (opts & LPR_V)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("job accepted");
|
2008-02-27 20:05:21 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
// next, please!
|
|
|
|
job = (job + 1) % 1000;
|
|
|
|
} while (*++argv);
|
2008-02-23 03:54:48 +05:30
|
|
|
|
2008-02-25 00:14:20 +05:30
|
|
|
return EXIT_SUCCESS;
|
2008-02-23 03:54:48 +05:30
|
|
|
}
|