source: trunk/athena/bin/lpr/startdaemon.c @ 6362

Revision 6362, 1.6 KB checked in by probe, 32 years ago (diff)
Renamed variable "sun" (Sun port)
Line 
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.  The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8static char sccsid[] = "@(#)startdaemon.c       5.1 (Berkeley) 6/6/85";
9#endif not lint
10
11/*
12 * Tell the printer daemon that there are new files in the spool directory.
13 */
14
15#include <stdio.h>
16#include <syslog.h>
17#include <sys/types.h>
18#include <sys/socket.h>
19#include <sys/un.h>
20#include "lp.local.h"
21
22startdaemon(printer)
23        char *printer;
24{
25        struct sockaddr_un sockun;
26        register int s, n;
27        char buf[BUFSIZ];
28
29        syslog(LOG_DEBUG, "Attempting to restart printer %s", printer);
30        s = socket(AF_UNIX, SOCK_STREAM, 0);
31        if (s < 0) {
32                perr("socket");
33                return(0);
34        }
35        sockun.sun_family = AF_UNIX;
36        strcpy(sockun.sun_path, SOCKETNAME);
37        if (connect(s, &sockun, strlen(sockun.sun_path) + 2) < 0) {
38                perr("connect");
39                (void) close(s);
40                return(0);
41        }
42        (void) sprintf(buf, "\1%s\n", printer);
43        n = strlen(buf);
44        if (write(s, buf, n) != n) {
45                perr("write");
46                (void) close(s);
47                return(0);
48        }
49        if (read(s, buf, 1) == 1) {
50                if (buf[0] == '\0') {           /* everything is OK */
51                        (void) close(s);
52                        return(1);
53                }
54                putchar(buf[0]);
55        }
56        while ((n = read(s, buf, sizeof(buf))) > 0)
57                fwrite(buf, 1, n, stdout);
58        (void) close(s);
59        return(0);
60}
61
62static
63perr(msg)
64        char *msg;
65{
66        extern char *name;
67        extern int sys_nerr;
68        extern char *sys_errlist[];
69        extern int errno;
70
71        syslog(LOG_DEBUG, "%s: %s: %m", name, msg);
72        printf("%s: %s: ", name, msg);
73        fputs(errno < sys_nerr ? sys_errlist[errno] : "Unknown error" , stdout);
74        putchar('\n');
75}
Note: See TracBrowser for help on using the repository browser.