Opened 9 years ago

Closed 7 years ago

#1388 closed defect (fixed)

Error parsing PID from output of "ps"

Reported by: anonymous Owned by: n8fr8
Priority: Medium Milestone:
Component: Applications/Orbot Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Orbot version: 0.2.2.10-alpha-orbot-0.0.5.apk
Android version: OpenEclair 1.3

Error log:
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): error: unable to parse 'app_92' as integer
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): java.lang.NumberFormatException: unable to parse 'app_92' as integer
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at java.lang.Integer.parse(Integer.java:374)
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at java.lang.Integer.parseInt(Integer.java:363)
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at java.lang.Integer.parseInt(Integer.java:323)
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at org.torproject.android.service.TorServiceUtils.findProcessId(TorServiceUtils.java:138)
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at org.torproject.android.service.TorService.runPrivoxyShellCmd(TorService.java:452)
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at org.torproject.android.service.TorService.access$000(TorService.java:32)
05-09 16:07:33.754: ERROR/TOR_SERVICE(26501): at org.torproject.android.service.TorService$1.run(TorService.java:384)

Description:
PID is at the first column of the output of "ps":

PID USER VSZ STAT COMMAND

22263 app_92 2736 S /data/data/org.torproject.android/tor -f /data/data/

OpenEclair uses BusyBox. Perhaps the output order is different.

Child Tickets

Change History (7)

comment:1 Changed 9 years ago by atagar

Nathan: Hi, I'm not sure off hand what the issue is but arm runs into similar problems (needing to guess the tor process id). In my case I use ps as a last resort, doing the following:

  1. "pidof tor"
  2. "netstat -npl | grep 127.0.0.1:%s" % <tor control port>
  3. "ps -o pid -C tor"

With pidof and ps I discard the results if there's multiple tor instances (since the second is the only one that'll account for the currently used control port). Hope this helps! -Damian

comment:2 Changed 9 years ago by atagar

Oh, and forgot to mention that a "info/pid" GETINFO option is a currently mothballed proposal:
http://archives.seul.org/or/dev/Apr-2010/msg00005.html

so another 'fix' might be to finally implement that option... -Damian

comment:3 Changed 9 years ago by n8fr8

Resolution: fixed
Status: newclosed

i have added support for 'pidof' as the first check, and then move to 'ps' as the second. hopefully that will solve the OpenEclair issue.

comment:4 Changed 9 years ago by n8fr8

Resolution: fixed
Status: closedreopened

mikos on IRC reports this may not be working;

os> n8fr8: About that bug - I have looked at TorServiceUtils.java, method findProcessIdWithPidOf, and it _can't_ work in my opinion. It is starting "procPs = r.exec(SHELL_CMD_PIDOF);", but you must tell program name to pidof.
<n8fr8> but it does work sometimes, right?
<mikos> n8fr8: It should IMHO be something like "procPs = r.exec(SHELL_CMD_PIDOF + ' ' + command);". But maybe I am wrong, I am not Java programmer (only Pythoneer)...
--> katmagic (~katmagic@…) has joined #tor
<-- gouki has quit (Remote host closed the connection)
<n8fr8> okay i will reopen the ticket and look at it myself shortly. working on an orbot update for release soon and can send you a build as well.
<mikos> n8fr8: No, it doesn't for me... it tries also findProcessIdWithPS, but this will fail too, because PID is in first column in ps output but it expects second column

n8fr8: Maybe some other Android builds have ps with another output format?

--> gouki (~gouki@…) has joined #tor
<mikos> n8fr8: But anyway findProcessIdWithPidOf IMHO really could't work (and never did, if it was always same)

comment:5 Changed 9 years ago by n8fr8

Owner: set to n8fr8
Status: reopenedassigned

atagar says: n8fr8, mikos: sorry, just skimming but I've found that pgrep is better for getting the pid than pidof (for an example and alternatives see http://tor.pastebin.com/3fa86rPW)

comment:6 Changed 9 years ago by atagar

Pending Tor: 0.2.3.x-final Orbot will be able to reliably fetch the pid from the control port, as per:
https://trac.torproject.org/projects/tor/ticket/2291

Cheers! -Damian

comment:7 Changed 7 years ago by n8fr8

Resolution: fixed
Status: assignedclosed

good on this now

Note: See TracTickets for help on using tickets.