Exemplo n.º 1
0
/*
 * Disable queuing.
 */
void
disable_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, lf);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
/*
 * kill an existing daemon and disable printing.
 */
void
abort_q(struct printer *pp)
{
	int killres, setres;
	char lf[MAXPATHLEN];

	lock_file_name(pp, lf, sizeof lf);
	printf("%s:\n", pp->printer);

	/*
	 * Turn on the owner execute bit of the lock file to disable printing.
	 */
	setres = set_qstate(SQS_STOPP, lf);

	/*
	 * If set_qstate found that there already was a lock file, then
	 * call a routine which will read that lock file and kill the
	 * lpd-process which is listed in that lock file.  If the lock
	 * file did not exist, then either there is no daemon running
	 * for this queue, or there is one running but *it* could not
	 * write a lock file (which means we can not determine the
	 * process id of that lpd-process).
	 */
	switch (setres) {
	case SQS_CHGOK:
	case SQS_CHGFAIL:
		/* Kill the process */
		killres = kill_qtask(lf);
		break;
	case SQS_CREOK:
	case SQS_CREFAIL:
		printf("\tno daemon to abort\n");
		break;
	case SQS_STATFAIL:
		printf("\tassuming no daemon to abort\n");
		break;
	default:
		printf("\t<unexpected result (%d) from set_qstate>\n",
		    setres);
		break;
	}

	if (setres >= 0)
		upstat(pp, "printing disabled\n", 0);
}
Exemplo n.º 4
0
/*
 * Processing in common between topq and bottomq commands.
 */
void
tqbq_common(int argc, char *argv[], int origcmd)
{
	struct printer myprinter, *pp;
	struct touchjqe_info touch_info;
	int i, movecnt, setres;

	pp = setup_myprinter(*argv, &myprinter, SUMP_CHDIR_SD);
	if (pp == NULL)
		return;
	--argc;			/* Second argv was the printer name */
	++argv;

	nitems = getq(pp, &queue);
	if (nitems == 0) {
		printf("\tthere are no jobs in the queue\n");
		free_printer(pp);
		return;
	}

	/*
	 * The only real difference between topq and bottomq is the
	 * initial value used for newtime.
	 */
	switch (origcmd) {
	case IS_BOTQ:
		/*
		 * When moving jobs to the bottom of the queue, pick a
		 * starting value which is one second after the last job
		 * in the queue.
		*/
		touch_info.newtime = queue[nitems - 1]->job_time + 1;
		break;
	case IS_TOPQ:
		/*
		 * When moving jobs to the top of the queue, the greatest
		 * number of jobs which could be moved is all the jobs
		 * that are in the queue.  Pick a starting value which
		 * leaves plenty of room for all existing jobs.
		 */
		touch_info.newtime = queue[0]->job_time - nitems - 5;
		break;
	default:
		printf("\ninternal error in topq/bottomq processing.\n");
		return;
	}

	movecnt = process_jobs(argc, argv, touch_jqe, &touch_info);

	/*
	 * If any jobs were moved, then chmod the lock file to notify any
	 * active process for this queue that the queue has changed, so
	 * it will rescan the queue to find out the new job order. 
	 */
	if (movecnt == 0)
		printf("\tqueue order unchanged\n");
	else {
		setres = set_qstate(SQS_QCHANGED, pp->lock_file);
		if (setres < 0)
			printf("\t* queue order changed for %s, but the\n"
			    "\t* attempt to set_qstate() failed [%d]!\n",
			    pp->printer, setres);
	}

	for (i = 0; i < nitems; i++)
		free(queue[i]);
	free(queue);
	free_printer(pp);
}