changeset 14002:af551fdf9db5

3683 pfiles shouldn't try to trace itself 3684 pfiles crashes on processes with no files 3685 getsockname should set the sa_family_t for unbound unix domain sockets 3686 pfiles shows incorrect socket information on some getsockname calls Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Garrett D'Amore <garrett@damore.org> Approved by: Gordon Ross <gwr@nexenta.com>
author Robert Mustacchi <rm@joyent.com>
date Wed, 03 Apr 2013 11:07:46 -0700
parents c55122c1831c
children d4552e4ac833
files usr/src/cmd/ptools/pfiles/pfiles.c usr/src/lib/libproc/common/Pfdinfo.c usr/src/uts/common/fs/sockfs/socktpi.c
diffstat 3 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/ptools/pfiles/pfiles.c	Tue Apr 02 13:28:58 2013 -0700
+++ b/usr/src/cmd/ptools/pfiles/pfiles.c	Wed Apr 03 11:07:46 2013 -0700
@@ -23,6 +23,9 @@
  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  */
+/*
+ * Copyright (c) 2013 Joyent, Inc.  All Rights reserved.
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -180,14 +183,10 @@
 		} else {
 			switch (gret) {
 			case G_SYS:
-			case G_SELF:
 				proc_unctrl_psinfo(&psinfo);
 				(void) printf("%d:\t%.70s\n", (int)pid,
 				    psinfo.pr_psargs);
-				if (gret == G_SYS)
-					(void) printf("  [system process]\n");
-				else
-					show_files(NULL);
+				(void) printf("  [system process]\n");
 				break;
 			default:
 				(void) fprintf(stderr, "%s: %s: %d\n",
@@ -339,11 +338,7 @@
 #ifdef _LP64
 	struct flock64_32 flock_target;
 
-	/*
-	 * Pr may be NULL when pfiles is inspecting itself, but in that case
-	 * we already know the data model of the two processes must match.
-	 */
-	if ((Pr != NULL) && (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)) {
+	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
 		copyflock(flock_target, *flock_native);
 		ret = pr_fcntl(Pr, fd, F_GETLK, &flock_target);
 		copyflock(*flock_native, flock_target);
@@ -505,6 +500,9 @@
 	char  abuf[INET6_ADDRSTRLEN];
 	const char *p;
 
+	if (len == 0)
+		return;
+
 	switch (sa->sa_family) {
 	default:
 		return;
--- a/usr/src/lib/libproc/common/Pfdinfo.c	Tue Apr 02 13:28:58 2013 -0700
+++ b/usr/src/lib/libproc/common/Pfdinfo.c	Wed Apr 03 11:07:46 2013 -0700
@@ -12,6 +12,9 @@
 /*
  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  */
+/*
+ * Copyright (c) 2013 Joyent, Inc.  All Rights reserved.
+ */
 
 #include <limits.h>
 #include <stdio.h>
@@ -159,7 +162,7 @@
 	/* NB: We walk the list backwards. */
 
 	for (fip = list_prev(&P->fd_head);
-	    fip != (void *)&P->fd_head;
+	    fip != (void *)&P->fd_head && fip != NULL;
 	    fip = list_prev(fip)) {
 		if ((rv = func(cd, &fip->fd_info)) != 0)
 			return (rv);
--- a/usr/src/uts/common/fs/sockfs/socktpi.c	Tue Apr 02 13:28:58 2013 -0700
+++ b/usr/src/uts/common/fs/sockfs/socktpi.c	Wed Apr 03 11:07:46 2013 -0700
@@ -22,6 +22,9 @@
 /*
  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
  */
+/*
+ * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
+ */
 
 #include <sys/types.h>
 #include <sys/t_lock.h>
@@ -4978,9 +4981,17 @@
 	}
 
 	if (so->so_family == AF_UNIX) {
-		/* Transport has different name space - return local info */
+		/*
+		 * Transport has different name space - return local info. If we
+		 * have enough space, let consumers know the family.
+		 */
+		if (*namelen >= sizeof (sa_family_t)) {
+			name->sa_family = AF_UNIX;
+			*namelen = sizeof (sa_family_t);
+		} else {
+			*namelen = 0;
+		}
 		error = 0;
-		*namelen = 0;
 		goto done;
 	}
 	if (!(so->so_state & SS_ISBOUND)) {