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
This commit is contained in:
Garance A Drosehn 2002-06-16 01:43:29 +00:00
parent e2e0461977
commit 5b1c34fbb7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=98278
4 changed files with 73 additions and 3 deletions

View File

@ -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;
@ -1147,6 +1155,60 @@ putmsg(struct printer *pp, int argc, char **argv)
(void) close(fd);
}
/*
* 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
*/

View File

@ -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 },

View File

@ -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 */

View File

@ -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 .