1

I've been calling virsh from my .Net Core console app in Linux using Proccess.start for many month but suddenly I get a permission error:

Permission denied
at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setUser, UInt32 userId, UInt32 groupId, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean shouldThrow)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at wconfig.Menus.MAIN.Test(Object& Obj)
  • I run my .Net Core app as root
  • I can run virsh commands fine from shell
  • I can run virsh commands fine with Process.Start if I use bash -c MyVirshCmd...
  • I can run other commands in my .Net Core app fine, I've only seen the problem with virsh

Something strange is happening in the native .net core function ForkAndExecProcess and virsh.

.Net Core code example:

Dim PI As New ProcessStartInfo
PI.RedirectStandardOutput = False
PI.FileName = "virsh"
PI.Arguments = "list --all"
Using proc As New Process
  proc.StartInfo = PI
  proc.Start()
End Using

In the /etc/libvirt/qemu.conf config file it says The user for QEMU processes run by the system instance.? I've tried to set user and group in the file to "root" but it didn't help.

In desperation I tried to restart server, didn't help of course.
I cannot think of anything that has changed on the server, it just stopped working yesterday out of the blue.
Using Debian Buster (10)
I'm lost?

MrCalvin
  • 1,675
  • 1
  • 19
  • 27
  • Normally you should have a separate user for running qemu, most people create a user called `qemu`. Have you checked permissions, aka that root has permission to execute, all relevant executables? – PiRocks Sep 10 '19 at 09:54
  • But if root doesn't have the necessary rights, I assume I would see the permission error when running the command in the shell, right? – MrCalvin Sep 10 '19 at 20:03
  • I was concerned that you where not running the command from root yourself. Though it appears you have resolved the problem, so my comment is no longer relevant. – PiRocks Sep 11 '19 at 12:30

1 Answers1

0

YES, I got it!
By using strace -f -o /tmp/strace.txt MyDotNetApp I could see dotnet was executing /root/virsh??.
As it turns out this file existed for some reason and was 0KB!
Apparently dotnet has another path search order than the shell, so dotnet executed /root/virsh whereas shell executed the real virsh in /usr/bin/virsh.
GOSH...this could have taking me a long time to find, well it did, but it could have taking month (scarry)!

By the was my system environment PATH is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

So it seems dotnet uses its own "path" :-(

MrCalvin
  • 1,675
  • 1
  • 19
  • 27