protected TerminalLauncher(string title, string initScript, ReadOnlyCollection <EnvironmentEntry> environment) { _title = title; _initScript = initScript; _environment = environment; _isRoot = UnixNativeMethods.GetEUid() == 0; }
internal static string MakeFifo(string identifier = null, Logger logger = null) { string path = Path.Combine(Path.GetTempPath(), Utilities.GetMIEngineTemporaryFilename(identifier)); // Mod is normally in octal, but C# has no octal values. This is 384 (rw owner, no rights anyone else) const int rw_owner = 384; byte[] pathAsBytes = new byte[Encoding.UTF8.GetByteCount(path) + 1]; Encoding.UTF8.GetBytes(path, 0, path.Length, pathAsBytes, 0); int result = UnixNativeMethods.MkFifo(pathAsBytes, rw_owner); if (result != 0) { // Failed to create the fifo. Bail. logger?.WriteLine("Failed to create fifo"); throw new ArgumentException("MakeFifo failed to create fifo at path {0}", path); } return(path); }
internal static string GetDebuggerCommand(LocalLaunchOptions localOptions) { string quotedDebuggerPath = String.Format(CultureInfo.InvariantCulture, "\"{0}\"", localOptions.MIDebuggerPath); if (PlatformUtilities.IsLinux()) { string debuggerPathCorrectElevation = quotedDebuggerPath; string prompt = string.Empty; // If running as root, make sure the new console is also root. bool isRoot = UnixNativeMethods.GetEUid() == 0; // If the system doesn't allow a non-root process to attach to another process, try to run GDB as root if (localOptions.ProcessId.HasValue && !isRoot && UnixUtilities.GetRequiresRootAttach(localOptions.DebuggerMIMode)) { prompt = String.Format(CultureInfo.CurrentCulture, "echo -n '{0}'; read yn; if [ \"$yn\" != 'y' ] && [ \"$yn\" != 'Y' ] ; then exit 1; fi; ", MICoreResources.Warn_AttachAsRootProcess); // Prefer pkexec for a nice graphical prompt, but fall back to sudo if it's not available if (File.Exists(UnixUtilities.PKExecPath)) { debuggerPathCorrectElevation = String.Concat(UnixUtilities.PKExecPath, " ", debuggerPathCorrectElevation); } else if (File.Exists(UnixUtilities.SudoPath)) { debuggerPathCorrectElevation = String.Concat(UnixUtilities.SudoPath, " ", debuggerPathCorrectElevation); } else { Debug.Fail("Root required to attach, but no means of elevating available!"); } } return(String.Concat(prompt, debuggerPathCorrectElevation)); } else { return(quotedDebuggerPath); } }
internal static bool IsProcessRunning(int processId) { // When getting the process group ID, getpgid will return -1 // if there is no process with the ID specified. return(UnixNativeMethods.GetPGid(processId) >= 0); }