Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-01-22 02:28:06 +0300
committerisaacs <i@izs.me>2011-02-08 04:09:04 +0300
commita9cf93f79d9a601d004521ae8246c2bda6e84da2 (patch)
tree5c5d49afca041883fc7cf72c263d0b160730baa2 /bin
parent3ac631279c64329b33ba51065f17d819d923ab82 (diff)
Specify uid and gid to script runner
Diffstat (limited to 'bin')
-rw-r--r--bin/npm-script-runner.js37
1 files changed, 16 insertions, 21 deletions
diff --git a/bin/npm-script-runner.js b/bin/npm-script-runner.js
index 6b4fdef9b..bfc323c6c 100644
--- a/bin/npm-script-runner.js
+++ b/bin/npm-script-runner.js
@@ -1,31 +1,26 @@
-#!/usr/bin/env/ node
+#!/usr/bin/env node
-// Run a command as nobody
+// Run a command as a specific user.
// env is passed through untouched.
-// usage: npm-script-runner $folder $uid "make test"
+// usage: npm-script-runner $folder $uid $gid "make test"
// This is internal plumbing
-console.error(process.argv)
-
var argv = process.argv.slice(2)
, cwd = argv.shift()
- , cmd = argv.shift()
, uid = argv.shift()
+ , gid = argv.shift()
+ , cmd = argv.shift()
, stdio = process.binding("stdio")
+ , cp = require("child_process")
-try {
- process.setuid(uid)
-} catch (ex) {
- console.error("Could not setuid to "+uid)
- throw ex
-}
-
+process.setgid(gid)
+process.setuid(uid)
-require("child_process").spawn( "sh", ["-c", cmd]
- , { env : process.env
- , cwd : cwd
- , customFDs: [ stdio.stdinFD
- , stdio.stdoutFD
- , stdio.stderrFD ]
- })
- .on("exit", function (c) { process.exit(c) })
+cp.spawn( "sh", ["-c", cmd]
+ , { env : process.env
+ , cwd : cwd
+ , customFds: [ stdio.stdinFD
+ , stdio.stdoutFD
+ , stdio.stderrFD ]
+ } )
+ .on("exit", function (c) { process.exit(c) })