49ba8eb426bd9a41d7444296c0afa98350abc7d6
static char sccsid
[] = "@(#)cmds.c 4.4 (Berkeley) %G%";
* lpc -- line printer control program
* kill an existing daemon and disable printing.
register char *cp1
, *cp2
;
printf("Usage: abort {all | printer ...}\n");
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
(void) sprintf(line
, "%s/%s", SD
, LO
);
printf("%s:\n", printer
);
* Turn on the owner execute bit of the lock file to disable printing.
if (stat(line
, &stbuf
) >= 0) {
if (chmod(line
, (stbuf
.st_mode
& 0777) | 0100) < 0)
printf("\tcannot disable printing\n");
printf("\tprinting disabled\n");
} else if (errno
== ENOENT
) {
if ((fd
= open(line
, O_WRONLY
|O_CREAT
, 0760)) < 0)
printf("\tcannot create lock file\n");
printf("\tprinting disabled\n");
printf("\tno daemon to abort\n");
printf("\tcannot stat lock file\n");
* Kill the current daemon to stop printing now.
if ((fp
= fopen(line
, "r")) == NULL
) {
printf("\tcannot open lock file\n");
if (!getline(fp
) || flock(fileno(fp
), LOCK_SH
|LOCK_NB
) == 0) {
printf("\tno daemon to abort\n");
if (kill(pid
= atoi(line
), SIGINT
) < 0)
printf("\tWarning: daemon (pid %d) not killed\n", pid
);
printf("\tdaemon (pid %d) killed\n", pid
);
* Remove all spool files and temporaries from the spooling area.
register char *cp1
, *cp2
;
printf("Usage: clean {all | printer ...}\n");
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
register struct direct
*dp
;
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
for (cp
= line
, cp1
= SD
; *cp
++ = *cp1
++; );
printf("%s:\n", printer
);
if ((dirp
= opendir(SD
)) == NULL
) {
printf("\tcannot examine spool directory\n");
while ((dp
= readdir(dirp
)) != NULL
) {
if ((c
== 'c' || c
== 't' || c
== 'd') && dp
->d_name
[1]=='f') {
printf("\tcannot remove %s\n", line
);
printf("\tremoved %s\n", line
);
* Enable queuing to the printer (allow lpr's).
register char *cp1
, *cp2
;
printf("Usage: enable {all | printer ...}\n");
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
(void) sprintf(line
, "%s/%s", SD
, LO
);
printf("%s:\n", printer
);
* Turn off the group execute bit of the lock file to enable queuing.
if (stat(line
, &stbuf
) >= 0) {
if (chmod(line
, stbuf
.st_mode
& 0767) < 0)
printf("\tcannot enable queuing\n");
printf("\tqueuing enabled\n");
register char *cp1
, *cp2
;
printf("Usage: disable {all | printer ...}\n");
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
(void) sprintf(line
, "%s/%s", SD
, LO
);
printf("%s:\n", printer
);
* Turn on the group execute bit of the lock file to disable queuing.
if (stat(line
, &stbuf
) >= 0) {
if (chmod(line
, (stbuf
.st_mode
& 0777) | 010) < 0)
printf("\tcannot disable queuing\n");
printf("\tqueuing disabled\n");
} else if (errno
== ENOENT
) {
if ((fd
= open(line
, O_WRONLY
|O_CREAT
, 0670)) < 0)
printf("\tcannot create lock file\n");
printf("\tqueuing disabled\n");
printf("\tcannot stat lock file\n");
register char *cp1
, *cp2
;
printf("Usage: restart {all | printer ...}\n");
gethostname(host
, sizeof(host
));
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
* Enable printing on the specified printer and startup the daemon.
register char *cp1
, *cp2
;
printf("Usage: start {all | printer ...}\n");
gethostname(host
, sizeof(host
));
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
(void) sprintf(line
, "%s/%s", SD
, LO
);
printf("%s:\n", printer
);
* Turn off the owner execute bit of the lock file to enable printing.
if (enable
&& stat(line
, &stbuf
) >= 0) {
if (chmod(line
, stbuf
.st_mode
& 0677) < 0)
printf("\tcannot enable printing\n");
printf("\tprinting enabled\n");
printf("\tcouldn't start daemon\n");
printf("\tdaemon started\n");
* Print the status of each queue listed or all the queues.
register char *cp1
, *cp2
;
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
* Print the status of the printer queue.
register struct direct
*dp
;
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
if ((ST
= pgetstr("st", &bp
)) == NULL
)
printf("%s:\n", printer
);
(void) sprintf(line
, "%s/%s", SD
, LO
);
if (stat(line
, &stbuf
) >= 0) {
printf("\tqueuing is %s\n",
(stbuf
.st_mode
& 010) ? "disabled" : "enabled");
printf("\tprinting is %s\n",
(stbuf
.st_mode
& 0100) ? "disabled" : "enabled");
printf("\tqueuing is enabled\n");
printf("\tprinting is enabled\n");
if ((dirp
= opendir(SD
)) == NULL
) {
printf("\tcannot examine spool directory\n");
while ((dp
= readdir(dirp
)) != NULL
) {
if (*dp
->d_name
== 'c' && dp
->d_name
[1] == 'f')
printf("\tno entries\n");
printf("\t1 entry in spool area\n");
printf("\t%d entries in spool area\n", i
);
fd
= open(line
, O_RDONLY
);
if (fd
< 0 || flock(fd
, LOCK_SH
|LOCK_NB
) == 0) {
printf("\tno daemon present\n");
(void) sprintf(line
, "%s/%s", SD
, ST
);
fd
= open(line
, O_RDONLY
);
(void) flock(fd
, LOCK_SH
);
while ((i
= read(fd
, line
, sizeof(line
))) > 0)
(void) fwrite(line
, 1, i
, stdout
);
* Stop the specified daemon after completing the current job and disable
register char *cp1
, *cp2
;
printf("Usage: stop {all | printer ...}\n");
if (argc
== 2 && !strcmp(argv
[1], "all")) {
while (getprent(line
) > 0) {
while ((c
= *cp2
++) && c
!= '|' && c
!= ':')
if ((status
= pgetent(line
, printer
)) < 0) {
printf("cannot open printer description file\n");
} else if (status
== 0) {
printf("unknown printer %s\n", printer
);
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
(void) sprintf(line
, "%s/%s", SD
, LO
);
printf("%s:\n", printer
);
* Turn on the owner execute bit of the lock file to disable printing.
if (stat(line
, &stbuf
) >= 0) {
if (chmod(line
, (stbuf
.st_mode
& 0777) | 0100) < 0)
printf("\tcannot disable printing\n");
printf("\tprinting disabled\n");
} else if (errno
== ENOENT
) {
if ((fd
= open(line
, O_WRONLY
|O_CREAT
, 0760)) < 0)
printf("\tcannot create lock file\n");
printf("\tprinting disabled\n");
printf("\tcannot stat lock file\n");