Forum > Operating Systems
using RunCommand to wrap LXD linux container crashes
nomorelogic:
hello everyone
I have a problem using RunCommand (unit process); this is a special case as I am doing some testing with linux LXD containers.
My system is DEVUAN:
--- Code: ---uname -a
Linux myhost 6.1.0-30-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.124-1 (2025-01-12) x86_64 GNU/Linux
--- End code ---
LXD version:
--- Code: ---$ lxc --version
5.0.2
--- End code ---
.
The program is trivial and, once compiled, it must be launched from the shell as root user or using "sudo":
--- Code: ---sudo ./testlxc
--- End code ---
.
Below is the code.
--- Code: ---program testlxc;
uses process;
const
LXC_BIN = ‘/usr/bin/lxc’;
var AStdOut: string;
begin
Writeln(LXC_BIN + ‘ LIST ’);
RunCommand(LXC_BIN, [‘list’], AStdOut); // this works
Writeln(‘output: >>’);
Writeln(AStdOut);
Writeln(‘<<’);
Writeln(LXC_BIN + ‘ INIT ’);
RunCommand(LXC_BIN, [‘init’, ‘ubuntu:20.04’, ‘u1’], AStdOut); // here it crashes
Writeln(‘output: >>’);
Writeln(AStdOut);
Writeln(‘<<’);
end.
--- End code ---
.
The first invocation of RunCommand with parameter ‘list’ works correctly as expected.
The second invocation with parameter ‘init’, on the other hand, crashes.
The result is as follows:
--- Code: ---$ sudo ./testlxc
/usr/bin/lxc LIST
output: >>
+------+---------+------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+------+------+-----------+-----------+
| m1 | STOPPED | | CONTAINER | 0 |
+------+---------+------+------+-----------+-----------+
<<
/usr/bin/lxc INIT
--- End code ---
Running from terminal:
--- Code: ---sudo lxc list
--- End code ---
.
or
--- Code: ---sudo lxc init ubuntu:20.04 u1
--- End code ---
everything works correctly and smoothly.
I can't see where the problem lies.
Any ideas?
thanks
nomorelogic
MarkMLl:
I'd suggest that the first thing to try would be running it as root rather than using sudo.
If that fails in the same way I'd suggest supplying a couple of dummy parameters in the first RunCommand() invocation, so that you can be sure that you're comparing like with like.
I've not used LXD, but from my experience with Docker etc. I think you need to focus on whether it's RunCommand() which is crashing (i.e. before transferring control into lxc), or lxc (after control has been transferred into it) because e.g. it wants some resource which it still can't get at despite the use of sudo.
MarkMLl
nomorelogic:
thanks for your suggestions
I ran the test as root user, unfortunately not much changed
I also added some parameters to the first invocation of RunCommand
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program testlxc;uses process; const LXC_BIN = '/usr/bin/lxc'; var AStdOut: string;begin Writeln(LXC_BIN + ' LIST '); RunCommand(LXC_BIN, ['list', '-f', 'json'], AStdOut); // <- works Writeln('output: >>'); Writeln(AStdOut); Writeln('<<'); Writeln(LXC_BIN + ' INIT '); RunCommand(LXC_BIN, ['init', 'ubuntu:20.04', 'u1'], AStdOut); // <- crashes Writeln('output: >>'); Writeln(AStdOut); Writeln('<<'); end.
this is the output (executed as root)
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---# ./testlxc /usr/bin/lxc LIST output: >>[{"architecture":"x86_64","config":{"image.architecture":"amd64","image.description":"Macaroni OS Eagle Minimal amd64 (20250127_15:11)","image.os":"Macaroni OS","image.release":"current","image.serial":"20250127_15:11","image.type":"squashfs","volatile.base_image":"00e40cbff9f6be5a7524cc3ee64cc5bafe28b85e8a94cf72193450af30f2d2f5","volatile.cloud-init.instance-id":"ce50a30b-7add-4ecd-aee5-be0d7b7a0e50","volatile.eth0.hwaddr":"00:16:3e:e1:1f:8d","volatile.idmap.base":"0","volatile.idmap.current":"[{\"Isuid\":true,\"Isgid\":false,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001},{\"Isuid\":false,\"Isgid\":true,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001}]","volatile.idmap.next":"[{\"Isuid\":true,\"Isgid\":false,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001},{\"Isuid\":false,\"Isgid\":true,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001}]","volatile.last_state.idmap":"[{\"Isuid\":true,\"Isgid\":false,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001},{\"Isuid\":false,\"Isgid\":true,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001}]","volatile.last_state.power":"STOPPED","volatile.uuid":"d134e8c3-9f00-4b14-a863-a7a393e21e13"},"devices":{"sharedsrc":{"path":"/tmp","source":"/media/dati/dev/lxc/test001/","type":"disk"}},"ephemeral":false,"profiles":["default"],"stateful":false,"description":"","created_at":"2025-01-30T14:44:59.593127664Z","expanded_config":{"image.architecture":"amd64","image.description":"Macaroni OS Eagle Minimal amd64 (20250127_15:11)","image.os":"Macaroni OS","image.release":"current","image.serial":"20250127_15:11","image.type":"squashfs","volatile.base_image":"00e40cbff9f6be5a7524cc3ee64cc5bafe28b85e8a94cf72193450af30f2d2f5","volatile.cloud-init.instance-id":"ce50a30b-7add-4ecd-aee5-be0d7b7a0e50","volatile.eth0.hwaddr":"00:16:3e:e1:1f:8d","volatile.idmap.base":"0","volatile.idmap.current":"[{\"Isuid\":true,\"Isgid\":false,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001},{\"Isuid\":false,\"Isgid\":true,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001}]","volatile.idmap.next":"[{\"Isuid\":true,\"Isgid\":false,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001},{\"Isuid\":false,\"Isgid\":true,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001}]","volatile.last_state.idmap":"[{\"Isuid\":true,\"Isgid\":false,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001},{\"Isuid\":false,\"Isgid\":true,\"Hostid\":165536,\"Nsid\":0,\"Maprange\":10000001}]","volatile.last_state.power":"STOPPED","volatile.uuid":"d134e8c3-9f00-4b14-a863-a7a393e21e13"},"expanded_devices":{"eth0":{"name":"eth0","network":"lxdbr0","type":"nic"},"root":{"path":"/","pool":"default","type":"disk"},"sharedsrc":{"path":"/tmp","source":"/media/dati/dev/lxc/test001/","type":"disk"}},"name":"m1","status":"Stopped","status_code":102,"last_used_at":"2025-02-03T16:35:51.011958116Z","location":"none","type":"container","project":"default","backups":null,"state":{"status":"Stopped","status_code":102,"disk":{"root":{"usage":169681408}},"memory":{"usage":0,"usage_peak":0,"swap_usage":0,"swap_usage_peak":0},"network":null,"pid":0,"processes":0,"cpu":{"usage":0}},"snapshots":null}] <</usr/bin/lxc INIT
probably now I have to figure out if RunCommand crashes or if lxc is waiting for some resource.
The only problem I have is that I cannot debug with Lazarus as I cannot launch Lazarus as root.
MarkMLl:
--- Quote from: nomorelogic on February 06, 2025, 05:18:20 pm ---The only problem I have is that I cannot debug with Lazarus as I cannot launch Lazarus as root.
--- End quote ---
That tends to depend on the widget set, and version thereof. However a reliable workaround is to start the program using gdbserver, and attach to that using Lazarus.
MarkMLl
nomorelogic:
working using gdb at command line I got this
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---(gdb) runStarting program: /media/dev/lxc/testlxc /usr/bin/lxc LIST [Detaching after fork from child process 5888]output: >>[{"architecture":"x86_64", [...cut...] ,"snapshots":null}] <</usr/bin/lxc INIT [Detaching after fork from child process 5895]
I was reflecting on the gdb message before the crash
Detaching after fork from child process 5895
Looks like RunCommand did its job.
Navigation
[0] Message Index
[#] Next page