This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specify uid and gid to script runner
- Loading branch information
Showing
2 changed files
with
20 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters