Chris Bennett writes:
> I am having trouble seeing how these two functions are accomplshinig the
> same thing, checking for control files in the spool.
> These files always start with cf.
>
> in lpd.c
> makes sense to me.
>
> /*
> * Make sure there's some work to do before forking off a child
> * XXX - could be common w/ lpq
> */
> static int
> ckqueue(char *cap)
> {
> struct dirent *d;
> DIR *dirp;
> char *spooldir;
>
> if (cgetstr(cap, "sd", &spooldir) >= 0) {
> dirp = opendir(spooldir);
> free(spooldir);
> } else
> dirp = opendir(_PATH_DEFSPOOL);
>
> if (dirp == NULL)
> return (-1);
> while ((d = readdir(dirp)) != NULL) {
> if (d->d_name[0] == 'c' && d->d_name[1] == 'f') {
> closedir(dirp);
> return (1); /* found a cf file */
> }
> }
> closedir(dirp);
> return (0);
> }
>
>
> in lpq.c
> does not make sense to me
>
> /* XXX - could be common w/ lpd */
> static int
> ckqueue(char *cap)
> {
> struct dirent *d;
> DIR *dirp;
> char *spooldir;
>
> if (cgetstr(cap, "sd", &spooldir) >= 0) {
> dirp = opendir(spooldir);
> free(spooldir);
> } else
> dirp = opendir(_PATH_DEFSPOOL);
>
> if (dirp == NULL)
> return (-1);
> while ((d = readdir(dirp)) != NULL) {
> if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
> continue; /* daemon control files only */
> closedir(dirp);
> return (1); /* found something */
> }
> closedir(dirp);
> return (0);
> }
>
>
> the line:
> if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
> is excluding files that start with cf,
The test is true for files names that *do not* start with "cf". The
action is "continue", ie, restart the loop. I think the code is
correct.
> yet then has the comment that daemon
> controls files are found.
> They both acccomplish the same thing of returning if there are files in the
> spool.
I agree that the lpq.c version is harder to read. Patches to:
- use the same test in both lpd and lpq (the one from lpd is nicer)
- move ckqueue() to common_source/
would be welcome IMO.
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE