Exemple #1
0
            public static void RemoveChildProcessState(UnixChildProcessState childProcessState)
            {
                Debug.Assert(childProcessState._refCount == 0);

                lock (ChildProcessState)
                {
                    ChildProcessState.Remove(childProcessState.Token);
                }
            }
Exemple #2
0
            public static UnixChildProcessState Create()
            {
                var token = IssueProcessToken();
                var state = new UnixChildProcessState(token);

                lock (ChildProcessState)
                {
                    ChildProcessState.Add(token, state);
                }
                return(state);
        private static void ProcessNotification(ref ChildExitNotification notification)
        {
            if (!UnixChildProcessState.TryGetChildProcessState(notification.Token, out var holder))
            {
                return;
            }

            using (holder)
            {
                if (holder.State.HasExitCode)
                {
                    Trace.WriteLine("warning: Multiple ChildExitNotification delivered to one process.");
                }
                else
                {
                    // TODO: Status may be a signal number.
                    holder.State.SetExited(notification.Status);
                }
            }
        }
Exemple #4
0
        private static void ProcessNotification(ref ChildExitNotification notification)
        {
            if (!UnixChildProcessState.TryGetChildProcessState(notification.Token, out var holder))
            {
                // Ignore. This is a process where exec failed and we already reported that failure.
                return;
            }

            using (holder)
            {
                if (holder.State.HasExitCode)
                {
                    Trace.WriteLine("warning: Multiple ChildExitNotification delivered to one process.");
                }
                else
                {
                    // TODO: Status may be a signal number.
                    holder.State.SetExited(notification.Status);
                }
            }
        }
Exemple #5
0
 public UnixChildProcessStateHolder(UnixChildProcessState state)
 {
     _state = state;
 }
Exemple #6
0
        public IChildProcessStateHolder SpawnProcess(
            ref ChildProcessStartInfoInternal startInfo,
            string resolvedPath,
            SafeHandle stdIn,
            SafeHandle stdOut,
            SafeHandle stdErr)
        {
            var arguments            = startInfo.Arguments;
            var environmentVariables = startInfo.EnvironmentVariables;
            var workingDirectory     = startInfo.WorkingDirectory;

            Span <int> fds         = stackalloc int[3];
            int        handleCount = 0;
            uint       flags       = 0;

            if (stdIn != null)
            {
                fds[handleCount++] = stdIn.DangerousGetHandle().ToInt32();
                flags |= RequestFlagsRedirectStdin;
            }
            if (stdOut != null)
            {
                fds[handleCount++] = stdOut.DangerousGetHandle().ToInt32();
                flags |= RequestFlagsRedirectStdout;
            }
            if (stdErr != null)
            {
                fds[handleCount++] = stdErr.DangerousGetHandle().ToInt32();
                flags |= RequestFlagsRedirectStderr;
            }

            using var bw = new MyBinaryWriter(InitialBufferCapacity);
            var stateHolder = UnixChildProcessState.Create();

            try
            {
                bw.Write(0U); // Dummy length to be rewritten later
                bw.Write(stateHolder.State.Token);
                bw.Write(flags);
                bw.Write(workingDirectory);
                bw.Write(resolvedPath);

                bw.Write((uint)(arguments.Count + 1));
                bw.Write(resolvedPath);
                foreach (var x in arguments)
                {
                    bw.Write(x);
                }

                if (environmentVariables == null)
                {
                    bw.Write(0U);
                }
                else
                {
                    bw.Write((uint)environmentVariables.Count);
                    foreach (var(name, value) in environmentVariables)
                    {
                        bw.WriteEnvironmentVariable(name, value);
                    }
                }

                bw.RewritePrefixedLength();

                var subchannel = _helperProcess.RentSubchannelAsync(default).AsTask().GetAwaiter().GetResult();