/* Prstop - signal printer daemon to interrupt current print */

#include <stdio.h>

char lock[] =	"/usr/lpd/lock";
char qlock[] =	"/usr/lpd/qlock";

char cant[]	"Can't find printer daemon!\n";

main(argc, argv)
char **argv;
{
	register pid, c;
	register char lockf;

	lockf = lock;
	if (argc > 1) {
		if (**++argv == '-')
			(*argv)++;
		if (**argv == 'q')
			lockf = qlock;
	}
	close(0);
	if (open(lockf, 0) != 0) {
		write(2, cant, sizeof cant);
		exit(1);
	}
	pid = 0;
	while ((c = getchar()) != '\n') {
		pid <<= 3;
		pid  += c-'0';
	}
	if (kill(pid, 5) < 0)
		write(2, cant, sizeof cant);
}
