mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +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:
@@ -286,10 +286,10 @@ duk_ret_t ILibDuktape_ChildProcess_execFile(duk_context *ctx)
|
||||
// Options
|
||||
spawnType = (ILibProcessPipe_SpawnTypes)Duktape_GetIntPropertyValue(ctx, i, "type", (int)ILibProcessPipe_SpawnTypes_DEFAULT);
|
||||
uid = Duktape_GetIntPropertyValue(ctx, i, "uid", -1);
|
||||
if (Duktape_GetBooleanProperty(ctx, i, "detached", 0) != 0) { spawnType = ILibProcessPipe_SpawnTypes_POSIX_DETACHED; }
|
||||
#ifdef WIN32
|
||||
if (uid >= 0 && spawnType == ILibProcessPipe_SpawnTypes_USER) { spawnType = ILibProcessPipe_SpawnTypes_SPECIFIED_USER; }
|
||||
#endif
|
||||
if (Duktape_GetBooleanProperty(ctx, i, "detached", 0) != 0) { spawnType |= ILibProcessPipe_SpawnTypes_POSIX_DETACHED; }
|
||||
if (duk_has_prop_string(ctx, i, "env"))
|
||||
{
|
||||
int ecount = 0;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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_Object* retVal = NULL;
|
||||
int needSetSid = ((spawnType & ILibProcessPipe_SpawnTypes_POSIX_DETACHED) == ILibProcessPipe_SpawnTypes_POSIX_DETACHED);
|
||||
if (needSetSid != 0) { spawnType ^= ILibProcessPipe_SpawnTypes_POSIX_DETACHED; }
|
||||
|
||||
#ifdef WIN32
|
||||
STARTUPINFOA info = { 0 };
|
||||
@@ -760,10 +762,11 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
DWORD sessionId;
|
||||
HANDLE token = NULL, userToken = NULL, procHandle = NULL;
|
||||
int allocParms = 0;
|
||||
|
||||
|
||||
ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
|
||||
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_DEFAULT)
|
||||
{
|
||||
@@ -899,7 +902,18 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
retVal->stdOut = ILibProcessPipe_CreatePipe(pipeManager, 4096, (ILibProcessPipe_GenericBrokenPipeHandler)ILibProcessPipe_Process_BrokenPipeSink, extraMemorySize);
|
||||
retVal->stdOut->mProcess = retVal;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
if (needSetSid == 0)
|
||||
{
|
||||
pid = vfork();
|
||||
}
|
||||
else
|
||||
{
|
||||
pid = fork();
|
||||
}
|
||||
#else
|
||||
pid = vfork();
|
||||
#endif
|
||||
}
|
||||
if (pid < 0)
|
||||
{
|
||||
@@ -942,7 +956,7 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
{
|
||||
ignore_result(setuid((uid_t)UID));
|
||||
}
|
||||
if (spawnType == ILibProcessPipe_SpawnTypes_POSIX_DETACHED)
|
||||
if (needSetSid != 0)
|
||||
{
|
||||
ignore_result(setsid());
|
||||
}
|
||||
@@ -954,6 +968,7 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
execv(target, parameters);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if (spawnType != ILibProcessPipe_SpawnTypes_TERM && spawnType != ILibProcessPipe_SpawnTypes_DETACHED)
|
||||
{
|
||||
close(retVal->stdIn->mPipe_ReadEnd);
|
||||
|
||||
@@ -41,7 +41,7 @@ typedef enum ILibProcessPipe_SpawnTypes
|
||||
ILibProcessPipe_SpawnTypes_TERM = 3,
|
||||
ILibProcessPipe_SpawnTypes_DETACHED = 4,
|
||||
ILibProcessPipe_SpawnTypes_SPECIFIED_USER = 5,
|
||||
ILibProcessPipe_SpawnTypes_POSIX_DETACHED=6
|
||||
ILibProcessPipe_SpawnTypes_POSIX_DETACHED = 0x8000
|
||||
}ILibProcessPipe_SpawnTypes;
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -398,39 +398,8 @@ function macos_messageBox()
|
||||
this.client.uninstall = function ()
|
||||
{
|
||||
// Need to uninstall ourselves
|
||||
console.log('uninstall');
|
||||
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();
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
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 });
|
||||
child.waitExit();
|
||||
};
|
||||
return (this.client);
|
||||
};
|
||||
@@ -460,10 +429,10 @@ function macos_messageBox()
|
||||
|
||||
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(); });"]
|
||||
});
|
||||
require('service-manager').manager.getLaunchAgent(options.tmpServiceName).load(options.uid);
|
||||
require('service-manager').manager.getLaunchAgent(options.tmpServiceName, ret.uid).load();
|
||||
|
||||
return (ret);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user