Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 226491 - Remotetools don't recognize all used ports from remote host
Summary: Remotetools don't recognize all used ports from remote host
Status: RESOLVED FIXED
Alias: None
Product: PTP
Classification: Tools
Component: Remote Tools (show other bugs)
Version: 2.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.0.1   Edit
Assignee: Greg Watson CLA
QA Contact: Greg Watson CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-10 08:25 EDT by Daniel Henrique Barboza CLA
Modified: 2011-01-31 08:18 EST (History)
1 user (show)

See Also:


Attachments
Patch fixing the described bug. (2.98 KB, patch)
2008-04-10 08:25 EDT, Daniel Henrique Barboza CLA
no flags Details | Diff
Simplier patch. (2.14 KB, patch)
2008-04-10 13:17 EDT, Daniel Henrique Barboza CLA
g.watson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Henrique Barboza CLA 2008-04-10 08:25:55 EDT
Created attachment 95509 [details]
Patch fixing the described bug.

Build ID: M20080221-1800

Steps To Reproduce:
Remotetools uses (on linux systems) the output of /proc/net/<networkProtocol> to check used ports. A problem was detected on that procedure, ignoring the first valid entry of the output of that file, losing the information of one connection.


More information:

The problem is solved on attached patch.
Comment 1 Daniel Henrique Barboza CLA 2008-04-10 13:17:52 EDT
Created attachment 95554 [details]
Simplier patch.
Comment 2 Daniel Felix Ferber CLA 2008-04-10 13:21:43 EDT
Thanks Daniel HB. The patch solves this issue.
Comment 3 Greg Watson CLA 2008-04-10 14:59:08 EDT
Reopening so I can apply the patch. I'm assuming I should apply the second one?
Comment 4 Daniel Henrique Barboza CLA 2008-04-10 15:18:57 EDT
Yes, apply the second one.
Comment 5 Greg Watson CLA 2008-04-11 09:37:21 EDT
Applied. 

I noticed that this code is very architecture specific. e.g. MacOS X does not have a /proc/net device, so this may produce unexpected results on a non-Linux system. I'm wondering if (a) you should check the operating system first (e.g. uname -a), or (b) use a more generic method of finding the ports. I think one way would be to use 'netstat'.

On MacOS X:

netstat -a -n -p tcp | tail -n +3 | sed 's/  */ /g' | cut -d ' ' -f 4 | sed 's/.*\.\([0-9][0-9]*\)$/\1/' | sort -n | uniq

On Linux:

netstat -a -n -t | tail -n +3 | sed 's/  */ /g' | cut -d ' ' -f 4 | sed 's/.*:\([0-9][0-9]*\)$/\1/' | sort -n | uniq

Comments?
Comment 6 Daniel Felix Ferber CLA 2008-04-11 10:32:41 EDT
Currenly we support only Linux hosts, since we do not have a Mac OS for testing.

We decided to prefer querying /proc devices instead of executables (like netstat)  since we had several concerns.

1) Output of executable is often locale dependent and may break parsing on non English environment.
2) For performance reasons, we don't want to call a pipe of executables on the remote host, since this query might be called several times in a short period of time.
3) /proc produces data that is closer targeted to data that we want to query. Therefore, no filtering isrequired on the remote host, nor on the local, that improves performance.
3) Nearly no parsing is required for /proc. 

Does Mac OS have a /proc like devices to query system information?
Comment 7 Leonardo Garcia CLA 2008-04-11 10:38:53 EDT
Other good question here in my opinion is: does Windows or others OS matter for PTP?

Because then even the solution using netstat should not work.
Comment 8 Greg Watson CLA 2008-04-11 11:36:09 EDT
MacOS X does not have the equivalent of /proc, so the only way to get this information is running a command (netstat or lsof are the only ones I know about). I agree parsing output is problematic.

PTP currently supports both Linux and MacOS X as targets, but not Windows. It's possible that we might support Windows as a target in the future, but for now it's not required.

I think the the point I'm making here is that the method does not necessarily have to support MacOS X (although this would be nice), but should at least deal with non-Linux targets gracefully. It should also be documented as only working on Linux, if this is the case.
Comment 9 Daniel Felix Ferber CLA 2008-05-21 13:19:27 EDT
Greg, would you agree if I close this bug and open other one to discuss the /proc issue separately?
Comment 10 Greg Watson CLA 2008-05-21 13:58:52 EDT
Before it's closed, I think the StatusTools class needs either a comment that it will only work if the target host is Linux, or you need to check for the string "No such file or directory" when you execute the command, or both. Feel free to open another bug for the /proc issue.
Comment 11 Greg Watson CLA 2010-01-27 13:42:45 EST
Added comment to HEAD.