summaryrefslogtreecommitdiff
path: root/sudo_linux.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-07 04:55:46 -0500
committerJeff Carr <[email protected]>2025-10-07 04:55:46 -0500
commit46d67313cff2fc06975a53059f38555bc04d820e (patch)
tree925d128416c8d7779acb831465053b6b757e0b2e /sudo_linux.go
parent8c15048135fbf64592aa9fe31466ed09d520d2b0 (diff)
add sudo but it doesn't work and isn't rightv0.0.29
Diffstat (limited to 'sudo_linux.go')
-rw-r--r--sudo_linux.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/sudo_linux.go b/sudo_linux.go
new file mode 100644
index 0000000..0ef3995
--- /dev/null
+++ b/sudo_linux.go
@@ -0,0 +1,62 @@
+package fhelp
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "syscall"
+)
+
+func osSudoRaw(c []string) {
+ args := []string{"-S"}
+ args = append(args, c...)
+ cmd := exec.Command("sudo", args...)
+
+ // Assign the current process's standard input, output, and error
+ cmd.Stderr = os.Stderr
+ cmd.Stdout = os.Stdout
+ cmd.Stdin = os.Stdin
+
+ // Ensure the process has a terminal session
+ cmd.SysProcAttr = &syscall.SysProcAttr{
+ Setsid: true, // Start a new session
+ }
+
+ err := cmd.Run()
+ if err != nil {
+ fmt.Println("Command execution failed:", err)
+ }
+}
+
+func osSudo(c []string) error {
+ args := []string{"-S"}
+ // args := []string{}
+ args = append(args, c...)
+ cmd := exec.Command("sudo", args...)
+
+ // Open the terminal device directly to preserve input/output control
+ tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
+ if err != nil {
+ fmt.Println("Failed to open /dev/tty:", err)
+ return err
+ }
+ defer tty.Close()
+
+ // Assign the TTY explicitly
+ cmd.Stdin = tty
+ cmd.Stdout = tty
+ cmd.Stderr = tty
+
+ // Ensure the new process gets its own session
+ cmd.SysProcAttr = &syscall.SysProcAttr{
+ Setsid: true, // Start a new session
+ }
+
+ // Run the command
+ if err := cmd.Run(); err != nil {
+ fmt.Println("Command execution failed:", err)
+ }
+
+ fmt.Println("\nProcess finished. TTY restored.")
+ return nil
+}