1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-14 15:23:39 +00:00

1. Updated MacOS, so detached child process uses fork instead of vfork

2. Updated detached to be a bitmask on the type
3. Updated MacOS message-box cleanup
This commit is contained in:
Bryan Roe
2019-06-04 13:06:17 -07:00
parent 3ab7316172
commit f15c11c845
5 changed files with 45 additions and 60 deletions

View File

@@ -286,10 +286,10 @@ duk_ret_t ILibDuktape_ChildProcess_execFile(duk_context *ctx)
// Options // Options
spawnType = (ILibProcessPipe_SpawnTypes)Duktape_GetIntPropertyValue(ctx, i, "type", (int)ILibProcessPipe_SpawnTypes_DEFAULT); spawnType = (ILibProcessPipe_SpawnTypes)Duktape_GetIntPropertyValue(ctx, i, "type", (int)ILibProcessPipe_SpawnTypes_DEFAULT);
uid = Duktape_GetIntPropertyValue(ctx, i, "uid", -1); uid = Duktape_GetIntPropertyValue(ctx, i, "uid", -1);
if (Duktape_GetBooleanProperty(ctx, i, "detached", 0) != 0) { spawnType = ILibProcessPipe_SpawnTypes_POSIX_DETACHED; }
#ifdef WIN32 #ifdef WIN32
if (uid >= 0 && spawnType == ILibProcessPipe_SpawnTypes_USER) { spawnType = ILibProcessPipe_SpawnTypes_SPECIFIED_USER; } if (uid >= 0 && spawnType == ILibProcessPipe_SpawnTypes_USER) { spawnType = ILibProcessPipe_SpawnTypes_SPECIFIED_USER; }
#endif #endif
if (Duktape_GetBooleanProperty(ctx, i, "detached", 0) != 0) { spawnType |= ILibProcessPipe_SpawnTypes_POSIX_DETACHED; }
if (duk_has_prop_string(ctx, i, "env")) if (duk_has_prop_string(ctx, i, "env"))
{ {
int ecount = 0; int ecount = 0;

File diff suppressed because one or more lines are too long

View File

@@ -751,6 +751,8 @@ void ILibProcessPipe_Process_SoftKill(ILibProcessPipe_Process p)
ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_Manager pipeManager, char* target, char* const* parameters, ILibProcessPipe_SpawnTypes spawnType, void *sid, void *envvars, int extraMemorySize) ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_Manager pipeManager, char* target, char* const* parameters, ILibProcessPipe_SpawnTypes spawnType, void *sid, void *envvars, int extraMemorySize)
{ {
ILibProcessPipe_Process_Object* retVal = NULL; ILibProcessPipe_Process_Object* retVal = NULL;
int needSetSid = ((spawnType & ILibProcessPipe_SpawnTypes_POSIX_DETACHED) == ILibProcessPipe_SpawnTypes_POSIX_DETACHED);
if (needSetSid != 0) { spawnType ^= ILibProcessPipe_SpawnTypes_POSIX_DETACHED; }
#ifdef WIN32 #ifdef WIN32
STARTUPINFOA info = { 0 }; STARTUPINFOA info = { 0 };
@@ -764,6 +766,7 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION)); ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&info, sizeof(STARTUPINFOA)); ZeroMemory(&info, sizeof(STARTUPINFOA));
if (spawnType != ILibProcessPipe_SpawnTypes_SPECIFIED_USER && spawnType != ILibProcessPipe_SpawnTypes_DEFAULT && (sessionId = WTSGetActiveConsoleSessionId()) == 0xFFFFFFFF) { return(NULL); } // No session attached to console, but requested to execute as logged in user if (spawnType != ILibProcessPipe_SpawnTypes_SPECIFIED_USER && spawnType != ILibProcessPipe_SpawnTypes_DEFAULT && (sessionId = WTSGetActiveConsoleSessionId()) == 0xFFFFFFFF) { return(NULL); } // No session attached to console, but requested to execute as logged in user
if (spawnType != ILibProcessPipe_SpawnTypes_DEFAULT) if (spawnType != ILibProcessPipe_SpawnTypes_DEFAULT)
{ {
@@ -899,8 +902,19 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
retVal->stdOut = ILibProcessPipe_CreatePipe(pipeManager, 4096, (ILibProcessPipe_GenericBrokenPipeHandler)ILibProcessPipe_Process_BrokenPipeSink, extraMemorySize); retVal->stdOut = ILibProcessPipe_CreatePipe(pipeManager, 4096, (ILibProcessPipe_GenericBrokenPipeHandler)ILibProcessPipe_Process_BrokenPipeSink, extraMemorySize);
retVal->stdOut->mProcess = retVal; retVal->stdOut->mProcess = retVal;
} }
#ifdef __APPLE__
if (needSetSid == 0)
{
pid = vfork(); pid = vfork();
} }
else
{
pid = fork();
}
#else
pid = vfork();
#endif
}
if (pid < 0) if (pid < 0)
{ {
if (spawnType != ILibProcessPipe_SpawnTypes_DETACHED) if (spawnType != ILibProcessPipe_SpawnTypes_DETACHED)
@@ -942,7 +956,7 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
{ {
ignore_result(setuid((uid_t)UID)); ignore_result(setuid((uid_t)UID));
} }
if (spawnType == ILibProcessPipe_SpawnTypes_POSIX_DETACHED) if (needSetSid != 0)
{ {
ignore_result(setsid()); ignore_result(setsid());
} }
@@ -954,6 +968,7 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
execv(target, parameters); execv(target, parameters);
_exit(1); _exit(1);
} }
if (spawnType != ILibProcessPipe_SpawnTypes_TERM && spawnType != ILibProcessPipe_SpawnTypes_DETACHED) if (spawnType != ILibProcessPipe_SpawnTypes_TERM && spawnType != ILibProcessPipe_SpawnTypes_DETACHED)
{ {
close(retVal->stdIn->mPipe_ReadEnd); close(retVal->stdIn->mPipe_ReadEnd);

View File

@@ -41,7 +41,7 @@ typedef enum ILibProcessPipe_SpawnTypes
ILibProcessPipe_SpawnTypes_TERM = 3, ILibProcessPipe_SpawnTypes_TERM = 3,
ILibProcessPipe_SpawnTypes_DETACHED = 4, ILibProcessPipe_SpawnTypes_DETACHED = 4,
ILibProcessPipe_SpawnTypes_SPECIFIED_USER = 5, ILibProcessPipe_SpawnTypes_SPECIFIED_USER = 5,
ILibProcessPipe_SpawnTypes_POSIX_DETACHED=6 ILibProcessPipe_SpawnTypes_POSIX_DETACHED = 0x8000
}ILibProcessPipe_SpawnTypes; }ILibProcessPipe_SpawnTypes;
#ifdef WIN32 #ifdef WIN32

View File

@@ -398,39 +398,8 @@ function macos_messageBox()
this.client.uninstall = function () this.client.uninstall = function ()
{ {
// Need to uninstall ourselves // Need to uninstall ourselves
console.log('uninstall'); var child = require('child_process').execFile(process.execPath, [process.execPath.split('/').pop(), '-exec', "var s=require('service-manager').manager.getLaunchAgent('" + this._options.service + "', " + this._options.uid + "); s.unload(); require('fs').unlinkSync(s.plist);process.exit();"], { detached: true, type: require('child_process').SpawnTypes.DETACHED });
var s;
try
{
s = require('service-manager').manager.getLaunchAgent(this._options.service);
}
catch (ee)
{
console.log('LaunchAgent not found');
return; // Nothing to do if the service doesn't exist
}
var child = require('child_process').execFile('/bin/sh', ['sh'], { detached: true });
if (this._options.osversion.compareTo('10.10') < 0)
{
// Just unload
console.log('launchctl unload ' + s.plist + '\nrm ' + s.plist + '\nexit\n');
child.stdin.write('launchctl unload ' + s.plist + '\nrm ' + s.plist + '\nexit\n');
}
else
{
// Use bootout
console.log('launchctl bootout gui/' + this._options.uid + ' ' + s.plist + '\nrm ' + s.plist + '\nexit\n');
child.stdin.write('launchctl bootout gui/' + this._options.uid + ' ' + s.plist + '\nrm ' + s.plist + '\nexit\n');
}
try
{
child.waitExit(); child.waitExit();
}
catch (e)
{
}
}; };
return (this.client); return (this.client);
}; };
@@ -460,10 +429,10 @@ function macos_messageBox()
require('service-manager').manager.installLaunchAgent( require('service-manager').manager.installLaunchAgent(
{ {
name: options.tmpServiceName, servicePath: process.execPath, startType: 'AUTO_START', name: options.tmpServiceName, servicePath: process.execPath, startType: 'AUTO_START', uid: ret.uid,
sessionTypes: ['Aqua'], parameters: ['-exec', "require('message-box').startClient({ path: '" + options.path + "', service: '" + options.tmpServiceName + "' }).on('end', function () { process.exit(); }).on('error', function () { process.exit(); });"] sessionTypes: ['Aqua'], parameters: ['-exec', "require('message-box').startClient({ path: '" + options.path + "', service: '" + options.tmpServiceName + "' }).on('end', function () { process.exit(); }).on('error', function () { process.exit(); });"]
}); });
require('service-manager').manager.getLaunchAgent(options.tmpServiceName).load(options.uid); require('service-manager').manager.getLaunchAgent(options.tmpServiceName, ret.uid).load();
return (ret); return (ret);
}; };