1

Just experimenting with dtruss/dtrace here. I have this command:

sudo dtruss node server.js &> my-dtruss.log

that log looks like this: https://gist.github.com/ORESoftware/9b4d47682a8f0ec25330c02b4ef3ea2d

my question is, if my NODE_ENV var is set, why is it unset for child processes of dtruss command? and how can I set env variables for the node process?

my node server crashes if NODE_ENV is not set, so that's why I assume the dtruss output ends and does not continue.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 2
    It's more likely that `sudo` is dropping NODE_ENV from the environment before `dtruss` runs. Try running `sudo NODE_ENV="$NODE_ENV" dtruss node server.js` to have `sudo` set NODE_ENV in the environment that is inherited by `dtruss`. – ottomeister Mar 02 '18 at 06:26
  • cool that seems to work, pls add an answer to receive full compensation...any idea why sudo drops env vars like that? not sure if I have seen that happen before..weird – Alexander Mills Mar 02 '18 at 06:30
  • Thanks for the offer, but I'll just leave it as a comment -- I wasn't certain that that was what was happening. By default `sudo` only carries a handful of well-known environment variables into the command it executes. It has policy settings that control how strict it is, so maybe those settings have been relaxed on systems where you've used `sudo` in the past. You can use `sudo -E` to ask for your complete environment to be carried forward, but that only works if the policy setting allows it. As always, `man sudo` has the details. – ottomeister Mar 02 '18 at 06:40

0 Answers0