X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/8c8a5b54e79564c14fc7a2823a21a8f048449bcf..af359dea2e5ab3e937b62107ecd6a51d78189ed7:/usr/src/usr.sbin/lpr/lpd/recvjob.c diff --git a/usr/src/usr.sbin/lpr/lpd/recvjob.c b/usr/src/usr.sbin/lpr/lpd/recvjob.c index e4c99952a3..f199bd9772 100644 --- a/usr/src/usr.sbin/lpr/lpd/recvjob.c +++ b/usr/src/usr.sbin/lpr/lpd/recvjob.c @@ -2,11 +2,37 @@ * Copyright (c) 1983 Regents of the University of California. * All rights reserved. * - * %sccs.include.redist.c% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #ifndef lint -static char sccsid[] = "@(#)recvjob.c 5.12 (Berkeley) %G%"; +static char sccsid[] = "@(#)recvjob.c 5.15 (Berkeley) 5/4/91"; #endif /* not lint */ /* @@ -15,8 +41,8 @@ static char sccsid[] = "@(#)recvjob.c 5.12 (Berkeley) %G%"; */ #include "lp.h" -#include #include "pathnames.h" +#include char *sp = ""; #define ack() (void) write(1, sp, 1); @@ -24,10 +50,7 @@ char *sp = ""; char tfname[40]; /* tmp copy of cf before linking */ char dfname[40]; /* data files */ int minfree; /* keep at least minfree blocks available */ -char *ddev; /* disk device (for checking free space) */ -int dfd; /* file system device descriptor */ -char *find_dev(); void rcleanup(); recvjob() @@ -66,10 +89,7 @@ recvjob() } } else if (stat(SD, &stb) < 0) frecverr("%s: %s: %m", printer, SD); - minfree = read_number("minfree"); - ddev = find_dev(stb.st_dev, S_IFBLK); - if ((dfd = open(ddev, O_RDONLY)) < 0) - syslog(LOG_WARNING, "%s: %s: %m", printer, ddev); + minfree = 2 * read_number("minfree"); /* scale KB to 512 blocks */ signal(SIGTERM, rcleanup); signal(SIGPIPE, rcleanup); @@ -77,36 +97,6 @@ recvjob() printjob(); } -char * -find_dev(dev, type) - register dev_t dev; - register int type; -{ - register DIR *dfd = opendir(_PATH_DEV); - struct direct *dir; - struct stat stb; - char devname[MAXNAMLEN+6]; - char *dp; - - strcpy(devname, _PATH_DEV); - while ((dir = readdir(dfd))) { - strcpy(devname + 5, dir->d_name); - if (stat(devname, &stb)) - continue; - if ((stb.st_mode & S_IFMT) != type) - continue; - if (dev == stb.st_rdev) { - closedir(dfd); - dp = (char *)malloc(strlen(devname)+1); - strcpy(dp, devname); - return(dp); - } - } - closedir(dfd); - frecverr("cannot find device %d, %d", major(dev), minor(dev)); - /*NOTREACHED*/ -} - /* * Read printer jobs sent by lpd and copy them to the spooling directory. * Return the number of jobs successfully transfered. @@ -179,7 +169,8 @@ readjob() } (void) strcpy(dfname, cp); if (index(dfname, '/')) - frecverr("illegal path name"); + frecverr("readjob: %s: illegal path name", + dfname); (void) readfile(dfname, size); continue; } @@ -199,9 +190,9 @@ readfile(file, size) register int i, j, amt; int fd, err; - fd = open(file, O_WRONLY|O_CREAT, FILMOD); + fd = open(file, O_CREAT|O_EXCL|O_WRONLY, FILMOD); if (fd < 0) - frecverr("%s: %m", file); + frecverr("readfile: %s: illegal path name: %m", file); ack(); err = 0; for (i = 0; i < size; i += BUFSIZ) { @@ -254,14 +245,14 @@ chksize(size) int size; { int spacefree; - struct fs fs; + struct statfs sfb; - if (dfd < 0 || lseek(dfd, (long)(SBOFF), 0) < 0) - return(1); - if (read(dfd, (char *)&fs, sizeof fs) != sizeof fs) - return(1); - spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 1024; - size = (size + 1023) / 1024; + if (statfs(".", &sfb) < 0) { + syslog(LOG_ERR, "%s: %m", "statfs(\".\")"); + return (1); + } + spacefree = sfb.f_bavail * (sfb.f_fsize / 512); + size = (size + 511) / 512; if (minfree + size > spacefree) return(0); return(1);