Skip site navigation (1)Skip section navigation (2)
Date:      Sun,  4 Aug 2002 14:41:38 +0200 (CEST)
From:      Pawel Jakub Dawidek <nick@garage.freebsd.pl>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        mdodd@FreeBSD.org
Subject:   bin/41310: Added ,,-d'' option to truss(1) for change procfs directory from ,,/proc''.
Message-ID:  <20020804124138.3C0D83ABD46@milla.ask33.net>

next in thread | raw e-mail | index | archive | help

>Number:         41310
>Category:       bin
>Synopsis:       Added ,,-d'' option to truss(1) for change procfs directory from ,,/proc''.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 04 05:50:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Pawel Jakub Dawidek
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
>Environment:
System: FreeBSD milla.ask33.net 4.6-STABLE FreeBSD 4.6-STABLE #9: Wed Jul 31 21:18:46 CEST 2002 root@milla.ask33.net:/usr/obj/usr/src/sys/MILLA i386


>Description:
	Now we cn only use truss(1) if procfs(5) is mounted in ,,/proc''
	directory. If we're mounting linprocfs(5) there (because of running
	vmware or diffrent programm that required linprocfs) or something
	like that, we can't use truss. I'm sending patch for truss from
	-STABLE branch.
>How-To-Repeat:
>Fix:

diff -ur /usr/src/usr.bin/truss/alpha-fbsd.c truss/alpha-fbsd.c
--- /usr/src/usr.bin/truss/alpha-fbsd.c	Mon Oct 29 21:12:56 2001
+++ truss/alpha-fbsd.c	Sun Aug  4 14:31:16 2002
@@ -115,7 +115,7 @@
 
 void
 alpha_syscall_entry(int pid, int nargs) {
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct reg regs = { { 0 } };
   int syscall;
   int i;
@@ -124,7 +124,7 @@
   int indir = 0;	/* indirect system call */
 
   if (fd == -1 || pid != cpid) {
-    sprintf(buf, "/proc/%d/regs", pid);
+    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
     fd = open(buf, O_RDWR);
     if (fd == -1) {
       fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
@@ -262,7 +262,7 @@
 
 void
 alpha_syscall_exit(int pid, int syscall) {
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct reg regs;
   int retval;
   int i;
@@ -270,7 +270,7 @@
   struct syscall *sc;
 
   if (fd == -1 || pid != cpid) {
-    sprintf(buf, "/proc/%d/regs", pid);
+    snprintf(buf, MAXPATHLEN, "%s/%d/regs", procpath, pid);
     fd = open(buf, O_RDONLY);
     if (fd == -1) {
       fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
diff -ur /usr/src/usr.bin/truss/i386-fbsd.c truss/i386-fbsd.c
--- /usr/src/usr.bin/truss/i386-fbsd.c	Mon Oct 29 21:12:56 2001
+++ truss/i386-fbsd.c	Sun Aug  4 14:31:15 2002
@@ -44,6 +44,7 @@
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#include <sys/param.h>
 #include <sys/pioctl.h>
 #include <sys/syscall.h>
 
@@ -67,6 +68,8 @@
 extern FILE *outfile;
 #include "syscalls.h"
 
+extern char *procpath;
+
 static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
 
 /*
@@ -112,7 +115,7 @@
 
 void
 i386_syscall_entry(int pid, int nargs) {
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct reg regs = { 0 };
   int syscall;
   int i;
@@ -120,7 +123,7 @@
   struct syscall *sc;
 
   if (fd == -1 || pid != cpid) {
-    sprintf(buf, "/proc/%d/regs", pid);
+    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
     fd = open(buf, O_RDWR);
     if (fd == -1) {
       fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
@@ -240,7 +243,7 @@
 
 void
 i386_syscall_exit(int pid, int syscall) {
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct reg regs;
   int retval;
   int i;
@@ -248,7 +251,7 @@
   struct syscall *sc;
 
   if (fd == -1 || pid != cpid) {
-    sprintf(buf, "/proc/%d/regs", pid);
+    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
     fd = open(buf, O_RDONLY);
     if (fd == -1) {
       fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
diff -ur /usr/src/usr.bin/truss/i386-linux.c truss/i386-linux.c
--- /usr/src/usr.bin/truss/i386-linux.c	Fri Feb 15 12:43:51 2002
+++ truss/i386-linux.c	Sun Aug  4 14:31:14 2002
@@ -42,6 +42,7 @@
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#include <sys/param.h>
 #include <sys/pioctl.h>
 
 #include <machine/reg.h>
@@ -65,6 +66,8 @@
 extern FILE *outfile;
 #include "linux_syscalls.h"
 
+extern char *procpath;
+
 static int nsyscalls =
 	sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);
 
@@ -92,14 +95,14 @@
 
 void
 i386_linux_syscall_entry(int pid, int nargs) {
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct reg regs = { 0 };
   int syscall;
   int i;
   struct syscall *sc;
 
   if (fd == -1 || pid != cpid) {
-    sprintf(buf, "/proc/%d/regs", pid);
+    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
     fd = open(buf, O_RDWR);
     if (fd == -1) {
       fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
@@ -198,7 +201,7 @@
 
 void
 i386_linux_syscall_exit(int pid, int syscall) {
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct reg regs;
   int retval;
   int i;
@@ -206,7 +209,7 @@
   struct syscall *sc;
 
   if (fd == -1 || pid != cpid) {
-    sprintf(buf, "/proc/%d/regs", pid);
+    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
     fd = open(buf, O_RDONLY);
     if (fd == -1) {
       fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
diff -ur /usr/src/usr.bin/truss/main.c truss/main.c
--- /usr/src/usr.bin/truss/main.c	Fri May 17 01:41:23 2002
+++ truss/main.c	Sun Aug  4 14:31:11 2002
@@ -40,6 +40,8 @@
  * do a lot of the work :).
  */
 
+#define	PROCPATH	"/proc"
+
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/pioctl.h>
@@ -64,6 +66,7 @@
 int nosigs = 0;
 FILE *outfile;
 int Procfd;
+char *procpath = NULL;
 
 static inline void
 usage(void)
@@ -103,11 +106,11 @@
 static struct ex_types *
 set_etype(void) {
   struct ex_types *funcs;
-  char etype[24];
+  char etype[MAXPATHLEN];
   char progt[32];
   int fd;
 
-  sprintf(etype, "/proc/%d/etype", pid);
+  snprintf(etype, sizeof etype, "%s/%d/etype", procpath, pid);
   if ((fd = open(etype, O_RDONLY)) == -1) {
     strcpy(progt, "FreeBSD a.out");
   } else {
@@ -140,7 +143,7 @@
   int sigexit = 0;
 
   outfile = stderr;
-  while ((c = getopt(ac, av, "p:o:S")) != -1) {
+  while ((c = getopt(ac, av, "p:o:d:S")) != -1) {
     switch (c) {
     case 'p':	/* specified pid */
       pid = atoi(optarg);
@@ -148,6 +151,9 @@
     case 'o':	/* Specified output file */
       fname = optarg;
       break;
+    case 'd':	/* Specified procfs directory */
+      procpath = optarg;
+      break;
     case 'S':	/* Don't trace signals */ 
       nosigs = 1;
       break;
@@ -164,6 +170,9 @@
     if ((outfile = fopen(fname, "w")) == NULL)
       errx(1, "cannot open %s", fname);
   }
+
+  if (procpath == NULL)
+    procpath = strdup(PROCPATH);
 
   /*
    * If truss starts the process itself, it will ignore some signals --
diff -ur /usr/src/usr.bin/truss/setup.c truss/setup.c
--- /usr/src/usr.bin/truss/setup.c	Fri Feb 15 12:43:51 2002
+++ truss/setup.c	Sun Aug  4 14:31:10 2002
@@ -55,6 +55,8 @@
 
 #include "extern.h"
 
+extern char *procpath;
+
 static int evflags = 0;
 
 /*
@@ -67,7 +69,7 @@
 int
 setup_and_wait(char *command[]) {
   struct procfs_status pfs;
-  char buf[32];
+  char buf[MAXPATHLEN];
   int fd;
   int pid;
   int flags;
@@ -78,9 +80,10 @@
   }
   if (pid == 0) {	/* Child */
     int mask = S_EXEC | S_EXIT;
-    fd = open("/proc/curproc/mem", O_WRONLY);
+    snprintf(buf, sizeof buf, "%s/curproc/mem", procpath);
+    fd = open(buf, O_WRONLY);
     if (fd == -1)
-      err(2, "cannot open /proc/curproc/mem");
+      err(2, "cannot open %s", buf);
     fcntl(fd, F_SETFD, 1);
     if (ioctl(fd, PIOCBIS, mask) == -1)
       err(3, "PIOCBIS");
@@ -107,7 +110,7 @@
     exit(1);
   }
 
-  sprintf(buf, "/proc/%d/mem", pid);
+  snprintf(buf, MAXPATHLEN, "%s/%d/mem", procpath, pid);
   if ((fd = open(buf, O_RDWR)) == -1)
     err(5, "cannot open %s", buf);
   if (ioctl(fd, PIOCWAIT, &pfs) == -1)
@@ -131,9 +134,9 @@
 int
 start_tracing(int pid, int flags) {
   int fd;
-  char buf[32];
+  char buf[MAXPATHLEN];
   struct procfs_status tmp;
-  sprintf(buf, "/proc/%d/mem", pid);
+  snprintf(buf, sizeof buf, "%s/%d/mem", procpath, pid);
 
   fd = open(buf, O_RDWR);
   if (fd == -1) {
diff -ur /usr/src/usr.bin/truss/truss.1 truss/truss.1
--- /usr/src/usr.bin/truss/truss.1	Fri Jun 21 17:29:40 2002
+++ truss/truss.1	Sun Aug  4 14:31:09 2002
@@ -10,10 +10,12 @@
 .Nm
 .Op Fl S
 .Op Fl o Ar file
+.Op Fl d Ar path
 .Fl p Ar pid
 .Nm
 .Op Fl S
 .Op Fl o Ar file
+.Op Fl d Ar path
 command
 .Op args
 .Sh DESCRIPTION
@@ -35,6 +37,10 @@
 Print the output to the specified
 .Ar file
 instead of standard error.
+.It Fl d Ar path
+Use specified
+.Ar path
+for procfs instead of ,,/proc''.
 .It Fl p Ar pid
 Follow the process specified by
 .Ar pid
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020804124138.3C0D83ABD46>