get-uid-gid.js 644 B

123456789101112131415161718192021222324
  1. if (module !== require.main) {
  2. throw new Error("This file should not be loaded with require()")
  3. }
  4. if (!process.getuid || !process.getgid) {
  5. throw new Error("this file should not be called without uid/gid support")
  6. }
  7. var argv = process.argv.slice(2)
  8. , user = argv[0] || process.getuid()
  9. , group = argv[1] || process.getgid()
  10. if (!isNaN(user)) user = +user
  11. if (!isNaN(group)) group = +group
  12. console.error([user, group])
  13. try {
  14. process.setgid(group)
  15. process.setuid(user)
  16. console.log(JSON.stringify({uid:+process.getuid(), gid:+process.getgid()}))
  17. } catch (ex) {
  18. console.log(JSON.stringify({error:ex.message,errno:ex.errno}))
  19. }