summaryrefslogtreecommitdiffstats
path: root/sbin/ddb
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2008-03-05 17:51:06 +0000
committerbrooks <brooks@FreeBSD.org>2008-03-05 17:51:06 +0000
commit4f09dc4a2c5f046226a2d25e87b16412e5c4431d (patch)
treef096d2c4db6bde8b814cfb0a64ef1e765e4e0647 /sbin/ddb
parenta43ebd515c88be9d501daa673f803853d1a715e1 (diff)
downloadFreeBSD-src-4f09dc4a2c5f046226a2d25e87b16412e5c4431d.zip
FreeBSD-src-4f09dc4a2c5f046226a2d25e87b16412e5c4431d.tar.gz
Add the ability to read a file of commands to ddb(8) modeled after the
feature in ipfw(8).
Diffstat (limited to 'sbin/ddb')
-rw-r--r--sbin/ddb/ddb.814
-rw-r--r--sbin/ddb/ddb.c72
2 files changed, 81 insertions, 5 deletions
diff --git a/sbin/ddb/ddb.8 b/sbin/ddb/ddb.8
index b233143..9f355f2 100644
--- a/sbin/ddb/ddb.8
+++ b/sbin/ddb/ddb.8
@@ -43,6 +43,8 @@
.Nm
.Cm unscript
.Ar scriptname
+.Nm
+.Ar pathname
.Sh DESCRIPTION
.Nm
configures certain aspects of the
@@ -51,6 +53,18 @@ kernel debugger from user space that are not configured at compile-time or
easily via
.Xr sysctl 8
MIB entries.
+.Pp
+To ease configuration, commands can be put in a file which is processed using
+.Nm
+as shown in the last synopsis line.
+An absolute
+.Ar pathname
+must be used.
+The file will be read line by line and applied as arguments to the
+.Nm
+utility.
+Whitespace at the beginning of lines will be ignored as will lines where the
+first non-whitespace character is #.
.Sh SCRIPTING
.Nm
can be used to configure aspects of
diff --git a/sbin/ddb/ddb.c b/sbin/ddb/ddb.c
index 9ca0d57..869e34c 100644
--- a/sbin/ddb/ddb.c
+++ b/sbin/ddb/ddb.c
@@ -27,13 +27,18 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+#include <unistd.h>
#include "ddb.h"
+void ddb_readfile(char *file);
+void ddb_main(int argc, char *argv[]);
+
void
usage(void)
{
@@ -46,15 +51,58 @@ usage(void)
exit(EX_USAGE);
}
-int
-main(int argc, char *argv[])
+void
+ddb_readfile(char *filename)
{
+ char buf[BUFSIZ];
+ FILE* f;
+
+ if ((f = fopen(filename, "r")) == NULL)
+ err(EX_UNAVAILABLE, "fopen: %s", filename);
+
+#define WHITESP " \t"
+#define MAXARG 2
+ while (fgets(buf, BUFSIZ, f)) {
+ int argc = 0;
+ char *argv[MAXARG];
+ size_t spn;
+
+ spn = strlen(buf);
+ if (buf[spn-1] == '\n')
+ buf[spn-1] = '\0';
+
+ spn = strspn(buf, WHITESP);
+ argv[0] = buf + spn;
+ if (*argv[0] == '#' || *argv[0] == '\0')
+ continue;
+ argc++;
+
+ spn = strcspn(argv[0], WHITESP);
+ argv[1] = argv[0] + spn + strspn(argv[0] + spn, WHITESP);;
+ argv[0][spn] = '\0';
+ if (*argv[1] != '\0')
+ argc++;
+
+#ifdef DEBUG
+ {
+ int i;
+ printf("argc = %d\n", argc);
+ for (i = 0; i < argc; i++) {
+ printf("arg[%d] = %s\n", i, argv[i]);
+ }
+ }
+#endif
+ ddb_main(argc, argv);
+ }
+}
- if (argc < 2)
+void
+ddb_main(int argc, char *argv[])
+{
+
+ if (argc < 1)
usage();
- argc -= 1;
- argv += 1;
if (strcmp(argv[0], "script") == 0)
ddb_script(argc, argv);
else if (strcmp(argv[0], "scripts") == 0)
@@ -63,5 +111,19 @@ main(int argc, char *argv[])
ddb_unscript(argc, argv);
else
usage();
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ /*
+ * If we've only got one argument and it's an absolute path to a file,
+ * interpret as a file to be read in.
+ */
+ if (argc == 2 && argv[1][0] == '/' && access(argv[1], R_OK) == 0)
+ ddb_readfile(argv[1]);
+ else
+ ddb_main(argc-1, argv+1);
exit(EX_OK);
}
OpenPOWER on IntegriCloud