File ltrace.trunk-r46.patch of Package ltrace
------------------------------------------------------------------------
r46 | ianw-guest | 2006-07-17 21:18:35 +0000 (Mon, 17 Jul 2006) | 3 lines
Changed paths:
M /ltrace/trunk/ChangeLog
M /ltrace/trunk/etc/ltrace.conf
M /ltrace/trunk/ltrace.1
M /ltrace/trunk/ltrace.c
M /ltrace/trunk/options.c
M /ltrace/trunk/options.h
add -F option to read in config files
Steve Fink <sphink@gmail.com>
------------------------------------------------------------------------
---
ChangeLog | 5 +++++
etc/ltrace.conf | 5 +++++
ltrace.1 | 6 ++++++
ltrace.c | 31 +++++++++++++++++--------------
options.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
options.h | 7 +++++++
6 files changed, 94 insertions(+), 16 deletions(-)
Index: options.h
===================================================================
--- options.h.orig
+++ options.h
@@ -31,6 +31,11 @@ struct opt_e_t {
struct opt_e_t *next;
};
+struct opt_F_t {
+ char *filename;
+ struct opt_F_t *next;
+};
+
struct opt_x_t {
char *name;
int found;
@@ -42,6 +47,8 @@ extern struct opt_p_t *opt_p; /* attach
extern struct opt_e_t *opt_e; /* list of function names to display */
extern int opt_e_enable; /* 0 if '!' is used, 1 otherwise */
+extern struct opt_F_t *opt_F; /* alternate configuration file(s) */
+
extern struct opt_x_t *opt_x; /* list of functions to break at */
extern char **process_options(int argc, char **argv);
Index: ChangeLog
===================================================================
--- ChangeLog.orig
+++ ChangeLog
@@ -1,3 +1,8 @@
+2006-07-16 Steve Fink <sphink@gmail.com>
+
+ * options.c: implement -F flag for alternate config file(s)
+ * ltrace.c: load SYSCONFDIR/ltrace.conf and ~/.ltrace.conf by default
+
2006-06-19 Ian Wienand <ianw@ieee.org>
* sysdeps/linux-gnu/mksyscallent: update, fix for ia64
Index: ltrace.c
===================================================================
--- ltrace.c.orig
+++ ltrace.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <pwd.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
@@ -18,10 +19,6 @@
#include "options.h"
#include "debug.h"
-#ifndef SYSCONFDIR
-#define SYSCONFDIR "/etc"
-#endif
-
char *command = NULL;
struct process *list_of_processes = NULL;
@@ -98,7 +95,6 @@ static void guess_cols(void)
int main(int argc, char **argv)
{
struct opt_p_t *opt_p_tmp;
- char *home;
atexit(normal_exit);
signal(SIGINT, signal_exit); /* Detach processes when interrupted */
@@ -106,17 +102,24 @@ int main(int argc, char **argv)
guess_cols();
argv = process_options(argc, argv);
- read_config_file(SYSCONFDIR "/ltrace.conf");
- home = getenv("HOME");
- if (home) {
+ while (opt_F) {
+ /* If filename begins with ~, expand it to the user's home */
+ /* directory. This does not correctly handle ~yoda, but that */
+ /* isn't as bad as it seems because the shell will normally */
+ /* be doing the expansion for us; only the hardcoded */
+ /* ~/.ltrace.conf should ever use this code. */
+ if (opt_F->filename[0] == '~') {
char path[PATH_MAX];
- if (strlen(home) > PATH_MAX - 15) {
- fprintf(stderr, "Error: $HOME too long\n");
- exit(1);
- }
- strcpy(path, getenv("HOME"));
- strcat(path, "/.ltrace.conf");
+ char *home_dir = getpwuid(geteuid())->pw_dir;
+ strncpy(path, home_dir, PATH_MAX - 1);
+ path[PATH_MAX - 1] = '\0';
+ strncat(path, opt_F->filename + 1,
+ PATH_MAX - strlen(path) - 1);
read_config_file(path);
+ } else {
+ read_config_file(opt_F->filename);
+ }
+ opt_F = opt_F->next;
}
if (opt_e) {
struct opt_e_t *tmp = opt_e;
Index: ltrace.1
===================================================================
--- ltrace.1.orig
+++ ltrace.1
@@ -62,6 +62,12 @@ currently traced processes as a result
or clone(2) system calls.
The new process is attached as soon as its pid is known.
.TP
+.I \-F
+Load an alternate config file. Normally, /etc/ltrace.conf and
+~/.ltrace.conf will be read (the latter only if it exists).
+Use this option to load the given file or files instead of
+those two default files.
+.TP
.I \-h, \-\-help
Show a summary of the options to ltrace and exit.
.TP
Index: etc/ltrace.conf
===================================================================
--- etc/ltrace.conf.orig
+++ etc/ltrace.conf
@@ -1,4 +1,9 @@
; ltrace.conf
+;
+; ~/.ltrace.conf will also be read, if it exists. The -F option may be
+; used to suppress the automatic inclusion of both this file and
+; ~/.ltrace.conf, and load a different config file or config files
+; instead.
; Argument types:
; + == May vary (ie, is a returned value) (prefix)
Index: options.c
===================================================================
--- options.c.orig
+++ options.c
@@ -21,6 +21,13 @@
#include "options.h"
#include "defs.h"
+#ifndef SYSCONFDIR
+#define SYSCONFDIR "/etc"
+#endif
+
+#define SYSTEM_CONFIG_FILE SYSCONFDIR "/trace.conf"
+#define USER_CONFIG_FILE "~/.ltrace.conf"
+
#define MAX_LIBRARY 30
char *library[MAX_LIBRARY];
int library_num = 0;
@@ -53,6 +60,9 @@ int opt_e_enable = 1;
/* List of global function names given to -x: */
struct opt_x_t *opt_x = NULL;
+/* List of filenames give to option -F: */
+struct opt_F_t *opt_F = NULL; /* alternate configuration file(s) */
+
#ifdef PLT_REINITALISATION_BP
/* Set a break on the routine named here in order to re-initialize breakpoints
after all the PLTs have been initialzed */
@@ -88,6 +98,12 @@ static void usage(void)
" -e expr modify which events to trace.\n"
" -f follow forks.\n"
# if HAVE_GETOPT_LONG
+ " -F, --config=FILE load alternate configuration file\n"
+# else
+ " -F FILE load alternate configuration file\n"
+# endif
+ " (can be repeated).\n"
+# if HAVE_GETOPT_LONG
" -h, --help display this help and exit.\n"
# else
" -h display this help and exit.\n"
@@ -174,6 +190,7 @@ char **process_options(int argc, char **
int option_index = 0;
static struct option long_options[] = {
{"align", 1, 0, 'a'},
+ {"config", 1, 0, 'F'},
{"debug", 0, 0, 'd'},
# ifdef USE_DEMANGLE
{"demangle", 0, 0, 'C'},
@@ -189,14 +206,14 @@ char **process_options(int argc, char **
# ifdef USE_DEMANGLE
"C"
# endif
- "a:e:l:n:o:p:s:u:x:X:", long_options,
+ "a:e:F:l:n:o:p:s:u:x:X:", long_options,
&option_index);
#else
c = getopt(argc, argv, "+cdfhiLrStTV"
# ifdef USE_DEMANGLE
"C"
# endif
- "a:e:l:n:o:p:s:u:x:X:");
+ "a:e:F:l:n:o:p:s:u:x:X:");
#endif
if (c == -1) {
break;
@@ -252,6 +269,18 @@ char **process_options(int argc, char **
case 'f':
opt_f = 1;
break;
+ case 'F':
+ {
+ struct opt_F_t *tmp = malloc(sizeof(struct opt_F_t));
+ if (!tmp) {
+ perror("ltrace: malloc");
+ exit(1);
+ }
+ tmp->filename = strdup(optarg);
+ tmp->next = opt_F;
+ opt_F = tmp;
+ break;
+ }
case 'h':
usage();
exit(0);
@@ -371,6 +400,29 @@ char **process_options(int argc, char **
argv += optind;
#endif
+ if (!opt_F) {
+ opt_F = malloc(sizeof(struct opt_F_t));
+ opt_F->next = malloc(sizeof(struct opt_F_t));
+ opt_F->next->next = NULL;
+ opt_F->filename = USER_CONFIG_FILE;
+ opt_F->next->filename = SYSTEM_CONFIG_FILE;
+ }
+ /* Reverse the config file list since it was built by
+ * prepending, and it would make more sense to process the
+ * files in the order they were given. Probably it would make
+ * more sense to keep a tail pointer instead? */
+ {
+ struct opt_F_t *egg = NULL;
+ struct opt_F_t *chicken;
+ while (opt_F) {
+ chicken = opt_F->next;
+ opt_F->next = egg;
+ egg = opt_F;
+ opt_F = chicken;
+ }
+ opt_F = egg;
+ }
+
if (!opt_p && argc < 1) {
fprintf(stderr, "%s: too few arguments\n", progname);
usage();