bin/56648: [PATCH] enable rcorder(8) to use a directory for
locating config files
Lukas Ertl
l.ertl at univie.ac.at
Tue Sep 9 11:50:12 PDT 2003
>Number: 56648
>Category: bin
>Synopsis: [PATCH] enable rcorder(8) to use a directory for locating config files
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Tue Sep 09 11:50:09 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Lukas Ertl
>Release: FreeBSD 5.1-CURRENT i386
>Organization:
Vienna University Computer Center
>Environment:
System: FreeBSD korben 5.1-CURRENT FreeBSD 5.1-CURRENT #16: Sun Sep 7 18:12:54 CEST 2003 le at korben:/usr/obj/usr/src/sys/KORBEN i386
>Description:
The attached patch enables rcorder(8) to use "-D <directory>" to locate
the configuration files instead of passing in all configuration filenames
via a shell glob.
>How-To-Repeat:
>Fix:
--- rcorder.diff begins here ---
Index: sbin/rcorder/rcorder.8
===================================================================
RCS file: /usr/local/bsdcvs/src/sbin/rcorder/rcorder.8,v
retrieving revision 1.3
diff -u -r1.3 rcorder.8
--- sbin/rcorder/rcorder.8 25 Nov 2002 16:23:03 -0000 1.3
+++ sbin/rcorder/rcorder.8 9 Sep 2003 18:35:46 -0000
@@ -41,7 +41,7 @@
.Nm
.Op Fl k Ar keep
.Op Fl s Ar skip
-.Ar
+.Fl D Ar directory | Ar
.Sh DESCRIPTION
The
.Nm
@@ -104,6 +104,10 @@
If any
.Fl s
option is given, files containing the matching keyword are not listed.
+.It Fl D
+Instead of listing all filenames on the command line, use the files
+located in the specified
+.Ar directory .
.El
.Pp
An example block follows:
Index: sbin/rcorder/rcorder.c
===================================================================
RCS file: /usr/local/bsdcvs/src/sbin/rcorder/rcorder.c,v
retrieving revision 1.2
diff -u -r1.2 rcorder.c
--- sbin/rcorder/rcorder.c 7 Sep 2003 14:17:17 -0000 1.2
+++ sbin/rcorder/rcorder.c 7 Sep 2003 17:54:59 -0000
@@ -37,8 +37,10 @@
__FBSDID("$FreeBSD: src/sbin/rcorder/rcorder.c,v 1.2 2003/09/07 14:17:17 charnier Exp $");
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/stat.h>
+#include <dirent.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
@@ -150,16 +152,24 @@
void initialize(void);
void generate_ordering(void);
int main(int, char *[]);
+int get_files(char *, char ***);
int
main(argc, argv)
int argc;
char *argv[];
{
- int ch;
+ char *directory;
+ int ch, Dflag;
- while ((ch = getopt(argc, argv, "dk:s:")) != -1)
+ Dflag = 0;
+
+ while ((ch = getopt(argc, argv, "D:dk:s:")) != -1)
switch (ch) {
+ case 'D':
+ Dflag = 1;
+ directory = optarg;
+ break;
case 'd':
#ifdef DEBUG
debug = 1;
@@ -180,8 +190,12 @@
argc -= optind;
argv += optind;
- file_count = argc;
- file_list = argv;
+ if (Dflag) {
+ file_count = get_files(directory, &file_list);
+ } else {
+ file_count = argc;
+ file_list = argv;
+ }
DPRINTF((stderr, "parse_args\n"));
initialize();
@@ -192,6 +206,37 @@
DPRINTF((stderr, "generate_ordering\n"));
exit(exit_code);
+}
+
+int
+get_files(char *dir, char ***list)
+{
+ char *fname;
+ DIR *dirp;
+ int count, i;
+ struct dirent *entry;
+
+ count = 0;
+
+ if (dir[strlen(dir)-1] == '/')
+ dir[strlen(dir)-1] = '\0';
+
+ if ((dirp = opendir(dir)) == NULL)
+ return 0;
+
+ while ((entry = readdir(dirp)) != NULL) {
+ if (strcmp(entry->d_name, ".") == 0 ||
+ strcmp(entry->d_name, "..") == 0)
+ continue;
+ fname = emalloc(MAXPATHLEN);
+ snprintf(fname, MAXPATHLEN, "%s/%s", dir, entry->d_name);
+ *list = erealloc(*list, (count+1)*sizeof(char *));
+ (*list)[count] = fname;
+ count++;
+ }
+ closedir(dirp);
+
+ return count;
}
/*
--- rcorder.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list