Example #1
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);
}
Example #2
0
static void
stoppr(void)
{
	int fd;
	struct stat stbuf;

	if (cgetstr(bp, "sd", &SD) == -1)
		SD = _PATH_DEFSPOOL;
	if (cgetstr(bp, "lo", &LO) == -1)
		LO = DEFLOCK;
	(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
	printf("%s:\n", printer);

	/*
	 * Turn on the owner execute bit of the lock file to disable printing.
	 */
	PRIV_START;
	if (stat(line, &stbuf) >= 0) {
		stbuf.st_mode |= S_IXUSR;
		if (chmod(line, stbuf.st_mode & 0777) < 0)
			printf("\tcannot disable printing\n");
		else {
			upstat("printing disabled\n");
			printf("\tprinting disabled\n");
		}
	} else if (errno == ENOENT) {
		if ((fd = safe_open(line, O_WRONLY|O_CREAT|O_NOFOLLOW, 0760)) < 0)
			printf("\tcannot create lock file\n");
		else {
			(void)fchown(fd, DEFUID, -1);
			(void)close(fd);
			upstat("printing disabled\n");
			printf("\tprinting disabled\n");
		}
	} else
		printf("\tcannot stat lock file\n");
	PRIV_END;
}
Example #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);
}
Example #4
0
static void
abortpr(int dis)
{
	FILE *fp;
	struct stat stbuf;
	int pid, fd;

	if (cgetstr(bp, "sd", &SD) == -1)
		SD = _PATH_DEFSPOOL;
	if (cgetstr(bp, "lo", &LO) == -1)
		LO = DEFLOCK;
	(void)snprintf(line, sizeof(line), "%s/%s", SD, LO);
	printf("%s:\n", printer);

	PRIV_START;
	/*
	 * Turn on the owner execute bit of the lock file to disable printing.
	 */
	if (dis) {
		if (stat(line, &stbuf) >= 0) {
			stbuf.st_mode |= S_IXUSR;
			if (chmod(line, stbuf.st_mode & 0777) < 0)
				printf("\tcannot disable printing\n");
			else {
				upstat("printing disabled\n");
				printf("\tprinting disabled\n");
			}
		} else if (errno == ENOENT) {
			if ((fd = safe_open(line, O_WRONLY|O_CREAT|O_NOFOLLOW,
			    0760)) < 0)
				printf("\tcannot create lock file\n");
			else {
				(void)fchown(fd, DEFUID, -1);
				(void)close(fd);
				upstat("printing disabled\n");
				printf("\tprinting disabled\n");
				printf("\tno daemon to abort\n");
			}
			goto out;
		} else {
			printf("\tcannot stat lock file\n");
			goto out;
		}
	}
	/*
	 * Kill the current daemon to stop printing now.
	 */
	fd = safe_open(line, O_RDONLY|O_NOFOLLOW, 0);
	if (fd < 0 || (fp = fdopen(fd, "r")) == NULL) {
		if (fd >= 0)
			close(fd);
		printf("\tcannot open lock file\n");
		goto out;
	}
	if (!get_line(fp) || flock(fileno(fp), LOCK_SH|LOCK_NB) == 0) {
		(void)fclose(fp);	/* unlocks as well */
		printf("\tno daemon to abort\n");
		goto out;
	}
	(void)fclose(fp);
	if (kill(pid = atoi(line), SIGTERM) < 0) {
		if (errno == ESRCH)
			printf("\tno daemon to abort\n");
		else
			printf("\tWarning: daemon (pid %d) not killed\n", pid);
	} else
		printf("\tdaemon (pid %d) killed\n", pid);
out:
	PRIV_END;
}