summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2002-06-16 01:43:29 +0000
committergad <gad@FreeBSD.org>2002-06-16 01:43:29 +0000
commit075d7239bd1571a0a5a991b23f18657c58988ded (patch)
tree3e8b14a1b66555d9cd706bd0e4eb879eabf4e353 /usr.sbin
parent3037932163933f3a6355f087e460bf6f7d5e8acc (diff)
downloadFreeBSD-src-075d7239bd1571a0a5a991b23f18657c58988ded.zip
FreeBSD-src-075d7239bd1571a0a5a991b23f18657c58988ded.tar.gz
Add a nearly complete rewrite of the lpc command 'down'. The only user-
visible change should be that more than one queue can now be specified, if one uses the '-msg' parameter to separate the list of queues from the status message to set. The previous implementation of 'down' remains available as the command 'xdown', available for instant fallback if there seems to be anything wrong with the new one. If no one reports a problem after a few weeks, then a later update will remove 'xdown'. Reviewed by: freebsd-print@bostonradio.org MFC after: 10 days
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/lpr/lpc/cmds.c64
-rw-r--r--usr.sbin/lpr/lpc/cmdtab.c3
-rw-r--r--usr.sbin/lpr/lpc/extern.h4
-rw-r--r--usr.sbin/lpr/lpc/lpc.85
4 files changed, 73 insertions, 3 deletions
diff --git a/usr.sbin/lpr/lpc/cmds.c b/usr.sbin/lpr/lpc/cmds.c
index 62d1b72..d49f9d0 100644
--- a/usr.sbin/lpr/lpc/cmds.c
+++ b/usr.sbin/lpr/lpc/cmds.c
@@ -118,8 +118,16 @@ generic(void (*specificrtn)(struct printer *_pp), int cmdopts,
char **margv, **targv;
if (argc == 1) {
+ /*
+ * Usage needs a special case for 'down': The user must
+ * either include `-msg', or only the first parameter
+ * that they give will be processed as a printer name.
+ */
printf("usage: %s {all | printer ...}", argv[0]);
- if (cmdopts & LPC_MSGOPT)
+ if (strcmp(argv[0], "down") == 0) {
+ printf(" -msg [<text> ...]\n");
+ printf(" or: down {all | printer} [<text> ...]");
+ } else if (cmdopts & LPC_MSGOPT)
printf(" [-msg <text> ...]");
printf("\n");
return;
@@ -1148,6 +1156,60 @@ putmsg(struct printer *pp, int argc, char **argv)
}
/*
+ * Disable queuing and printing and put a message into the status file
+ * (reason for being down). If the user specified `-msg', then use
+ * everything after that as the message for the status file. If the
+ * user did NOT specify `-msg', then the command should take the first
+ * parameter as the printer name, and all remaining parameters as the
+ * message for the status file. (This is to be compatible with the
+ * original definition of 'down', which was implemented long before
+ * `-msg' was around).
+ */
+void
+down_gi(int argc, char *argv[])
+{
+
+ /* If `-msg' was specified, then this routine has nothing to do. */
+ if (generic_msg != NULL)
+ return;
+
+ /*
+ * If the user only gave one parameter, then use a default msg.
+ * (if argc == 1 at this point, then *argv == name of printer).
+ */
+ if (argc == 1) {
+ generic_msg = strdup("printing disabled\n");
+ return;
+ }
+
+ /*
+ * The user specified multiple parameters, and did not specify
+ * `-msg'. Build a message from all the parameters after the
+ * first one (and nullify those parameters so generic-processing
+ * will not process them as printer-queue names).
+ */
+ argc--;
+ argv++;
+ generic_msg = args2line(argc, argv);
+ for (; argc > 0; argc--, argv++)
+ *argv = generic_nullarg; /* "erase" it */
+}
+
+void
+down_q(struct printer *pp)
+{
+ int setres;
+ char lf[MAXPATHLEN];
+
+ lock_file_name(pp, lf, sizeof lf);
+ printf("%s:\n", pp->printer);
+
+ setres = set_qstate(SQS_DISABLEQ+SQS_STOPP, lf);
+ if (setres >= 0)
+ upstat(pp, generic_msg, 1);
+}
+
+/*
* Exit lpc
*/
void
diff --git a/usr.sbin/lpr/lpc/cmdtab.c b/usr.sbin/lpr/lpc/cmdtab.c
index 570c5fb..7664dd53 100644
--- a/usr.sbin/lpr/lpc/cmdtab.c
+++ b/usr.sbin/lpr/lpc/cmdtab.c
@@ -74,7 +74,7 @@ struct cmd cmdtab[] = {
{ "enable", enablehelp, PR, 0, enable_q },
{ "exit", quithelp, 0, quit, 0 },
{ "disable", disablehelp, PR, 0, disable_q },
- { "down", downhelp, PR, down, 0 },
+ { "down", downhelp, PR|M, down_gi, down_q },
{ "help", helphelp, 0, help, 0 },
{ "quit", quithelp, 0, quit, 0 },
{ "restart", restarthelp, 0, 0, restart_q },
@@ -89,6 +89,7 @@ struct cmd cmdtab[] = {
{ "xabort", aborthelp, PR, 0, doabort },
{ "xenable", enablehelp, PR, 0, enable },
{ "xdisable", disablehelp, PR, 0, disable },
+ { "xdown", downhelp, PR, down, 0 },
{ "xrestart", restarthelp, 0, 0, restart },
{ "xstart", starthelp, PR, 0, startcmd },
{ "xstop", stophelp, PR, 0, stop },
diff --git a/usr.sbin/lpr/lpc/extern.h b/usr.sbin/lpr/lpc/extern.h
index 211f115..ac79e31 100644
--- a/usr.sbin/lpr/lpc/extern.h
+++ b/usr.sbin/lpr/lpc/extern.h
@@ -45,7 +45,8 @@ __BEGIN_DECLS
void abort_q(struct printer *_pp);
void clean_q(struct printer *_pp);
void disable_q(struct printer *_pp);
-void down(int _argc, char *_argv[]);
+void down_gi(int _argc, char *_argv[]);
+void down_q(struct printer *_pp);
void enable_q(struct printer *_pp);
void generic(void (*_specificrtn)(struct printer *_pp), int _cmdopts,
void (*_initcmd)(int _argc, char *_argv[]),
@@ -64,6 +65,7 @@ void topq(int _argc, char *_argv[]);
void up_q(struct printer *_pp);
void disable(struct printer *_pp); /* X-version */
void doabort(struct printer *_pp); /* X-version */
+void down(int _argc, char *_argv[]); /* X-version */
void enable(struct printer *_pp); /* X-version */
void restart(struct printer *_pp); /* X-version */
void startcmd(struct printer *_pp); /* X-version */
diff --git a/usr.sbin/lpr/lpc/lpc.8 b/usr.sbin/lpr/lpc/lpc.8
index c35763f..aebbf0e 100644
--- a/usr.sbin/lpr/lpc/lpc.8
+++ b/usr.sbin/lpr/lpc/lpc.8
@@ -112,10 +112,15 @@ This prevents new
printer jobs from being entered into the queue by
.Xr lpr 1 .
.Pp
+.It Ic down Bro Cm all | Ar printer ... Brc Cm -msg Ar message ...
.It Ic down Bro Cm all | Ar printer Brc Ar message ...
Turn the specified printer queue off, disable printing and put
.Ar message
in the printer status file.
+When specifying more than one printer queue, the
+.Ic -msg
+argument is required to separate the list of printers from the text
+that will be the new status message.
The message doesn't need to be quoted, the
remaining arguments are treated like
.Xr echo 1 .
OpenPOWER on IntegriCloud