Re: move ckqueue function to common.c - tweaked and proper diff

2016-02-29 Thread Jeremie Courreges-Anglas

Committed, thanks.

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: move ckqueue function to common.c - tweaked and proper diff

2016-02-28 Thread Chris Bennett

Index: usr.sbin/lpr/common_source/common.c
===
RCS file: /cvs/src/usr.sbin/lpr/common_source/common.c,v
retrieving revision 1.40
diff -u -p -r1.40 common.c
--- usr.sbin/lpr/common_source/common.c 12 Jan 2016 23:35:13 -  1.40
+++ usr.sbin/lpr/common_source/common.c 28 Feb 2016 20:11:18 -
@@ -453,3 +453,32 @@ safe_open(const char *path, int flags, m
(void)fchmod(fd, mode);
return (fd);
 }
+
+/*
+ * Make sure there's some work to do before forking off a child - lpd
+ * Check to see if anything in queue - lpq
+ */
+int
+ckqueue(char *cap)
+{
+   struct dirent *d;
+   DIR *dirp;
+   char *spooldir;
+
+   if (cgetstr(cap, "sd", ) >= 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);
+}
Index: usr.sbin/lpr/common_source/lp.h
===
RCS file: /cvs/src/usr.sbin/lpr/common_source/lp.h,v
retrieving revision 1.20
diff -u -p -r1.20 lp.h
--- usr.sbin/lpr/common_source/lp.h 12 Jan 2016 23:35:13 -  1.20
+++ usr.sbin/lpr/common_source/lp.h 28 Feb 2016 20:11:19 -
@@ -120,6 +120,7 @@ struct dirent;
 
 /* common.c */
 char   *checkremote(void);
+int ckqueue(char *);
 voidfatal(const char *, ...)
 __attribute__((__noreturn__,__format__(__printf__, 1, 2)));
 int get_line(FILE *);
Index: usr.sbin/lpr/lpd/lpd.c
===
RCS file: /cvs/src/usr.sbin/lpr/lpd/lpd.c,v
retrieving revision 1.63
diff -u -p -r1.63 lpd.c
--- usr.sbin/lpr/lpd/lpd.c  19 Dec 2015 19:59:07 -  1.63
+++ usr.sbin/lpr/lpd/lpd.c  28 Feb 2016 20:11:20 -
@@ -107,7 +107,6 @@ static void mcleanup(int);
 static voiddoit(void);
 static voidstartup(void);
 static voidchkhost(struct sockaddr *);
-static int ckqueue(char *);
 static __dead void usage(void);
 static int *socksetup(int, int, const char *);
 
@@ -593,35 +592,6 @@ startup(void)
free(buf);
}
}
-}
-
-/*
- * 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", ) >= 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);
 }
 
 /*
Index: usr.sbin/lpr/lpq/lpq.c
===
RCS file: /cvs/src/usr.sbin/lpr/lpq/lpq.c,v
retrieving revision 1.22
diff -u -p -r1.22 lpq.c
--- usr.sbin/lpr/lpq/lpq.c  9 Feb 2015 23:00:14 -   1.22
+++ usr.sbin/lpr/lpq/lpq.c  28 Feb 2016 20:11:22 -
@@ -64,7 +64,6 @@ intusers; /* # of users in user arra
 
 volatile sig_atomic_t gotintr;
 
-static int ckqueue(char *);
 static __dead void usage(void);
 
 int
@@ -146,32 +145,6 @@ main(int argc, char **argv)
} else
displayq(lflag);
exit(0);
-}
-
-/* XXX - could be common w/ lpd */
-static int
-ckqueue(char *cap)
-{
-   struct dirent *d;
-   DIR *dirp;
-   char *spooldir;
-
-   if (cgetstr(cap, "sd", ) >= 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);
 }
 
 static __dead void