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
   8: static 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 <sys/types.h>
  17: #include <sys/socket.h>
  18: #include <sys/un.h>
  19: #include "lp.local.h"
  20: 
  21: startdaemon(printer)
  22:     char *printer;
  23: {
  24:     struct sockaddr_un sun;
  25:     register int s, n;
  26:     char buf[BUFSIZ];
  27: 
  28:     s = socket(AF_UNIX, SOCK_STREAM, 0);
  29:     if (s < 0) {
  30:         perr("socket");
  31:         return(0);
  32:     }
  33:     sun.sun_family = AF_UNIX;
  34:     strcpy(sun.sun_path, SOCKETNAME);
  35:     if (connect(s, &sun, strlen(sun.sun_path) + 2) < 0) {
  36:         perr("connect");
  37:         (void) close(s);
  38:         return(0);
  39:     }
  40:     (void) sprintf(buf, "\1%s\n", printer);
  41:     n = strlen(buf);
  42:     if (write(s, buf, n) != n) {
  43:         perr("write");
  44:         (void) close(s);
  45:         return(0);
  46:     }
  47:     if (read(s, buf, 1) == 1) {
  48:         if (buf[0] == '\0') {       /* everything is OK */
  49:             (void) close(s);
  50:             return(1);
  51:         }
  52:         putchar(buf[0]);
  53:     }
  54:     while ((n = read(s, buf, sizeof(buf))) > 0)
  55:         fwrite(buf, 1, n, stdout);
  56:     (void) close(s);
  57:     return(0);
  58: }
  59: 
  60: static
  61: perr(msg)
  62:     char *msg;
  63: {
  64:     extern char *name;
  65:     extern int sys_nerr;
  66:     extern char *sys_errlist[];
  67:     extern int errno;
  68: 
  69:     printf("%s: %s: ", name, msg);
  70:     fputs(errno < sys_nerr ? sys_errlist[errno] : "Unknown error" , stdout);
  71:     putchar('\n');
  72: }

Defined functions

perr defined in line 60; used 3 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1985-06-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1057
Valid CSS Valid XHTML 1.0 Strict