mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
Add support for Luckfox PicoKVM
Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
118
native_linux.go
118
native_linux.go
@@ -24,23 +24,119 @@ func (w *nativeOutput) Write(p []byte) (n int, err error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func startNativeBinary(binaryPath string) (*exec.Cmd, error) {
|
||||
// Run the binary in the background
|
||||
func startVideoBinary(binaryPath string) (*exec.Cmd, error) {
|
||||
// Run the binary inthe background
|
||||
cmd := exec.Command(binaryPath)
|
||||
|
||||
nativeOutputLock := sync.Mutex{}
|
||||
nativeStdout := &nativeOutput{
|
||||
mu: &nativeOutputLock,
|
||||
logger: nativeLogger.Info().Str("pipe", "stdout"),
|
||||
vidoeOutputLock := sync.Mutex{}
|
||||
videoStdout := &nativeOutput{
|
||||
mu: &vidoeOutputLock,
|
||||
logger: videoLogger.Info().Str("pipe", "stdout"),
|
||||
}
|
||||
nativeStderr := &nativeOutput{
|
||||
mu: &nativeOutputLock,
|
||||
logger: nativeLogger.Info().Str("pipe", "stderr"),
|
||||
videoStderr := &nativeOutput{
|
||||
mu: &vidoeOutputLock,
|
||||
logger: videoLogger.Info().Str("pipe", "stderr"),
|
||||
}
|
||||
|
||||
// Redirect stdout and stderr to the current process
|
||||
cmd.Stdout = nativeStdout
|
||||
cmd.Stderr = nativeStderr
|
||||
cmd.Stdout = videoStdout
|
||||
cmd.Stderr = videoStderr
|
||||
|
||||
// Set the process group ID so we can kill the process and its children when this process exits
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
Pdeathsig: syscall.SIGKILL,
|
||||
}
|
||||
|
||||
// Start the command
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, fmt.Errorf("failed to start binary: %w", err)
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func startAudioBinary(binaryPath string) (*exec.Cmd, error) {
|
||||
// Run the binary inthe background
|
||||
cmd := exec.Command(binaryPath)
|
||||
|
||||
audioOutputLock := sync.Mutex{}
|
||||
audioStdout := &nativeOutput{
|
||||
mu: &audioOutputLock,
|
||||
logger: audioLogger.Info().Str("pipe", "stdout"),
|
||||
}
|
||||
audioStderr := &nativeOutput{
|
||||
mu: &audioOutputLock,
|
||||
logger: audioLogger.Info().Str("pipe", "stderr"),
|
||||
}
|
||||
|
||||
// Redirect stdout and stderr to the current process
|
||||
cmd.Stdout = audioStdout
|
||||
cmd.Stderr = audioStderr
|
||||
|
||||
// Set the process group ID so we can kill the process and its children when this process exits
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
Pdeathsig: syscall.SIGKILL,
|
||||
}
|
||||
|
||||
// Start the command
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, fmt.Errorf("failed to start binary: %w", err)
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func startVpnBinary(binaryPath string) (*exec.Cmd, error) {
|
||||
// Run the binary inthe background
|
||||
cmd := exec.Command(binaryPath)
|
||||
|
||||
vpnOutputLock := sync.Mutex{}
|
||||
vpnStdout := &nativeOutput{
|
||||
mu: &vpnOutputLock,
|
||||
logger: audioLogger.Info().Str("pipe", "stdout"),
|
||||
}
|
||||
vpnStderr := &nativeOutput{
|
||||
mu: &vpnOutputLock,
|
||||
logger: audioLogger.Info().Str("pipe", "stderr"),
|
||||
}
|
||||
|
||||
// Redirect stdout and stderr to the current process
|
||||
cmd.Stdout = vpnStdout
|
||||
cmd.Stderr = vpnStderr
|
||||
|
||||
// Set the process group ID so we can kill the process and its children when this process exits
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
Pdeathsig: syscall.SIGKILL,
|
||||
}
|
||||
|
||||
// Start the command
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, fmt.Errorf("failed to start binary: %w", err)
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func startDisplayBinary(binaryPath string) (*exec.Cmd, error) {
|
||||
// Run the binary inthe background
|
||||
cmd := exec.Command(binaryPath)
|
||||
|
||||
displayOutputLock := sync.Mutex{}
|
||||
displayStdout := &nativeOutput{
|
||||
mu: &displayOutputLock,
|
||||
logger: displayLogger.Info().Str("pipe", "stdout"),
|
||||
}
|
||||
displayStderr := &nativeOutput{
|
||||
mu: &displayOutputLock,
|
||||
logger: displayLogger.Info().Str("pipe", "stderr"),
|
||||
}
|
||||
|
||||
//// Redirect stdout and stderr to the current process
|
||||
cmd.Stdout = displayStdout
|
||||
cmd.Stderr = displayStderr
|
||||
|
||||
// Set the process group ID so we can kill the process and its children when this process exits
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
|
||||
Reference in New Issue
Block a user