Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753670Ab3DWAaS (ORCPT ); Mon, 22 Apr 2013 20:30:18 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:40420 "EHLO dcvr.yhbt.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752221Ab3DWAaQ (ORCPT ); Mon, 22 Apr 2013 20:30:16 -0400 Date: Tue, 23 Apr 2013 00:30:15 +0000 From: Eric Wong To: Felix Becker Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: socket file descriptor a/m/c-timestamps broken in <= 3.8.8? Message-ID: <20130423003015.GA26858@dcvr.yhbt.net> References: <5175CA2F.2030206@felixbecker.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5175CA2F.2030206@felixbecker.name> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4813 Lines: 161 Cc:-ing netdev (no comments of my own) Felix Becker wrote: > Hi, > > I tried to figure out how old my TCP connections are and took a look > at /proc//fd/ using 'ls -la' / 'stat'. > > When I'm creating a new socket in my application, the time stamps > returned by stat / ls -la are correct - as expected. After closing the > socket, the fd isn't visible in /proc//fd anymore - as expected. > When creating a new socket a few minutes later (which gets the same > number as the socket closed before), the newly created socket has the > same time stamps (access / modify / change) as the old socket - I > didn't expect this. > > When using fstat() from I'm getting 0 for a/m/c-time. > Only in /proc//fd/ i can see (the wrong) times. > > I attached a test code for reproducing the issue. In my production > environments i have new socket file descriptors which have timestamps > indicating that they are many hours old. > > Q1: is it a bug that fstat() returns 0-values for a/m/c-time? > > Q2: is it a bug that a new socket, with the file descriptor number of > an older socket which existed before, have the a/m/c-times of the old > socket in /proc//fd/? > > Best regards > > Felix > > p.s. test setup is a normal x86_64 architecture (intel xeon). > > ======================================================================= > // sockettest.c > > #include > #include > #include > #include > #include > #include > #include > #include > #include > > > void print_socket_stats(int sfd){ > struct stat socket_stats; > fstat(sfd, &socket_stats); > printf("Socket stats for socket %d\n", sfd); > printf("socket stat: st_atime: %ld\n", socket_stats.st_atime); > printf("socket stat: st_mtime: %ld\n", socket_stats.st_mtime); > printf("socket stat: st_ctime: %ld\n", socket_stats.st_ctime); > } > > void print_with_time(const char* message){ > time_t t; > time(&t); > printf("%s @ %s\n", message, ctime(&t)); > > } > > int main(int argc, char *argv[]) { > > int sfd; > > printf("pid: %d\n", getpid()); > > print_with_time("Opening socket"); > sfd = socket(AF_UNIX, SOCK_STREAM, 0); > printf("opened socket: %d\n",sfd); > print_socket_stats(sfd); > > print_with_time("sleeping 30\n"); > > sleep(30); > > printf("closing socket %d", sfd); > close(sfd); > > printf("closed socket: %d\n",sfd); > print_with_time("sleeping 61 seconds"); > > sleep(61); > > print_with_time("opening new socket"); > sfd = socket(AF_UNIX, SOCK_STREAM, 0); > printf("opened socket: %d\n",sfd); > print_socket_stats(sfd); > print_with_time("sleeping 999"); > > sleep(999); > } > > ======================================================================= > > ./sockettest & > > pid: 18267 > Opening socket @ Mon Apr 22 23:05:37 2013 > > opened socket: 3 > Socket stats for socket 3 > socket stat: st_atime: 0 > socket stat: st_mtime: 0 > socket stat: st_ctime: 0 > sleeping 30 @ Mon Apr 22 23:05:37 2013 > > >>> ls -la /proc/18267/fd/3 > lrwx------ 1 becker becker 64 Apr 22 23:05 /proc/18267/fd/3 -> > socket:[210268] > > > >>> stat /proc/18267/fd/3 > File: `/proc/18267/fd/3' -> `socket:[210268]' > Size: 64 Blocks: 0 IO Block: 1024 symbolic link > Device: 3h/3d Inode: 52177 Links: 1 > Access: (0700/lrwx------) Uid: ( 1001/ becker) Gid: ( 1001/ becker) > Access: 2013-04-22 23:05:46.179813835 +0000 > Modify: 2013-04-22 23:05:46.175813886 +0000 > Change: 2013-04-22 23:05:46.175813886 +0000 > > closing socket 3 > closed socket: 3 > > sleeping 61 seconds @ Mon Apr 22 23:06:07 2013 > > opening new socket @ Mon Apr 22 23:07:08 2013 > > opened socket: 3 > Socket stats for socket 3 > socket stat: st_atime: 0 > socket stat: st_mtime: 0 > socket stat: st_ctime: 0 > sleeping 999 @ Mon Apr 22 23:07:08 2013 > > > >>> ls -la /proc/18267/fd/3 > lrwx------ 1 becker becker 64 Apr 22 23:05 /proc/18267/fd/3 -> > socket:[210320] > > >>> stat /proc/18267/fd/3 > > > > File: `/proc/18267/fd/3' -> `socket:[210320]' > Size: 64 Blocks: 0 IO Block: 1024 symbolic link > Device: 3h/3d Inode: 52177 Links: 1 > Access: (0700/lrwx------) Uid: ( 1001/ becker) Gid: ( 1001/ becker) > Access: 2013-04-22 23:05:46.179813835 +0000 > Modify: 2013-04-22 23:05:46.175813886 +0000 > Change: 2013-04-22 23:05:46.175813886 +0000 > -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/