private void SetParentProcessExitCallback(IDictionary <string, string> argsDictionary)
        {
            // Attach to exit of parent process
            var hasParentProcessArgument = CommandLineArgumentsHelper.TryGetIntArgFromDict(argsDictionary, ParentProcessIdArgument, out var parentProcessId);

            if (!hasParentProcessArgument)
            {
                throw new ArgumentException($"Argument {ParentProcessIdArgument} was not specified.");
            }

            EqtTrace.Info("DefaultEngineInvoker.SetParentProcessExitCallback: Monitoring parent process with id: '{0}'", parentProcessId);

            if (parentProcessId == -1)
            {
                // In remote scenario we cannot monitor parent process, so we expect user to pass parentProcessId as -1
                return;
            }

            if (parentProcessId == 0)
            {
                //TODO: should there be a warning / error in this case, on windows and linux we are most likely not started by this PID 0, because it's Idle process on Windows, and Swapper on Linux, and similarly in docker
                // Trying to attach to 0 will cause access denied error on Windows
            }

            this.processHelper.SetExitCallback(
                parentProcessId,
                (obj) =>
            {
                EqtTrace.Info("DefaultEngineInvoker.SetParentProcessExitCallback: ParentProcess '{0}' Exited.",
                              parentProcessId);
                new PlatformEnvironment().Exit(1);
            });
        }
Esempio n. 2
0
        public void TryGetIntArgFromDictShouldReturnFalseIfKeyIsNotPresent()
        {
            var args = new List <string>()
            {
                "--hello", "--world"
            };
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray());

            bool found = CommandLineArgumentsHelper.TryGetIntArgFromDict(argsDictionary, "--port", out var data);

            Assert.IsFalse(found);
        }
Esempio n. 3
0
        public void TryGetIntArgFromDictShouldReturnTrueIfKeyIsPresentAndTheValue()
        {
            var args = new List <string>()
            {
                "--port", "59870"
            };
            var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args.ToArray());

            bool found = CommandLineArgumentsHelper.TryGetIntArgFromDict(argsDictionary, "--port", out var data);

            Assert.IsTrue(found);
            Assert.AreEqual(59870, data);
        }