Do not sudo unless necessary.
This makes it easier to run the swarm_client smoke tests on
insecure systems.
R=csharp@chromium.org
BUG=
Review URL: https://chromiumcodereview.appspot.com/13736002
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/swarm_client@192600 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/trace_inputs.py b/trace_inputs.py
index 64a9d4f..26f7ab5 100755
--- a/trace_inputs.py
+++ b/trace_inputs.py
@@ -24,15 +24,16 @@
import glob
import json
import logging
-import unicodedata
import optparse
import os
import re
+import stat
import subprocess
import sys
import tempfile
import threading
import time
+import unicodedata
import weakref
## OS-specific imports
@@ -2247,11 +2248,18 @@
self._dummy_file_id, self._dummy_file_name = tempfile.mkstemp(
prefix='trace_signal_file')
+ dtrace_path = '/usr/sbin/dtrace'
+ if not os.path.isfile(dtrace_path):
+ dtrace_path = 'dtrace'
+ elif use_sudo is None and (os.stat(dtrace_path).st_mode & stat.S_ISUID):
+ # No need to sudo. For those following at home, don't do that.
+ use_sudo = False
+
# Note: do not use the -p flag. It's useless if the initial process quits
# too fast, resulting in missing traces from the grand-children. The D
# code manages the dtrace lifetime itself.
trace_cmd = [
- 'dtrace',
+ dtrace_path,
# Use a larger buffer if getting 'out of scratch space' errors.
# Ref: https://wikis.oracle.com/display/DTrace/Options+and+Tunables
'-b', '10m',