From nobody@FreeBSD.org  Mon Feb 15 18:08:16 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E8AAD10656C6
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Feb 2010 18:08:15 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id BFE6E8FC24
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Feb 2010 18:08:15 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o1FI8Fau060167
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Feb 2010 18:08:15 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o1FI8Fop060146;
	Mon, 15 Feb 2010 18:08:15 GMT
	(envelope-from nobody)
Message-Id: <201002151808.o1FI8Fop060146@www.freebsd.org>
Date: Mon, 15 Feb 2010 18:08:15 GMT
From: Yuri <yuri@tsoft.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fstat(1) doesn't work on UNIX sockets
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         143962
>Category:       bin
>Synopsis:       fstat(1) doesn't work on UNIX sockets
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 15 18:10:00 UTC 2010
>Closed-Date:    
>Last-Modified:  Wed Mar 07 07:58:14 UTC 2012
>Originator:     Yuri
>Release:        8.0-STABLE
>Organization:
n/a
>Environment:
>Description:
fstat only shows which process opened it for regular files. For UNIX
sockets it doesn't show anything. For example:
> fstat /tmp/mysql.sock
> USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W NAME

Even though there are connected clients.

>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->pluknet 
Responsible-Changed-By: pluknet 
Responsible-Changed-When: Fri Jan 27 09:58:32 UTC 2012 
Responsible-Changed-Why:  
I am working on it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143962 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/143962: commit references a PR
Date: Fri,  3 Feb 2012 09:08:07 +0000 (UTC)

 Author: pluknet
 Date: Fri Feb  3 09:07:53 2012
 New Revision: 230934
 URL: http://svn.freebsd.org/changeset/base/230934
 
 Log:
   Print the owner process for unix domain sockets when restricted to the
   specified files.
   
   PR:		bin/143962
   MFC after:	2 weeks
 
 Modified:
   head/usr.bin/fstat/fstat.c
 
 Modified: head/usr.bin/fstat/fstat.c
 ==============================================================================
 --- head/usr.bin/fstat/fstat.c	Fri Feb  3 09:06:24 2012	(r230933)
 +++ head/usr.bin/fstat/fstat.c	Fri Feb  3 09:07:53 2012	(r230934)
 @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/socketvar.h>
  #include <sys/sysctl.h>
  #include <sys/queue.h>
 +#include <sys/un.h>
  
  #include <netinet/in.h>
  
 @@ -224,28 +225,53 @@ static void
  print_file_info(struct procstat *procstat, struct filestat *fst,
      const char *uname, const char *cmd, int pid)
  {
 +	struct sockstat sock;
  	struct vnstat vn;
  	DEVS *d;
  	const char *filename;
  	int error, fsmatch = 0;
  	char errbuf[_POSIX2_LINE_MAX];
  
 +	error = 0;
  	filename = NULL;
  	if (checkfile != 0) {
 -		if (fst->fs_type != PS_FST_TYPE_VNODE &&
 -		    fst->fs_type != PS_FST_TYPE_FIFO)
 +		switch (fst->fs_type) {
 +		case PS_FST_TYPE_VNODE:
 +		case PS_FST_TYPE_FIFO:
 +			error = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
 +			break;
 +		case PS_FST_TYPE_SOCKET:
 +			error = procstat_get_socket_info(procstat, fst, &sock, errbuf);
 +			break;
 +		default:
  			return;
 -		error = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
 +		}
  		if (error != 0)
  			return;
  
  		for (d = devs; d != NULL; d = d->next)
 -			if (d->fsid == vn.vn_fsid) {
 -				fsmatch = 1;
 -				if ((unsigned)d->ino == vn.vn_fileid) {
 -					filename = d->name;
 -					break;
 +			switch (fst->fs_type) {
 +			case PS_FST_TYPE_VNODE:
 +			case PS_FST_TYPE_FIFO:			
 +				if (d->fsid == vn.vn_fsid) {
 +					fsmatch = 1;
 +					if ((unsigned)d->ino == vn.vn_fileid) {
 +						filename = d->name;
 +						break;
 +					}
 +				}
 +				break;
 +			case PS_FST_TYPE_SOCKET:
 +				if (sock.dom_family == AF_UNIX) {
 +					fsmatch = 1;
 +					if (strcmp(((struct sockaddr_un *)
 +					    (&sock.sa_local))->sun_path,
 +					    d->name) == 0) {
 +						filename = d->name;
 +						break;
 +					}
  				}
 +				break;
  			}
  		if (fsmatch == 0 || (filename == NULL && fsflg == 0))
  			return;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: pluknet 
State-Changed-When: Mon Feb 6 12:14:19 UTC 2012 
State-Changed-Why:  
This is in head. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143962 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/143962: commit references a PR
Date: Fri, 17 Feb 2012 06:26:31 +0000 (UTC)

 Author: pluknet
 Date: Fri Feb 17 06:26:11 2012
 New Revision: 231859
 URL: http://svn.freebsd.org/changeset/base/231859
 
 Log:
   MFC r230934:
   
    Print the owner process for unix domain sockets when restricted to the
    specified files.
   
   PR:		bin/143962
 
 Modified:
   stable/9/usr.bin/fstat/fstat.c
 Directory Properties:
   stable/9/usr.bin/fstat/   (props changed)
 
 Modified: stable/9/usr.bin/fstat/fstat.c
 ==============================================================================
 --- stable/9/usr.bin/fstat/fstat.c	Fri Feb 17 04:26:24 2012	(r231858)
 +++ stable/9/usr.bin/fstat/fstat.c	Fri Feb 17 06:26:11 2012	(r231859)
 @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/socketvar.h>
  #include <sys/sysctl.h>
  #include <sys/queue.h>
 +#include <sys/un.h>
  
  #include <netinet/in.h>
  
 @@ -224,28 +225,53 @@ static void
  print_file_info(struct procstat *procstat, struct filestat *fst,
      const char *uname, const char *cmd, int pid)
  {
 +	struct sockstat sock;
  	struct vnstat vn;
  	DEVS *d;
  	const char *filename;
  	int error, fsmatch = 0;
  	char errbuf[_POSIX2_LINE_MAX];
  
 +	error = 0;
  	filename = NULL;
  	if (checkfile != 0) {
 -		if (fst->fs_type != PS_FST_TYPE_VNODE &&
 -		    fst->fs_type != PS_FST_TYPE_FIFO)
 +		switch (fst->fs_type) {
 +		case PS_FST_TYPE_VNODE:
 +		case PS_FST_TYPE_FIFO:
 +			error = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
 +			break;
 +		case PS_FST_TYPE_SOCKET:
 +			error = procstat_get_socket_info(procstat, fst, &sock, errbuf);
 +			break;
 +		default:
  			return;
 -		error = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
 +		}
  		if (error != 0)
  			return;
  
  		for (d = devs; d != NULL; d = d->next)
 -			if (d->fsid == vn.vn_fsid) {
 -				fsmatch = 1;
 -				if ((unsigned)d->ino == vn.vn_fileid) {
 -					filename = d->name;
 -					break;
 +			switch (fst->fs_type) {
 +			case PS_FST_TYPE_VNODE:
 +			case PS_FST_TYPE_FIFO:			
 +				if (d->fsid == vn.vn_fsid) {
 +					fsmatch = 1;
 +					if ((unsigned)d->ino == vn.vn_fileid) {
 +						filename = d->name;
 +						break;
 +					}
 +				}
 +				break;
 +			case PS_FST_TYPE_SOCKET:
 +				if (sock.dom_family == AF_UNIX) {
 +					fsmatch = 1;
 +					if (strcmp(((struct sockaddr_un *)
 +					    (&sock.sa_local))->sun_path,
 +					    d->name) == 0) {
 +						filename = d->name;
 +						break;
 +					}
  				}
 +				break;
  			}
  		if (fsmatch == 0 || (filename == NULL && fsflg == 0))
  			return;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: pluknet 
State-Changed-When: Mon Feb 20 17:30:27 UTC 2012 
State-Changed-Why:  
Merged to 9. Merging to older branches is not planned. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143962 
State-Changed-From-To: closed->open 
State-Changed-By: pluknet 
State-Changed-When: Mon Feb 27 17:44:17 UTC 2012 
State-Changed-Why:  
Reopen until we find a better solution. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143962 
Responsible-Changed-From-To: pluknet->freebsd-bugs 
Responsible-Changed-By: pluknet 
Responsible-Changed-When: Wed Mar 7 07:57:43 UTC 2012 
Responsible-Changed-Why:  
Back to the pool. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143962 
>Unformatted:
