Browse Source

Wow, this works

Defaults!/home/girish/tmp/node-process/child.js env_keep="HOME BOX_ENV"
Defaults!/home/girish/tmp/node-process/child.js closefrom_override
girish ALL=(ALL) NOPASSWD:SETENV: /home/girish/tmp/node-process/child.js

I was almost going to use some TCP connection ...
Girish Ramakrishnan 11 months ago
parent
commit
02eda2809c
2 changed files with 11 additions and 5 deletions
  1. 8 4
      child.js
  2. 3 1
      sudo_parent.js

+ 8 - 4
child.js

@@ -8,10 +8,14 @@ fs.writeFileSync('/tmp/childoutput', 'child did start', 'utf8');
 
 console.log('child is starting', process.pid);
 
-// process.on('disconnect', function () {
-//     console.log('looks like the parent died!');
-//     process.exit(1);
-// });
+process.on('disconnect', function () {
+     console.log('looks like the parent died!');
+     process.exit(1);
+});
+
+process.on('message', function (msg) {
+    console.log(msg, ' child!');
+});
 
 setTimeout(function () {
     console.log('child is ending');

+ 3 - 1
sudo_parent.js

@@ -4,10 +4,12 @@ let child_process = require('child_process');
 
 console.log('parent is starting', process.pid);
 
-let cp = child_process.spawn('/usr/bin/sudo', [ '-SE', __dirname + '/child.js' ], { stdio: [ 0, 1, 2, 'ipc' ] });
+let cp = child_process.spawn('/usr/bin/sudo', [ '-SE', '-C', 5, __dirname + '/child.js' ], { stdio: [ 0, 1, 2, 'ipc' ] });
 cp.on('exit', function (code, signal) {
     console.log('This is end of child', code, signal);
 });
 
+cp.send({ msg: 'omg, i do not' });
+
 setTimeout(function () {
 }, 4000);