home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / plp / part09 < prev    next >
Text File  |  1988-09-14  |  43KB  |  1,207 lines

  1. Subject:  v16i022:  Public lineprinter spooler package, Part09/16
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: papowell@julius.cs.umn.edu
  7. Posting-number: Volume 16, Issue 22
  8. Archive-name: plp/part09
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 9 (of 16)."
  17. # Contents:  src/Makefile src/global.c src/lockfile.c
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'src/Makefile' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'src/Makefile'\"
  21. else
  22. echo shar: Extracting \"'src/Makefile'\" \(12955 characters\)
  23. sed "s/^X//" >'src/Makefile' <<'END_OF_FILE'
  24. X#***************************************************************************
  25. X#* U. Minnesota LPD Software * Copyright 1987, 1988, Patrick Powell
  26. X#***************************************************************************
  27. X#* MODULE: Makefile
  28. X#***************************************************************************
  29. X#* Revision History:  Recreated
  30. X#* Sun Jan  3 07:27:44 CST 1988: V1
  31. X#***************************************************************************
  32. X#$Log:    Makefile,v $
  33. X# Revision 3.2  88/06/24  17:58:54  papowell
  34. X# MODS for VAX 4.3BSD UNIX
  35. X# 
  36. X# Revision 3.1  88/06/18  09:33:48  papowell
  37. X# Version 3.0- Distributed Sat Jun 18 1988
  38. X# 
  39. X# Revision 3.0  88/06/18  09:29:46  papowell
  40. X# Version 3.0- Distributed Sat Jun 18 1988
  41. X# 
  42. X# Revision 2.3  88/05/16  12:09:58  papowell
  43. X# Added a "test" entry to make XPERIMENT version
  44. X# 
  45. X# Revision 2.2  88/05/11  09:53:19  papowell
  46. X# Modified installation targets to be compatible with Berkeley LPR
  47. X# 
  48. X# Revision 2.1  88/05/09  10:07:22  papowell
  49. X# PLP: Released Version
  50. X# 
  51. X# Revision 1.10  88/04/29  07:44:51  papowell
  52. X# Added USE_LOCKF for alternative form of locking
  53. X# 
  54. X# Revision 1.9  88/04/28  17:30:23  papowell
  55. X# Fixed installation
  56. X# 
  57. X#
  58. X# This makefile will generate and install the PLP software.
  59. X# You should create a "bin" directory,  and copy this Makefile to the bin
  60. X# directory.  All binaries and executables will be created in the bin directory.
  61. X#
  62. X# The PLP stuff runs SUID ROOT.
  63. X#
  64. X# There are various compilation options;  see the following for details.
  65. X#
  66. X# Note that this Makefile does NOT create spool directories;
  67. X# you have to do that yourself, whenever a new entry is added to /etc/printcap
  68. X# See the "checkpc" program for help.
  69. X#
  70. X.SUFFIXES:
  71. X
  72. X# commands made by this script
  73. COMMANDS= lpd lpr lpq lprm lpc pac checkpc
  74. X
  75. X# where daemons are installed: lpd
  76. X#LIB=/usr/lib/
  77. X#LIB=/usr/local/new/lib
  78. LIB=/usr/lib/
  79. X
  80. X# where user commands are installed: lpr, lpq, lprm, lpc
  81. X#BIN=/usr/local/new/bin/
  82. BIN=/usr/ucb/
  83. X
  84. X# where maintenance commands are installed: pac, checkpc
  85. X#MAINTDIR=/etc/
  86. MAINTDIR=$(BIN)
  87. X
  88. X# source directory, holds all source
  89. SRC=../src
  90. X
  91. X# lint directory, where the output of the various lintings will go
  92. LNT=../lint
  93. X
  94. X#**************** OPTIONS *******************************
  95. X# The following flags are used to control compile time dependent options
  96. X
  97. X# MACHINE - IS_SUN, IS_VAX, IS_UMAX (ENCORE NS32000)
  98. X# Oh, this is sick.  You should check the lp.h file for dependencies
  99. X# These are explained below. Most are "ifndef" or "ifdef" in a very few files.
  100. X# Some systems do not have certain data types available,  so that you have to
  101. X# define some types.  See "lp.h" for the set of definitions and some options
  102. X# that have been hardwired there for ease of installation.
  103. X  MACHINE = -DIS_SUN=1
  104. X# MACHINE = -DIS_VAX4BSD=1
  105. X# MACHINE = -DIS_DATAGEN=1
  106. X# MACHINE = -DIS_UMAX=1
  107. X# MACHINE = -DIS_APOLLO=1
  108. X
  109. X
  110. X# XPERIMENT: Generation a version that can be used to experiment
  111. X# DEBUG: Generate a version that has -X option enabled
  112. X#   The XPERIMENT option specifies -X option always to be used
  113. X XPERIMENT=-DXPERIMENT=1
  114. X#DEBUG=-DDEBUG=1
  115. X
  116. X# SYSLOG: syslog(8) is a 4BSD logging facility.
  117. X# If you do not have syslog, define NOSYSLOG and error messages will
  118. X# be printed to /dev/console.  See syslogmsg.c for details.
  119. X# The <syslog.h> include file contains a set of definitions for values
  120. X# to be used by the SYSLOG software.  Different systems have different
  121. X# error values, which means that the values are compile time dependent.
  122. X# This  is usually set in lp.h based on "IS_??"
  123. X#NOSYSLOG=-DNOSYSLOG=1
  124. X
  125. X# SYMLINK: If you do not have symbolic links, you cannot use them.
  126. X# This  is usually set in lp.h based on "IS_??"
  127. X#NOSYMLINK=-DNOSYMLINK=1
  128. X
  129. X# ETCPC:  printcap file; default is /etc/printcap
  130. X# ETCPERMS:  printer permissions file; default is /etc/printer_perms
  131. X# Modify the following.
  132. X#ETCPC=-DETCPC='"/usr/etc/printcap"'
  133. X#ETCPERMS=-DETCPERMS='"/usr/etc/printer_perms"'
  134. X
  135. X# NO_LOCKF: some systems do not have lockf() which is used to lock files;
  136. X# The alternative is to use flock().  If you do not have either,  modify
  137. X# the do_lock() procedure in lockfile.c to provide locking, although this has
  138. X# proven to be fairly unsucessful in the past.
  139. X# NOTE: lockf is essential to use in an NFS environment
  140. X#NO_LOCKF=-DNO_LOCKF=1
  141. X
  142. X# Define TERMCAP and TERMLIB if curses is to be used by lpq
  143. TERMCAP=-DTERMCAP=1
  144. TERMLIB=-lcurses -ltermcap
  145. X
  146. XFLAGS= -I. -I${SRC} ${DEBUG} ${XPERIMENT} ${MACHINE} \
  147. X    ${NOSYMLINK} ${ETCPC} ${ETCPERMS} ${TERMCAP} ${USE_LOCKF}
  148. X#CFLAGS= -O ${FLAGS}
  149. CFLAGS= -g ${FLAGS}
  150. LINTFLAGS= -huv ${FLAGS}
  151. LINTFILTER = \
  152. X    | sed -e '/warning: struct.union iovec never defined/d' -e '/:$$/d' \
  153. X        -e '/warning: possible pointer alignment problem/d'
  154. X
  155. COMPILE= ${CC} -c ${CFLAGS}
  156. CXREF=/usr/ucb/ctags -x
  157. PRINT=cpr -r
  158. X
  159. all:    ${COMMANDS}
  160. X
  161. X#
  162. X# Binary : Object    dependencies
  163. X# LPD
  164. DEPlpd =  \
  165. X    banner.o checkperm.o control_ops.o displayq.o errormsg.o getopt.o global.o \
  166. X    link_support.o localprinter.o lockfile.o lpd.o mexecv.o print_support.o \
  167. X    printcap.o recvfiles.o remote_ops.o remoteprinter.o rmjob.o sendmail.o \
  168. X    servicereq.o setstatus.o setup_filter.o setup_test.o startserver.o \
  169. X    startprinter.o utils.o find_name.o
  170. SRClpd =  \
  171. X    ${SRC}/banner.c ${SRC}/checkperm.c ${SRC}/control_ops.c ${SRC}/displayq.c \
  172. X    ${SRC}/errormsg.c ${SRC}/getopt.c ${SRC}/global.c ${SRC}/link_support.c \
  173. X    ${SRC}/localprinter.c ${SRC}/lockfile.c ${SRC}/lpd.c ${SRC}/mexecv.c \
  174. X    ${SRC}/print_support.c ${SRC}/printcap.c ${SRC}/recvfiles.c \
  175. X    ${SRC}/remote_ops.c ${SRC}/remoteprinter.c ${SRC}/rmjob.c \
  176. X    ${SRC}/sendmail.c ${SRC}/servicereq.c ${SRC}/setstatus.c \
  177. X    ${SRC}/setup_filter.c ${SRC}/setup_test.c ${SRC}/startserver.c \
  178. X    ${SRC}/startprinter.c ${SRC}/utils.c ${SRC}/find_name.c
  179. lpd: $(DEPlpd)
  180. X    ${CC}  ${CFLAGS}  -o lpd $(DEPlpd)
  181. DEPlpr =  \
  182. X    checkperm.o errormsg.o getopt.o global.o lockfile.o lpr.o lpr_canprint.o \
  183. X    lpr_filters.o lpr_global.o lpr_job.o lpr_parms.o lpr_temp.o mexecv.o \
  184. X    printcap.o setup_filter.o setup_test.o startserver.o utils.o getprinter.o \
  185. X    remote_ops.o link_support.o
  186. SRClpr =  \
  187. X    ${SRC}/checkperm.c ${SRC}/errormsg.c ${SRC}/getopt.c ${SRC}/global.c \
  188. X    ${SRC}/lockfile.c ${SRC}/lpr.c ${SRC}/lpr_canprint.c ${SRC}/lpr_filters.c \
  189. X    ${SRC}/lpr_global.c ${SRC}/lpr_job.c ${SRC}/lpr_parms.c ${SRC}/lpr_temp.c \
  190. X    ${SRC}/mexecv.c ${SRC}/printcap.c ${SRC}/setup_filter.c \
  191. X    ${SRC}/setup_test.c ${SRC}/startserver.c ${SRC}/utils.c \
  192. X    ${SRC}/getprinter.c ${SRC}/remote_ops.c ${SRC}/link_support.c
  193. lpr: $(DEPlpr)
  194. X    ${CC}  ${CFLAGS}  -o lpr $(DEPlpr)
  195. DEPlpq =  \
  196. X    lpq.o getprinter.o global.o displayq.o utils.o setup_test.o \
  197. X    lockfile.o errormsg.o printcap.o remote_ops.o link_support.o \
  198. X    termclear.o getopt.o
  199. SRClpq =  \
  200. X    ${SRC}/lpq.c ${SRC}/getprinter.c ${SRC}/global.c ${SRC}/displayq.c \
  201. X    ${SRC}/utils.c ${SRC}/setup_test.c ${SRC}/lockfile.c ${SRC}/errormsg.c \
  202. X    ${SRC}/printcap.c ${SRC}/remote_ops.c ${SRC}/link_support.c \
  203. X    ${SRC}/termclear.c ${SRC}/getopt.c 
  204. lpq: $(DEPlpq)
  205. X    ${CC}  ${CFLAGS}  -o lpq $(DEPlpq) ${TERMLIB}
  206. DEPlpc =  \
  207. X    checkperm.o control_ops.o errormsg.o getopt.o getprinter.o global.o \
  208. X    lockfile.o lpc.o printcap.o setup_test.o startserver.o utils.o \
  209. X    remote_ops.o link_support.o
  210. SRClpc =  \
  211. X    ${SRC}/checkperm.c ${SRC}/control_ops.c ${SRC}/errormsg.c \
  212. X    ${SRC}/getopt.c ${SRC}/getprinter.c ${SRC}/global.c \
  213. X    ${SRC}/lockfile.c ${SRC}/lpc.c ${SRC}/printcap.c ${SRC}/setup_test.c \
  214. X    ${SRC}/startserver.c ${SRC}/utils.c ${SRC}/remote_ops.c \
  215. X    ${SRC}/link_support.c
  216. lpc: $(DEPlpc)
  217. X    ${CC}  ${CFLAGS}  -o lpc $(DEPlpc)
  218. DEPlprm =  \
  219. X    checkperm.o errormsg.o getopt.o getprinter.o global.o link_support.o \
  220. X    lockfile.o lprm.o printcap.o remote_ops.o rmjob.o setup_test.o \
  221. X    startserver.o utils.o
  222. SRClprm =  \
  223. X    ${SRC}/checkperm.c ${SRC}/errormsg.c ${SRC}/getopt.c ${SRC}/getprinter.c \
  224. X    ${SRC}/global.c ${SRC}/link_support.c ${SRC}/lockfile.c ${SRC}/lprm.c \
  225. X    ${SRC}/printcap.c ${SRC}/remote_ops.c ${SRC}/rmjob.c ${SRC}/setup_test.c \
  226. X    ${SRC}/startserver.c ${SRC}/utils.c
  227. lprm: $(DEPlprm)
  228. X    ${CC}  ${CFLAGS}  -o lprm $(DEPlprm)
  229. DEPcheckpc= \
  230. X    checkpc.o global.o printcap.o errormsg.o setup_test.o utils.o \
  231. X    lockfile.o getopt.o
  232. SRCcheckpc= \
  233. X    ${SRC}/checkpc.c ${SRC}/global.c ${SRC}/printcap.c ${SRC}/errormsg.c \
  234. X    ${SRC}/setup_test.c ${SRC}/utils.c ${SRC}/lockfile.c ${SRC}/getopt.c
  235. checkpc: $(DEPcheckpc)
  236. X    ${CC}  ${CFLAGS}  -o checkpc $(DEPcheckpc)
  237. DEPpac= \
  238. X    pac.o global.o printcap.o errormsg.o setup_test.o \
  239. X    getopt.o getprinter.o utils.o lockfile.o
  240. SRCpac= \
  241. X    ${SRC}/pac.c ${SRC}/global.c ${SRC}/printcap.c ${SRC}/errormsg.c  \
  242. X    ${SRC}/setup_test.c ${SRC}/getopt.c ${SRC}/getprinter.c ${SRC}/utils.c \
  243. X    ${SRC}/lockfile.c
  244. pac: $(DEPpac)
  245. X    ${CC}  ${CFLAGS}  -o pac $(DEPpac)
  246. X#
  247. X# Object - Source  dependencies
  248. X#
  249. banner.o:    $(SRC)/banner.c
  250. X    ${COMPILE} ${SRC}/banner.c
  251. checkpc.o:    $(SRC)/checkpc.c
  252. X    ${COMPILE} ${SRC}/checkpc.c
  253. checkperm.o:    $(SRC)/checkperm.c
  254. X    ${COMPILE} ${SRC}/checkperm.c
  255. control_ops.o:    $(SRC)/control_ops.c
  256. X    ${COMPILE} ${SRC}/control_ops.c
  257. displayq.o:    $(SRC)/displayq.c
  258. X    ${COMPILE} ${SRC}/displayq.c
  259. errormsg.o:    $(SRC)/errormsg.c
  260. X    ${COMPILE} ${SRC}/errormsg.c
  261. find_name.o:    $(SRC)/find_name.c
  262. X    ${COMPILE} ${SRC}/find_name.c
  263. getprinter.o:    $(SRC)/getprinter.c
  264. X    ${COMPILE} ${SRC}/getprinter.c
  265. getopt.o:    $(SRC)/getopt.c
  266. X    ${COMPILE} ${SRC}/getopt.c
  267. global.o:    $(SRC)/global.c
  268. X    ${COMPILE} ${SRC}/global.c
  269. link_support.o:    $(SRC)/link_support.c
  270. X    ${COMPILE} ${SRC}/link_support.c
  271. localprinter.o:    $(SRC)/localprinter.c
  272. X    ${COMPILE} ${SRC}/localprinter.c
  273. lockfile.o:    $(SRC)/lockfile.c
  274. X    ${COMPILE} ${SRC}/lockfile.c
  275. lpc.o:    $(SRC)/lpc.c
  276. X    ${COMPILE} ${SRC}/lpc.c
  277. lpd.o:    $(SRC)/lpd.c
  278. X    ${COMPILE} ${SRC}/lpd.c
  279. lpr.o:    $(SRC)/lpr.c
  280. X    ${COMPILE} ${SRC}/lpr.c
  281. lprm.o:    $(SRC)/lprm.c
  282. X    ${COMPILE} ${SRC}/lprm.c
  283. lpq.o:    $(SRC)/lpq.c
  284. X    ${COMPILE} ${SRC}/lpq.c
  285. lpr_canprint.o:    $(SRC)/lpr_canprint.c
  286. X    ${COMPILE} ${SRC}/lpr_canprint.c
  287. lpr_filters.o:    $(SRC)/lpr_filters.c
  288. X    ${COMPILE} ${SRC}/lpr_filters.c
  289. lpr_global.o:    $(SRC)/lpr_global.c
  290. X    ${COMPILE} ${SRC}/lpr_global.c
  291. lpr_job.o:    $(SRC)/lpr_job.c
  292. X    ${COMPILE} ${SRC}/lpr_job.c
  293. lpr_parms.o:    $(SRC)/lpr_parms.c
  294. X    ${COMPILE} ${SRC}/lpr_parms.c
  295. lpr_temp.o:    $(SRC)/lpr_temp.c
  296. X    ${COMPILE} ${SRC}/lpr_temp.c
  297. mexecv.o:    $(SRC)/mexecv.c
  298. X    ${COMPILE} ${SRC}/mexecv.c
  299. pac.o:    $(SRC)/pac.c
  300. X    ${COMPILE} ${SRC}/pac.c
  301. print_support.o:    $(SRC)/print_support.c
  302. X    ${COMPILE} ${SRC}/print_support.c
  303. printcap.o:    $(SRC)/printcap.c
  304. X    ${COMPILE} ${SRC}/printcap.c
  305. recvfiles.o:    $(SRC)/recvfiles.c
  306. X    ${COMPILE} ${SRC}/recvfiles.c
  307. remote_ops.o:    $(SRC)/remote_ops.c
  308. X    ${COMPILE} ${SRC}/remote_ops.c
  309. remoteprinter.o:    $(SRC)/remoteprinter.c
  310. X    ${COMPILE} ${SRC}/remoteprinter.c
  311. rmjob.o:    $(SRC)/rmjob.c
  312. X    ${COMPILE} ${SRC}/rmjob.c
  313. sendmail.o:    $(SRC)/sendmail.c
  314. X    ${COMPILE} ${SRC}/sendmail.c
  315. servicereq.o:    $(SRC)/servicereq.c
  316. X    ${COMPILE} ${SRC}/servicereq.c
  317. setstatus.o:    $(SRC)/setstatus.c
  318. X    ${COMPILE} ${SRC}/setstatus.c
  319. setup_filter.o:    $(SRC)/setup_filter.c
  320. X    ${COMPILE} ${SRC}/setup_filter.c
  321. setup_test.o:    $(SRC)/setup_test.c
  322. X    ${COMPILE} ${SRC}/setup_test.c
  323. startserver.o:    $(SRC)/startserver.c
  324. X    ${COMPILE} ${SRC}/startserver.c
  325. startprinter.o:    $(SRC)/startprinter.c
  326. X    ${COMPILE} ${SRC}/startprinter.c
  327. termclear.o:    $(SRC)/termclear.c
  328. X    ${COMPILE} ${SRC}/termclear.c
  329. utils.o:    $(SRC)/utils.c
  330. X    ${COMPILE} ${SRC}/utils.c
  331. X#
  332. X# Installation of commands
  333. X#
  334. install: all
  335. X    install -s -c -o root -m u=sxr,g=xr,o=xr lpd ${LIB}
  336. X    install -s -c -o root -m u=sxr,g=xr,o=xr lpq ${BIN}
  337. X    install -s -c -o root -m u=sxr,g=xr,o=xr lprm ${BIN}
  338. X    install -s -c -o root -m u=sxr,g=xr,o=xr lpc ${MAINTDIR}
  339. X    install -s -c -o root -m u=sxr,g=xr,o=xr lpr ${BIN}
  340. X    install -s -c -o root pac ${MAINTDIR}
  341. X    install -s -c -o root checkpc ${MAINTDIR}
  342. X
  343. remove:
  344. X    rm -f ${LIB}/lpd
  345. X    rm -f ${BIN}/lpq
  346. X    rm -f ${BIN}/lprm
  347. X    rm -f ${MAINTDIR}/lpc
  348. X    rm -f ${BIN}/lpr
  349. X    rm -f ${MAINTDIR}/pac
  350. X    rm -f ${MAINTDIR}/checkpc
  351. X#
  352. X# Lint dependencies
  353. X#
  354. X
  355. lint:    $(LNT)/lpd $(LNT)/lpr $(LNT)/lpq $(LNT)/lprm \
  356. X        $(LNT)/lpc $(LNT)/checkpc $(LNT)/pac
  357. X
  358. X$(LNT)/lpd: $(SRClpd)
  359. X    lint  ${LINTFLAGS} $(SRClpd)  ${LINTFILTER} > $(LNT)/lpd
  360. X
  361. X$(LNT)/lpr: $(SRClpr)
  362. X    lint  ${LINTFLAGS} $(SRClpr)  ${LINTFILTER} > $(LNT)/lpr
  363. X
  364. X$(LNT)/lpq: $(SRClpq)
  365. X    lint  ${LINTFLAGS} $(SRClpq)  ${LINTFILTER} > $(LNT)/lpq
  366. X
  367. X$(LNT)/lprm: $(SRClprm)
  368. X    lint  ${LINTFLAGS} $(SRClprm)  ${LINTFILTER} > $(LNT)/lprm
  369. X
  370. X$(LNT)/lpc: $(SRClpc)
  371. X    lint  ${LINTFLAGS} $(SRClpc)  ${LINTFILTER} > $(LNT)/lpc
  372. X
  373. X$(LNT)/checkpc: $(SRCcheckpc)
  374. X    lint  ${LINTFLAGS} $(SRCcheckpc)  ${LINTFILTER} > $(LNT)/checkpc
  375. X
  376. X$(LNT)/pac: $(SRCpac)
  377. X    lint  ${LINTFLAGS} $(SRCpac)  ${LINTFILTER} > $(LNT)/pac
  378. X
  379. X#
  380. X# Miscellaneous
  381. X#
  382. clean:
  383. X    -rm -f ${COMMANDS} *.o core ?
  384. X
  385. print:
  386. X    @${PRINT} Makefile *.h ${SRCS} | lpr -J lpd
  387. X
  388. xref:
  389. X    @${CXREF} *.c | pr -h XREF
  390. X
  391. Tags:
  392. X    ctags -t *.c *.h >.ctags_warnings 2>&1
  393. perms:
  394. X    chown root lp? lp??
  395. X    chmod  u=sxr,g=xr,o=xr lp? lp??
  396. unperms:
  397. X    for i in ${COMMANDS} ; \
  398. X    do \
  399. X    case $$i in \
  400. X        lp? | lp??)    \
  401. X            echo $$i ;    \
  402. X            cat $$i >x; rm $$i ; mv x $$i; \
  403. X            chmod a+x $$i    ;    \
  404. X            ;;    \
  405. X    esac                \
  406. X    done
  407. test:
  408. X    -rm checkpc.o lpc.o lpd.o lpq.o lpr.o lprm.o pac.o
  409. X    make  XPERIMENT=-DXPERIMENT=1 all
  410. END_OF_FILE
  411. if test 12955 -ne `wc -c <'src/Makefile'`; then
  412.     echo shar: \"'src/Makefile'\" unpacked with wrong size!
  413. fi
  414. # end of 'src/Makefile'
  415. fi
  416. if test -f 'src/global.c' -a "${1}" != "-c" ; then 
  417.   echo shar: Will not clobber existing file \"'src/global.c'\"
  418. else
  419. echo shar: Extracting \"'src/global.c'\" \(14489 characters\)
  420. sed "s/^X//" >'src/global.c' <<'END_OF_FILE'
  421. X/***************************************************************************
  422. X * U. Minnesota LPD Software * Copyright 1987, 1988, Patrick Powell
  423. X ***************************************************************************
  424. X * MODULE: globals.c
  425. X * Definitions of global variables.
  426. X * NOTE: system dependent,  default values defined in lp.h
  427. X ***************************************************************************
  428. X * Revision History: Created Sun Jan  3 08:25:42 CST 1988
  429. X * $Log:    global.c,v $
  430. X * Revision 3.1  88/06/18  09:34:18  papowell
  431. X * Version 3.0- Distributed Sat Jun 18 1988
  432. X * 
  433. X * Revision 2.3  88/05/21  10:27:41  papowell
  434. X * Minor editing
  435. X * 
  436. X * Revision 2.2  88/05/14  10:18:12  papowell
  437. X * Use long format for job file names;
  438. X * Added 'fd', no forward flag;
  439. X * Control file has to have hostname and origination agree.
  440. X * 
  441. X * Revision 2.1  88/05/09  10:08:15  papowell
  442. X * PLP: Released Version
  443. X * 
  444. X * Revision 1.7  88/05/09  10:03:32  papowell
  445. X * Revised effects of -h option
  446. X * 
  447. X * Revision 1.6  88/04/27  20:25:40  papowell
  448. X * Modified to remove unused variables
  449. X * 
  450. X * Revision 1.5  88/04/07  12:31:25  papowell
  451. X * 
  452. X * Revision 1.4  88/03/25  14:59:34  papowell
  453. X * Debugged Version:
  454. X * 1. Added the PLP control file first transfer
  455. X * 2. Checks for MX during file transfers
  456. X * 3. Found and fixed a mysterious bug involving the SYSLOG facilities;
  457. X *     apparently they open files and then assume that they will stay
  458. X *     open.
  459. X * 4. Made sure that stdin, stdout, stderr was available at all times.
  460. X * 
  461. X * Revision 1.3  88/03/11  19:29:31  papowell
  462. X * Minor Changes, Updates
  463. X * 
  464. X * Revision 1.2  88/03/05  15:02:05  papowell
  465. X * Minor Corrections,  Lint Problems
  466. X * 
  467. X * Revision 1.1  88/03/01  11:08:27  papowell
  468. X * Initial revision
  469. X * 
  470. X ***************************************************************************/
  471. X#ifndef lint
  472. static char id_str1[] =
  473. X    "$Header: global.c,v 3.1 88/06/18 09:34:18 papowell Exp $ PLP Copyright 1988 Patrick Powell";
  474. X#endif lint
  475. X
  476. X#include "lp.h"
  477. X
  478. X/*************************************************************************
  479. X * global variables
  480. X *************************************************************************/
  481. X
  482. char  *Name;                    /* program Name (argv[0]) */
  483. char  *Printer;                    /* Printer Name, set for a queue handler */
  484. char   Host[64];                /* Host machine name */
  485. char  *From;                    /* client's machine Name */
  486. char  *Person;                    /* Name of Person making request */
  487. XFILE  *Lfd;                        /* lock file file descriptor */
  488. char  *First_name;                /* first name in printcap entry */
  489. int    Debug;                    /* Debugging level */
  490. int    Echo_on_stdout;            /* error messages on stdout and stderr */
  491. int    Errorcode = 2;            /* exit() value for fatal termination */
  492. struct parm Parms[MAXPARMS];    /* character parameters */
  493. int    Parmcount;                /* number of requests */
  494. char   Last_errormsg[BUFSIZ];    /* last errormessage */
  495. struct queue *Jobentry;            /* current job entry in queue */
  496. int    Request;                    /* current lpd request code */
  497. int    Print_fd;                /* output printer file descriptor */
  498. char   CFparm[26][MAXPARMLEN+1];    /* parameters read from control file */
  499. struct queue *Queue;            /* Getq generates a vector of jobs */
  500. int    Jobcount;                /* and returns the number of jobs  */
  501. int    Short_format;            /* short status format */
  502. int    Rec_cnt;                    /* number of files in a job */
  503. int    Is_root;                 /* is this the root user? */
  504. int    Is_local;                /* doing this locally or remotely? */
  505. struct stat LO_statb;            /* used to stat lockfile */
  506. int    Daemon_uid;                /* daemon UID */
  507. int    Daemon_gid;                /* daemon GID */
  508. X
  509. X/******************************************************************
  510. X * Definitions for the printcap variables.
  511. X ******************************************************************/
  512. X
  513. int    AB;        /* Always have a banner flag, ignore lpr -h option */
  514. char  *AF;        /* accounting file */
  515. int    BK;        /* Berkeley compatible remote and local */
  516. char  *BP;        /* banner printer filter */
  517. int    BR;        /* baud rate if lp is a tty */
  518. int    CO;        /* cost of printing in dollars per thousand pages */
  519. char  *EP;        /* end printer filter */
  520. int    FC;        /* flags to clear if lp is a tty */
  521. int    FD;        /* No forwarding, accept only from original site */
  522. char  *FF;        /* form feed string */
  523. int    FJ;        /* send control file  first to remote site */
  524. int    FO;        /* print a form feed when device is opened */
  525. int    FQ;        /* form feed on quitting */
  526. int    FS;        /* flags to set if lp is a tty */
  527. char  *FX;        /* allowable formats */
  528. char  *LD;        /* leader string on opening */
  529. char  *LF;        /* log file for error messages */
  530. int    LH;        /* use long host name */
  531. char  *LN;        /* group allowed to use links */
  532. char  *LO;        /* lock file Name */
  533. char  *LP;        /* line Printer device Name */
  534. int    MC;        /* maximum number of copies allowed */
  535. int    MX;        /* maximum number of blocks to copy */
  536. int    NW;        /* Networked file system, do not make copies */
  537. int    PL;        /* page length */
  538. char  *PR;        /* pr program Name Name */
  539. char  *PS;        /* Printer status file Name */
  540. int    PW;        /* page width */
  541. int    PX;        /* page width in pixels */
  542. int    PY;        /* page length in pixels */
  543. char  *QH;        /* queue handler */
  544. char  *RG;        /* restrict use to group */
  545. char  *RM;        /* remote machine Name */
  546. char  *RP;        /* remote Printer Name */
  547. int    RT;        /* max retries */
  548. int    RW;        /* open LP for reading and writing */
  549. int    SB;        /* short banner instead of normal header */
  550. int    SC;        /* suppress multiple copies */
  551. char  *SD;        /* spool directory */
  552. int    SF;        /* suppress FF on each print job */
  553. int    SH;        /* suppress header page */
  554. char  *SS;        /* name of queue that the server serves  */
  555. char  *ST;        /* status file Name */
  556. char  *SV;        /* names of servers */
  557. char  *TR;        /* trailer string to be output when Q empties */
  558. char  *TY;        /* terminal characteristics, stty options */
  559. int    XC;        /* flags to clear for local mode */
  560. int    XS;        /* flags to set for local mode */
  561. char  *XU;        /* restrict use to users with perms in file */
  562. char  *XT;        /* check format in string for printable text only */
  563. X/*
  564. X * filter arguments are indexed by first letter of the filter Name.
  565. X * For example:
  566. X * "if=/usr/lib/iffilter" -> Filter_name['i'-'a']
  567. X */
  568. char *Filter_name[26];
  569. X/*
  570. X * Prefilter arguments are indexed by first letter of the filter Name,
  571. X * as for the filters
  572. X */
  573. char *Prefilter_name[26];
  574. X
  575. X/*************************************************************************
  576. X * Printcap Entries,  Defaults, and Variables
  577. X * The All_pc_vars[] and Status_pc_vars[] arrays contain the Names
  578. X * of the printcap entries, the type of entry,  the default value,
  579. X * and the variable which is set by the entry.
  580. X * The array is sorted by the printcap entry.
  581. X *************************************************************************/
  582. X
  583. PC_ENTRY All_pc_vars[] = {
  584. X{ "ab", PC_FLAG, 0, 0, (char **)&AB },
  585. X{ "ae", PC_STRING, 0, 0, &Prefilter_name['a'-'a'] },
  586. X{ "af", PC_STRING, 0, DEFACCT, &AF },
  587. X{ "be", PC_STRING, 0, 0, &Prefilter_name['b'-'a'] },
  588. X{ "bf", PC_STRING, 0, 0, &Filter_name['b'-'a'] },
  589. X{ "bk", PC_NUM, 0, 0, (char **)&BK },
  590. X{ "bp", PC_STRING, 0, 0, &BP },
  591. X{ "br", PC_NUM, 0, 0, (char **)&BR },
  592. X{ "ce", PC_STRING, 0, 0, &Prefilter_name['c'-'a'] },
  593. X{ "cf", PC_STRING, 0, 0, &Filter_name['c'-'a'] },
  594. X{ "co", PC_NUM, 0, 0, (char **)&CO },
  595. X{ "de", PC_STRING, 0, 0, &Prefilter_name['d'-'a'] },
  596. X{ "df", PC_STRING, 0, 0, &Filter_name['d'-'a'] },
  597. X{ "ee", PC_STRING, 0, 0, &Prefilter_name['e'-'a'] },
  598. X{ "ef", PC_STRING, 0, 0, &Filter_name['e'-'a'] },
  599. X{ "ep", PC_STRING, 0, 0, &EP },
  600. X{ "fc", PC_NUM, 0, 0, (char **)&FC },
  601. X{ "fd", PC_FLAG, 0, 0, (char **)&FD },
  602. X{ "ff", PC_STRING, 0, DEFFF, &FF },
  603. X{ "fj", PC_FLAG, 0, 0, (char **)&FJ },
  604. X{ "fo", PC_FLAG, 0, 0, (char **)&FO },
  605. X{ "fq", PC_FLAG, 0, 0, (char **)&FQ },
  606. X{ "fs", PC_NUM, 0, 0, (char **)&FS },
  607. X{ "fx", PC_STRING, 0, 0, &FX },
  608. X{ "ge", PC_STRING, 0, 0, &Prefilter_name['g'-'a'] },
  609. X{ "gf", PC_STRING, 0, 0, &Filter_name['g'-'a'] },
  610. X{ "he", PC_STRING, 0, 0, &Prefilter_name['h'-'a'] },
  611. X{ "hf", PC_STRING, 0, 0, &Filter_name['h'-'a'] },
  612. X{ "ie", PC_STRING, 0, 0, &Prefilter_name['i'-'a'] },
  613. X{ "if", PC_STRING, 0, 0, &Filter_name['i'-'a'] },
  614. X{ "je", PC_STRING, 0, 0, &Prefilter_name['j'-'a'] },
  615. X{ "jf", PC_STRING, 0, 0, &Filter_name['j'-'a'] },
  616. X{ "ke", PC_STRING, 0, 0, &Prefilter_name['k'-'a'] },
  617. X{ "kf", PC_STRING, 0, 0, &Filter_name['k'-'a'] },
  618. X{ "le", PC_STRING, 0, 0, &Prefilter_name['l'-'a'] },
  619. X{ "lf", PC_STRING, 0, DEFLOGF, &LF },
  620. X{ "lh", PC_NUM, 0, 0, (char **)&LH },
  621. X{ "ln", PC_STRING, 0, 0, &LN },
  622. X{ "lo", PC_STRING, 0, DEFLOCK, &LO },
  623. X{ "lp", PC_STRING, 0, 0, &LP },
  624. X{ "mc", PC_NUM, DEFMAXCOPIES, 0, (char **)&MC },
  625. X{ "me", PC_STRING, 0, 0, &Prefilter_name['m'-'a'] },
  626. X{ "mf", PC_STRING, 0, 0, &Filter_name['m'-'a'] },
  627. X{ "mx", PC_NUM, DEFMX, 0, (char **)&MX },
  628. X{ "ne", PC_STRING, 0, 0, &Prefilter_name['n'-'a'] },
  629. X{ "nf", PC_STRING, 0, 0, &Filter_name['n'-'a'] },
  630. X{ "nw", PC_FLAG, 0, 0, (char **)&NW },
  631. X{ "oe", PC_STRING, 0, 0, &Prefilter_name['o'-'a'] },
  632. X{ "of", PC_STRING, 0, 0, &Filter_name['o'-'a'] },
  633. X{ "pe", PC_STRING, 0, 0, &Prefilter_name['p'-'a'] },
  634. X{ "pf", PC_STRING, 0, 0, &Filter_name['p'-'a'] },
  635. X{ "pl", PC_NUM, DEFLENGTH, 0, (char **)&PL },
  636. X{ "pr", PC_STRING, 0, DEFPR, &PR },
  637. X{ "ps", PC_STRING, 0, 0, &PS },
  638. X{ "pw", PC_NUM, DEFWIDTH, 0, (char **)&PW },
  639. X{ "px", PC_NUM, 0, 0, (char **)&PX },
  640. X{ "py", PC_NUM, 0, 0, (char **)&PY },
  641. X{ "qe", PC_STRING, 0, 0, &Prefilter_name['q'-'a'] },
  642. X{ "qf", PC_STRING, 0, 0, &Filter_name['q'-'a'] },
  643. X{ "qh", PC_STRING, 0, 0, &QH },
  644. X{ "re", PC_STRING, 0, 0, &Prefilter_name['r'-'a'] },
  645. X{ "rf", PC_STRING, 0, 0, &Filter_name['r'-'a'] },
  646. X{ "rg", PC_STRING, 0, 0, &RG },
  647. X{ "rm", PC_STRING, 0, 0, &RM },
  648. X{ "rp", PC_STRING, 0, 0, &RP },
  649. X{ "rt", PC_NUM, DEFRETRY, 0, (char **)&RT },
  650. X{ "rw", PC_FLAG, 0, 0, (char **)&RW },
  651. X{ "sb", PC_FLAG, 0, 0, (char **)&SB },
  652. X{ "sc", PC_FLAG, 0, 0, (char **)&SC },
  653. X{ "sd", PC_STRING, 0, 0, &SD },
  654. X{ "se", PC_STRING, 0, 0, &Prefilter_name['s'-'a'] },
  655. X{ "sf", PC_FLAG, 0, 0, (char **)&SF },
  656. X{ "sh", PC_FLAG, 0, 0, (char **)&SH },
  657. X{ "ss", PC_STRING, 0, 0, &SS },
  658. X{ "st", PC_STRING, 0, DEFSTAT, &ST },
  659. X{ "sv", PC_STRING, 0, 0, &SV },
  660. X{ "te", PC_STRING, 0, 0, &Prefilter_name['t'-'a'] },
  661. X{ "tf", PC_STRING, 0, 0, &Filter_name['t'-'a'] },
  662. X{ "tr", PC_STRING, 0, 0, &TR },
  663. X{ "ty", PC_STRING, 0, 0, &TY },
  664. X{ "ue", PC_STRING, 0, 0, &Prefilter_name['u'-'a'] },
  665. X{ "uf", PC_STRING, 0, 0, &Filter_name['u'-'a'] },
  666. X{ "ve", PC_STRING, 0, 0, &Prefilter_name['v'-'a'] },
  667. X{ "vf", PC_STRING, 0, 0, &Filter_name['v'-'a'] },
  668. X{ "we", PC_STRING, 0, 0, &Prefilter_name['w'-'a'] },
  669. X{ "wf", PC_STRING, 0, 0, &Filter_name['w'-'a'] },
  670. X{ "xc", PC_NUM, 0, 0, (char **)&XC },
  671. X{ "xe", PC_STRING, 0, 0, &Prefilter_name['x'-'a'] },
  672. X{ "xf", PC_STRING, 0, 0, &Filter_name['x'-'a'] },
  673. X{ "xs", PC_NUM, 0, 0, (char **)&XS },
  674. X{ "xt", PC_STRING, 0, 0, &XT },
  675. X{ "xu", PC_STRING, 0, 0, &XU },
  676. X{ "ye", PC_STRING, 0, 0, &Prefilter_name['y'-'a'] },
  677. X{ "yf", PC_STRING, 0, 0, &Filter_name['y'-'a'] },
  678. X{ "ze", PC_STRING, 0, 0, &Prefilter_name['z'-'a'] },
  679. X{ "zf", PC_STRING, 0, 0, &Filter_name['z'-'a'] }
  680. X};
  681. X
  682. int    All_pc_len = sizeof(All_pc_vars)/sizeof(PC_ENTRY);
  683. X
  684. X/**************************************************************************
  685. X * Status_pc_vars[] 
  686. X * status checking uses only a subset of all the printcap entries
  687. X **************************************************************************/
  688. PC_ENTRY Status_pc_vars[] = {
  689. X{ "af", PC_STRING, 0, 0, &AF },
  690. X{ "co", PC_NUM, 0, 0, (char **)&CO },
  691. X{ "fd", PC_FLAG, 0, 0, (char **)&FD },
  692. X{ "lf", PC_STRING, 0, DEFLOGF, &LF },
  693. X{ "lh", PC_NUM, 0, 0, (char **)&LH },
  694. X{ "lo", PC_STRING, 0, DEFLOCK, &LO },
  695. X{ "lp", PC_STRING, 0, 0, &LP },
  696. X{ "mx", PC_NUM, DEFMX, 0, (char **)&MX },
  697. X{ "nw", PC_FLAG, 0, 0, (char **)&NW },
  698. X{ "ps", PC_STRING, 0, 0, &PS },
  699. X{ "rg", PC_STRING, 0, 0, &RG },
  700. X{ "rm", PC_STRING, 0, 0, &RM },
  701. X{ "rp", PC_STRING, 0, 0, &RP },
  702. X{ "sd", PC_STRING, 0, 0, &SD },
  703. X{ "ss", PC_STRING, 0, 0, &SS },
  704. X{ "st", PC_STRING, 0, DEFSTAT, &ST },
  705. X{ "sv", PC_STRING, 0, 0, &SV },
  706. X{ "xu", PC_STRING, 0, 0, &XU }
  707. X};
  708. int    Status_pc_len = sizeof(Status_pc_vars)/sizeof(PC_ENTRY);
  709. X
  710. X/**************************************************************************
  711. X * Server_pc_vars[] 
  712. X * just used to get a select set of server information
  713. X **************************************************************************/
  714. PC_ENTRY Server_pc_vars[] = {
  715. X{ "ps", PC_STRING, 0, 0, &PS },
  716. X{ "ss", PC_STRING, 0, 0, &SS },
  717. X{ "st", PC_STRING, 0, DEFSTAT, &ST },
  718. X{ "sv", PC_STRING, 0, 0, &SV }
  719. X};
  720. X
  721. int    Server_pc_len = sizeof(Server_pc_vars)/sizeof(PC_ENTRY);
  722. X/*
  723. X * Location of LPD and LPR dependent files
  724. X * Note that this will get updated to site dependent versions.
  725. X */
  726. char Lpdlogf[MAXPATHLEN]  = RDEFLPDLOGF;
  727. char Masterlock[MAXPATHLEN]  = RMASTERLOCK;
  728. int    Lpr_port_num;        /* port number to connect to */
  729. int Maxportno = RMAXPORTNO;
  730. int Minportno = RMINPORTNO;
  731. char Permfile[MAXPATHLEN]  = RPERMFILE;
  732. char Printcap[MAXPATHLEN]  = RPRINTCAP;
  733. X
  734. X
  735. X/*
  736. X *  SYSLOG.H -- declarations for system logging program
  737. X *
  738. X *    These are used as the first parameter to logmsg().
  739. X *    Their meanings are approximately as follows:
  740. X *
  741. X *    LOG_ERR -- these represent error conditions, such as soft
  742. X *        disk failures, etc.
  743. X *    LOG_CRIT -- such messages contain critical information,
  744. X *        but which can not be classed as errors, for example,
  745. X *        'su' attempts.
  746. X *    LOG_WARNING -- issued when an abnormal condition has been
  747. X *        detected, but recovery can take place.
  748. X *    LOG_NOTICE -- something that falls in the class of
  749. X *        "important information"; this class is informational
  750. X *        but important enough that you don't want to throw
  751. X *        it away casually.
  752. X *    LOG_INFO -- information level messages.  These messages
  753. X *        could be thrown away without problems, but should
  754. X *        be included if you want to keep a close watch on
  755. X *        your system.
  756. X *    LOG_DEBUG -- it may be useful to log certain Debugging
  757. X *        information.  Normally this will be thrown away.
  758. X */
  759. X
  760. X#ifdef NOSYSLOG
  761. X
  762. X/* defines for priorities */
  763. X#define    LOG_ERR        4    /* synonym of LOG_ERROR */
  764. X#define    LOG_CRIT    5    /* critical information */
  765. X#define    LOG_WARNING    6    /* warning */
  766. X#define    LOG_NOTICE    7    /* important information */
  767. X#define    LOG_INFO    8    /* informational message */
  768. X#define    LOG_DEBUG    9    /* Debug level info */
  769. X
  770. X#else
  771. X#include <syslog.h>
  772. X#endif
  773. X
  774. int XLOG_ERR    = LOG_ERR;            /* synonym of LOG_ERROR */
  775. int XLOG_CRIT    = LOG_CRIT;            /* critical information */
  776. int XLOG_WARNING    = LOG_WARNING;    /* warning */
  777. int XLOG_NOTICE    = LOG_NOTICE;        /* important information */
  778. int XLOG_INFO    = LOG_INFO;            /* informational message */
  779. int XLOG_DEBUG    = LOG_DEBUG;        /* Debug level info */
  780. END_OF_FILE
  781. if test 14489 -ne `wc -c <'src/global.c'`; then
  782.     echo shar: \"'src/global.c'\" unpacked with wrong size!
  783. fi
  784. # end of 'src/global.c'
  785. fi
  786. if test -f 'src/lockfile.c' -a "${1}" != "-c" ; then 
  787.   echo shar: Will not clobber existing file \"'src/lockfile.c'\"
  788. else
  789. echo shar: Extracting \"'src/lockfile.c'\" \(12577 characters\)
  790. sed "s/^X//" >'src/lockfile.c' <<'END_OF_FILE'
  791. X/***************************************************************************
  792. X * U. Minnesota LPD Software * Copyright 1987, 1988, Patrick Powell
  793. X ***************************************************************************
  794. X * MODULE: lockfile.c
  795. X * lock file manipulation procedures.
  796. X ***************************************************************************
  797. X * Revision History: Created Sat Jan  2 06:59:04 CST 1988
  798. X * $Log:    lockfile.c,v $
  799. X * Revision 3.1  88/06/18  09:34:27  papowell
  800. X * Version 3.0- Distributed Sat Jun 18 1988
  801. X * 
  802. X * Revision 2.2  88/05/19  10:34:01  papowell
  803. X * Fixed open() calls to have a 0 parameter, ie: open(f, perms, 0), where needed
  804. X * 
  805. X * Revision 2.1  88/05/09  10:08:33  papowell
  806. X * PLP: Released Version
  807. X * 
  808. X * Revision 1.6  88/05/03  11:45:45  papowell
  809. X * Added LOCKF and FLOCK support
  810. X * 
  811. X * Revision 1.5  88/04/28  10:04:42  papowell
  812. X * minor definitions to keep lint happy
  813. X * 
  814. X * Revision 1.4  88/04/27  20:23:42  papowell
  815. X * Added flock() and lockf() functionality
  816. X * 
  817. X * Revision 1.3  88/04/06  12:13:32  papowell
  818. X * Minor updates, changes in error message formats.
  819. X * Elimination of the AF_UNIX connections, use AF_INET only.
  820. X * Better error messages.
  821. X * 
  822. X * Revision 1.2  88/03/25  14:59:49  papowell
  823. X * Debugged Version:
  824. X * 1. Added the PLP control file first transfer
  825. X * 2. Checks for MX during file transfers
  826. X * 3. Found and fixed a mysterious bug involving the SYSLOG facilities;
  827. X *     apparently they open files and then assume that they will stay
  828. X *     open.
  829. X * 4. Made sure that stdin, stdout, stderr was available at all times.
  830. X * 
  831. X * Revision 1.1  88/03/01  11:08:33  papowell
  832. X * Initial revision
  833. X * 
  834. X ***************************************************************************/
  835. X#ifndef lint
  836. static char id_str1[] =
  837. X    "$Header: lockfile.c,v 3.1 88/06/18 09:34:27 papowell Exp $ PLP Copyright 1988 Patrick Powell";
  838. X#endif lint
  839. X/***************************************************************************
  840. X * File Locking Routines:
  841. X * FILE * Lockcf( char *filename )
  842. X *     locks the indicated file if it exists
  843. X *     Returns: a FILE * for RW if successful, NULL otherwise;
  844. X * FILE * Readlockfile(char *filename,int *pid,char *str,int len,struct stat *s)
  845. X *     reads the information in the lock file.
  846. X * int Checklockfile(char *filename,int *pid,char *str,int len,struct stat *s)
  847. X *     Checks for the presence of a server by using kill(0,pid).
  848. X *     Returns 1 if server present, 0 if not.
  849. X *     Side Effect: if the server is present, returns PID and string from file
  850. X *       in pid and str, stats the file as well
  851. X * FILE * Getlockfile(char *filename,int *pid,char *str,int len,struct stat *s)
  852. X *     locks the indicated file;
  853. X *     Returns a FILE * if successful, NULL otherwise;
  854. X *     Side Effect: if the file is locked, returns PID and string from file
  855. X *       in pid and str, stats the file as well
  856. X * Setlockfile( FILE *fp; int pid; char *str);
  857. X *     write PID and str into the file
  858. X * Closelockfile( FILE *fp );
  859. X *     truncates the lock file and closes it.
  860. X * int Exlockcf( char *filename )
  861. X *    creates and locks the file.
  862. X *    Returns: FILE * for writing, NULL if file exists and is locked
  863. X ***************************************************************************
  864. X * Lock File Manipulation:
  865. X * Each active server has a lock file, which it uses to record its
  866. X * activity.  The lock file is created and then locked;
  867. X * the deamon will place its PID and an activity in the lock file.
  868. X * Programs wanting to know the server status will read the file.
  869. X * Note:  only active server, not status programs, will lock the file.
  870. X * This prevents a status program from locking out a server.
  871. X * Note that the information in the status file may be stale,  as the
  872. X * may update the file without the knowledge of the checker.  This
  873. X * appears to be a small price to pay;  the only place where it may
  874. X * have an effect is when a job is being removed.
  875. X ***************************************************************************/
  876. X#include "lp.h"
  877. extern long lseek();
  878. static int do_lock();
  879. X
  880. XFILE *
  881. Lockcf( filename )
  882. X    char *filename;        /* Name of file */
  883. X{
  884. X    int fd;                /* fd for file descriptor */
  885. X    FILE *fp;            /* fp for FILE * */
  886. X    int lock;            /* lock status */
  887. X
  888. X    /*
  889. X     * Open the lock file for RW
  890. X     */
  891. X    fp = NULL;
  892. X    if( (fd = open_daemon(filename, O_RDWR, 0)) < 0 ){
  893. X        logerr(XLOG_DEBUG,"Lockcf: cannot open file %s", filename);
  894. X    } else if( fd < 3 ){
  895. X        fatal( XLOG_CRIT, "Lockcf: open '%s' fd is %d", filename, fd);
  896. X    } else if( (lock = do_lock(fd, filename)) < 0) {
  897. X        logerr_die( XLOG_CRIT, "Lockcf: lock '%s' failed", filename);
  898. X    } else if( lock == 0 ){
  899. X        if(Debug>3)logerr( XLOG_DEBUG, "Lockcf: lock failed '%s' active",
  900. X            filename);
  901. X        (void)close( fd );
  902. X        fd = -1;
  903. X    } else if( (fp = fdopen( fd, "r+")) == NULL ){
  904. X        logerr_die( XLOG_CRIT, "Lockcf: fdopen '%s' failed", filename);
  905. X    }
  906. X    if(Debug>5)log(XLOG_DEBUG,"Lockcf: file '%s', fd %d", filename, fd );
  907. X    return( fp );
  908. X}
  909. X/***************************************************************************
  910. X * File *Readlockfile( .... )
  911. X * Utility function used by Getlockfile and Checklockfile
  912. X * Implements the lock manipulation and reading of the lock file.
  913. X ***************************************************************************/
  914. XFILE *
  915. Readlockfile( filename, pid, str, len, sb )
  916. X    char *filename;        /* Name of file */
  917. X    int *pid;            /* pid */
  918. X    char *str;            /* string */
  919. X    int len;            /* max string length */
  920. X    struct stat *sb;    /* stat buffer */
  921. X{
  922. X    int fd;                /* file descriptor */
  923. X    FILE *fp = NULL;    /* stream */
  924. X    int p;                /* ACME Integer and Buggy Works, Inc. */
  925. X    char buffer[BUFSIZ]; /* holds the pid read from file */
  926. X    char *cp;            /* ACME Pointer, Inc. */
  927. X    struct stat s;        /* try stating first */
  928. X
  929. X    /*
  930. X     * Open the lock file, creating if necessary
  931. X     */
  932. X    if(Debug>4)log(XLOG_DEBUG,"Readlockfile: lockfile '%s'", filename );
  933. X    if( (fd = open_daemon(filename, O_RDWR|O_CREAT, 0644) ) < 0 ){
  934. X        logerr_die(XLOG_DEBUG,
  935. X            "Readlockfile: cannot create lock file '%s'", filename);
  936. X    }
  937. X    /*
  938. X     * check to see that you are not clobbering stdin, stdout, stderr
  939. X     */
  940. X    if( fd < 3 ){
  941. X        fatal( XLOG_CRIT, "Readlockfile: open '%s' fd is %d", filename, fd);
  942. X    }
  943. X    /*
  944. X     * need a FILE * for stdio
  945. X     */
  946. X    if( (fp = fdopen( fd, "r+" )) == NULL ){
  947. X        logerr_die(XLOG_CRIT,"Readlockfile: fdopen '%s' failed",filename);
  948. X    }
  949. X    /*
  950. X     * stat the file for use by others
  951. X     */
  952. X    if( fstat( fd, &s ) < 0 ){
  953. X        logerr_die( XLOG_INFO,"Readlockfile: fstat '%s' failed", filename);
  954. X    }
  955. X    if( sb ){
  956. X        *sb = s;
  957. X    }
  958. X    if(Debug>4)log(XLOG_DEBUG,"Readlockfile: %s, perms 0%o",
  959. X        filename,s.st_mode);
  960. X    /* read the process number */
  961. X    if( fseek( fp, 0L, 0 ) < 0 ){
  962. X        logerr_die( XLOG_INFO,"Readlockfile: fseek '%s' failed", filename);
  963. X    }
  964. X    p = 0;
  965. X    if( fgets( buffer, sizeof(buffer), fp ) ){
  966. X        p = atoi( buffer );
  967. X    }
  968. X    if(Debug>2)log(XLOG_DEBUG, "Readlockfile: '%s' pid %d len %d",
  969. X        filename,p, s.st_size);
  970. X    if( fgets( buffer, sizeof(buffer), fp ) ){
  971. X        if( cp = index(buffer, '\n') ){
  972. X            *cp = 0;
  973. X        }
  974. X        if(Debug>2)log(XLOG_DEBUG, "Readlockfile: info '%s'", buffer );
  975. X        if( str ){
  976. X            (void)strncpy(str,buffer,len);
  977. X        }
  978. X    }
  979. X    if( pid ){
  980. X        *pid = p;
  981. X    }
  982. X    if( fseek( fp, 0L, 0 ) < 0 ){
  983. X        logerr_die( XLOG_INFO,"Readlockfile: fseek '%s' failed", filename);
  984. X    }
  985. X    return( fp );
  986. X}
  987. X
  988. X
  989. X/***************************************************************************
  990. X * int Checklockfile( ... )
  991. X * Calls Readlockfile() to read the interesting information, passes
  992. X * things onwards.
  993. X ***************************************************************************/
  994. X
  995. Checklockfile( filename, pid, str, len, sb )
  996. X    char *filename;        /* Name of file */
  997. X    int *pid;            /* pid */
  998. X    char *str;            /* string */
  999. X    int len;            /* max string length */
  1000. X    struct stat *sb;    /* stat buffer */
  1001. X{
  1002. X    FILE *fp;            /* stream */
  1003. X    int p;                /* ACME Integer and Buggy Works, Inc. */
  1004. X    /*
  1005. X     * Read the information
  1006. X     */
  1007. X    fp = Readlockfile( filename, &p, str, len, sb );
  1008. X    /* check to see if deamon present by using KILL */
  1009. X    if( p != 0 && kill( p, 0 ) < 0 ){
  1010. X        if(Debug>4)log(XLOG_DEBUG, "Checklockfile: server %d not present", p );
  1011. X        /* sigh... not present */
  1012. X        p = 0;
  1013. X    }
  1014. X    if( pid ){
  1015. X        *pid = p;
  1016. X    }
  1017. X    if( fp ){
  1018. X        (void)fclose( fp );
  1019. X    }
  1020. X    if(Debug>2)log(XLOG_DEBUG, "Checklockfile: %s server %d", filename,p );
  1021. X    return( p );
  1022. X}
  1023. X
  1024. X/***************************************************************************
  1025. X * FILE * Getlockfile( ... )
  1026. X * Calls Readlockfile() to read the interesting information, passes
  1027. X * things onwards.  Will try to lock the file; if it fails, assume status
  1028. X * correct.  Slight race condition here.
  1029. X ***************************************************************************/
  1030. X
  1031. XFILE *
  1032. Getlockfile( filename, pid, str, len, statb )
  1033. X    char *filename;        /* Name of file */
  1034. X    int *pid;            /* pid */
  1035. X    char *str;            /* string */
  1036. X    int len;            /* max string length */
  1037. X    struct stat *statb;    /* status buffer */
  1038. X{
  1039. X    FILE *fp;        /* lockfile */
  1040. X    int p;
  1041. X    int lock;
  1042. X
  1043. X    fp = Readlockfile( filename, &p, str, len, statb );
  1044. X    if( pid ){
  1045. X        *pid = p;
  1046. X    }
  1047. X    if( fp != NULL ){
  1048. X        if( (lock = do_lock(fileno(fp), filename) ) < 0) {
  1049. X            logerr_die( XLOG_CRIT, "Getlockfile: lock '%s' failed", filename);
  1050. X        } else if( lock == 0 ){
  1051. X            if(Debug>3)log(XLOG_DEBUG,"Getlockfile: locked by %d",p);
  1052. X            (void)fclose( fp );
  1053. X            fp = NULL;
  1054. X        }
  1055. X    }
  1056. X    if(Debug>2)log(XLOG_DEBUG,"Getlockfile: %s %s",
  1057. X        filename,fp!=NULL?"success":"fail");
  1058. X    return( fp );
  1059. X}
  1060. X
  1061. X/***************************************************************************
  1062. X * Setlockfile( FILE *lockfile; int pid; char *str )
  1063. X * will write things into the lock file
  1064. X * This has the format:
  1065. X * line 1: pid\n
  1066. X * line 2: string\n
  1067. X ***************************************************************************/
  1068. X
  1069. Setlockfile(name, fp, pid, str)
  1070. X    char *name;
  1071. X    FILE *fp;
  1072. X    int pid;
  1073. X    char *str;
  1074. X{
  1075. X    /* clear the lock file */
  1076. X    if( fseek(fp, 0L, 0) < 0 ){
  1077. X        logerr_die( XLOG_CRIT, "Setlockfile: fseek failed %s",name);
  1078. X    }
  1079. X    if( ftruncate(fileno(fp), (off_t)0) < 0 ){
  1080. X        logerr_die( XLOG_CRIT, "Setlockfile: ftruncate failed %s", name);
  1081. X    }
  1082. X    if( fprintf( fp, "%d\n%s\n", pid, str?str:"" ) == EOF ){
  1083. X        logerr_die( XLOG_CRIT, "Setlockfile: fprintf failed %s", name);
  1084. X    }
  1085. X    if( fflush( fp ) == EOF ){
  1086. X        logerr_die( XLOG_CRIT, "Setlockfile: fflush failed %s", name);
  1087. X    }
  1088. X    if(Debug>4)log(XLOG_DEBUG,"Setlockfile: %s (%d), %s",name,pid,
  1089. X        str?str:"(nil)");
  1090. X}
  1091. X
  1092. X/***************************************************************************
  1093. X * Closelockfile( FILE *lockfile)
  1094. X * Truncate the file.
  1095. X ***************************************************************************/
  1096. Closelockfile(name, fp )
  1097. X    char *name;
  1098. X    FILE *fp;
  1099. X{
  1100. X    if(Debug>4)log(XLOG_DEBUG,"Closelockfile: closing %s", name );
  1101. X    if( fp == NULL ){
  1102. X        return;
  1103. X    }
  1104. X    /* clear the lock file */
  1105. X    (void)fflush(fp);
  1106. X    if( ftruncate(fileno(fp), (off_t)0) < 0 ){
  1107. X        logerr( XLOG_CRIT, "Closelockfile: cannot truncate %s", name);
  1108. X        return;
  1109. X    }
  1110. X    if( fclose( fp ) == EOF ){
  1111. X        logerr( XLOG_CRIT, "Closelockfile: fclose failed %s", name);
  1112. X        return;
  1113. X    }
  1114. X}
  1115. X
  1116. X/***************************************************************************
  1117. X * int Exlockcf( char *userfile )
  1118. X * Create a user file in the directory and lock it. Prevents things
  1119. X * from getting confused.
  1120. X ***************************************************************************/
  1121. X
  1122. XExlockcf( filename )
  1123. X    char *filename;        /* Name of file */
  1124. X{
  1125. X    int fd;                /* fd for file descriptor */
  1126. X    int lock;
  1127. X
  1128. X    /*
  1129. X     * Open the lock file, creating if necessary
  1130. X     */
  1131. X    fd = open_daemon(filename, O_RDWR|O_CREAT, FILMOD);
  1132. X    if (fd < 0) {
  1133. X        logerr_die(XLOG_DEBUG,"EXlockcf: cannot create file %s", filename);
  1134. X    }
  1135. X    if( (lock = do_lock(fd, filename)) < 0) {
  1136. X        logerr_die( XLOG_CRIT, "Exlockcf: lock '%s' failed", filename);
  1137. X    } else if( lock == 0 ){
  1138. X        if(Debug>4)log( XLOG_DEBUG, "Exlockcf: '%s' locked", filename);
  1139. X        (void)close( fd );
  1140. X        fd = -1;
  1141. X    } else if( ftruncate( fd, (off_t)0) < 0 ){
  1142. X        logerr_die( XLOG_CRIT, "Exlockcf: cannot truncate %s", filename);
  1143. X    }
  1144. X    return( fd );
  1145. X}
  1146. X
  1147. X/***************************************************************************
  1148. X * do_lock( fd , char *filename)
  1149. X * does a lock on a file;
  1150. X * Returns: 1 if successful; 0 if locked; -1 otherwise
  1151. X ***************************************************************************/
  1152. static int
  1153. do_lock( fd, filename )
  1154. X    int fd;
  1155. X    char *filename;
  1156. X{
  1157. X    int code;
  1158. X
  1159. X    code = -1;
  1160. X    if(Debug>5)log(XLOG_DEBUG,"do_lock: file %s, fd %d", filename, fd );
  1161. X#ifndef NO_LOCKF
  1162. X    /*
  1163. X     * want to try F_TLOCK
  1164. X     */
  1165. X    if( lockf(fd, F_TLOCK, 0L) < 0) {
  1166. X        code = 0;
  1167. X    } else {
  1168. X        code = 1;
  1169. X    }
  1170. X#else
  1171. X    if( flock(fd, LOCK_EX|LOCK_NB) < 0) {
  1172. X        if (errno == EWOULDBLOCK){
  1173. X            code = 0;
  1174. X        }
  1175. X    } else {
  1176. X        code = 1;
  1177. X    }
  1178. X#endif NO_LOCKF
  1179. X    if(Debug>5)log(XLOG_DEBUG,"do_lock: status %d", code );
  1180. X    return( code );
  1181. X}
  1182. END_OF_FILE
  1183. if test 12577 -ne `wc -c <'src/lockfile.c'`; then
  1184.     echo shar: \"'src/lockfile.c'\" unpacked with wrong size!
  1185. fi
  1186. # end of 'src/lockfile.c'
  1187. fi
  1188. echo shar: End of archive 9 \(of 16\).
  1189. cp /dev/null ark9isdone
  1190. MISSING=""
  1191. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  1192.     if test ! -f ark${I}isdone ; then
  1193.     MISSING="${MISSING} ${I}"
  1194.     fi
  1195. done
  1196. if test "${MISSING}" = "" ; then
  1197.     echo You have unpacked all 16 archives.
  1198.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1199. else
  1200.     echo You still need to unpack the following archives:
  1201.     echo "        " ${MISSING}
  1202. fi
  1203. ##  End of shell archive.
  1204. exit 0
  1205.  
  1206.