Skip to content

Comments

instance: use mkdir_p helper#32

Merged
openwrt-bot merged 1 commit intoopenwrt:mainfrom
dangowrt:procd-instance-use-mkdir_p
Feb 17, 2026
Merged

instance: use mkdir_p helper#32
openwrt-bot merged 1 commit intoopenwrt:mainfrom
dangowrt:procd-instance-use-mkdir_p

Conversation

@dangowrt
Copy link
Member

Use mkdir_p() libubox helper function to create cgroup instance directories. This simplifies instance_add_cgroup() and also avoids returning an error in case the service directory already exists.

Fixes: #31
Fixes: 7e5b324 ("instance: check length of names when creating cgroups")

Use mkdir_p() libubox helper function to create cgroup instance
directories. This simplifies instance_add_cgroup() and also avoids
returning an error in case the service directory already exists.

Fixes: openwrt#31
Fixes: 7e5b324 ("instance: check length of names when creating cgroups")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@openwrt-bot openwrt-bot merged commit 180ffcc into openwrt:main Feb 17, 2026
0 of 2 checks passed
@dangowrt dangowrt deleted the procd-instance-use-mkdir_p branch February 17, 2026 14:56
@Alexey71
Copy link

Alexey71 commented Feb 21, 2026

@dangowrt @jfranzlx Qbittorrent does not start when the /etc/qbittorrent folder already exists. If you delete the folder, it will start once. After rebooting or updating the firmware, qbittorrent it still won't start until you delete the folder.

#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1
PROG=/usr/bin/qbittorrent-nox

get_config() {
	config_get_bool enabled $1 enabled 1
	config_get port $1 port 8080
	config_get profile_dir $1 profile_dir "/etc"
}

start_service() {
	config_load qbittorrent
	config_foreach get_config qbittorrent
	[ $enabled != 1 ] && return 1
	if [ ! -f "$profile_dir/qBittorrent/config/qBittorrent.conf" ]; then
		mkdir -p $profile_dir/qBittorrent/config/
		cp /usr/share/qbittorrent/qBittorrent.conf.example $profile_dir/qBittorrent/config/qBittorrent.conf
	fi
	if [ ! -f "$profile_dir/qBittorrent/config/categories.json" ]; then
		mkdir -p $profile_dir/qBittorrent/config/
		cp /usr/share/qbittorrent/categories.json.example $profile_dir/qBittorrent/config/categories.json
	fi
	procd_open_instance
	procd_set_param command $PROG
	procd_append_param command --webui-port=$port --profile=$profile_dir
	procd_set_param respawn
	procd_close_instance
}

service_triggers() {
	procd_add_reload_trigger "qbittorrent"
}

reload_service() {
	stop
	sleep 1
	start
}
root@OpenWrt:~# /etc/init.d/qbittorrent restart
root@OpenWrt:~# logread -e qbittorrent
Thu Feb 21 20:31:09 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:31:14 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:31:20 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:31:26 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:31:31 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:31:32 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 1 seconds since last crash
Thu Feb 21 20:43:21 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:43:27 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:43:32 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:43:38 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:43:44 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:43:49 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:43:50 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 1 seconds since last crash
Thu Feb 21 20:46:45 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:46:50 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:46:56 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:47:01 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:47:07 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:47:13 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:47:14 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 0 seconds since last crash
Thu Feb 21 20:59:41 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:59:47 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:59:53 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 20:59:58 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 21:00:04 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 21:00:10 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information
Thu Feb 21 21:00:11 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 0 seconds since last crash
Thu Feb 21 21:09:53 2026 daemon.warn procd: failed adding instance cgroup for qbittorrent: No error information

@dangowrt
Copy link
Member Author

dangowrt commented Feb 21, 2026

Are you sure you are using procd after this commit?

@Alexey71
Copy link

Alexey71 commented Feb 21, 2026

What does it have to do with how cgroups instance folders are created?

After the latest changes procd, stopped working.

@dangowrt
Copy link
Member Author

dangowrt commented Feb 21, 2026

Please check which version of procd you currently got installed. 2026-02-17?
I'm asking because this very commit was supposed to fix this exact problem introduced by 2026-02-09 version.

@Alexey71
Copy link

Are you sure you are using procd after this commit?

Yes. I tried the new build today. procd | 2026.02.17~180ffccf-r1
The problem started with this commit: openwrt/openwrt@361885b

@dangowrt
Copy link
Member Author

dangowrt commented Feb 21, 2026

Interesting. Before openwrt/openwrt@361885b there wasn't any check whether cgroup for the instance is actually created, now there are several checks along the way.
For starters, can you try building procd with this change and see what the actual error is:

diff --git a/service/instance.c b/service/instance.c
index a456b8c..6e13cf5 100644
--- a/service/instance.c
+++ b/service/instance.c
@@ -677,7 +677,7 @@ instance_start(struct service_instance *in)
                ret = instance_add_cgroup(in->srv->name, in->name);
                if (ret)
                        ULOG_WARN("failed adding instance cgroup for %s: %s\n",
-                                 in->srv->name, strerror(ret));
+                                 in->srv->name, strerror((ret < 0)? -ret : ret));
 
                instance_run(in, opipe[1], epipe[1]);
                return;

@Alexey71
Copy link

Alexey71 commented Feb 21, 2026

I can't build it. After patching, error

install -m0755 /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/ipkg-install/usr/sbin/block /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/.pkgdir/block-mount/sbin/
install -m0644 /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/ipkg-install/usr/lib/libblkid-tiny.so /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/.pkgdir/block-mount/lib/
ln -sf ../../sbin/block /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/.pkgdir/block-mount/usr/sbin/swapon
ln -sf ../../sbin/block /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/.pkgdir/block-mount/usr/sbin/swapoff
touch /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/.pkgdir/block-mount.installed
mkdir -p /home/alexey/openwrt-R4/staging_dir/target-aarch64_cortex-a53_musl/root-mediatek/stamp
SHELL= flock /home/alexey/openwrt-R4/tmp/.root-copy.flock -c 'cp -fpR /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/fstools-2026.02.15~8d377aa6/.pkgdir/block-mount/. /home/alexey/openwrt-R4/staging_dir/target-aarch64_cortex-a53_musl/root-mediatek/'
touch /home/alexey/openwrt-R4/staging_dir/target-aarch64_cortex-a53_musl/root-mediatek/stamp/.block-mount_installed
echo "block-mount" >> /home/alexey/openwrt-R4/staging_dir/target-aarch64_cortex-a53_musl/pkginfo/fstools.default.install
make[2]: Leaving directory '/home/alexey/openwrt-R4/package/system/fstools'
time: package/system/fstools/compile#0.42#0.25#0.62
make[2]: Entering directory '/home/alexey/openwrt-R4/package/system/procd'
rm -f /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/.built
touch /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/.built_check
MAKEFLAGS="" /home/alexey/openwrt-R4/staging_dir/host/bin/ninja  -j1 -C /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf
ninja: Entering directory `/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf'
[1/26] Building C object CMakeFiles/procd.dir/service/instance.c.o
FAILED: [code=1] CMakeFiles/procd.dir/service/instance.c.o
/home/alexey/openwrt-R4/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/bin/aarch64-openwrt-linux-musl-gcc -DEARLY_PATH=\"/usr/sbin:/usr/bin:/sbin:/bin\" -DHAS_UDEBUG -DSECCOMP_SUPPORT  -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -fmacro-prefix-map=/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf=procd-2026.02.17~180ffccf -flto=auto -fno-fat-lto-objects -Wformat -Werror=format-security -DPIC -fPIC -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Wl,-z,pack-relative-relocs  -I/home/alexey/openwrt-R4/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/usr/include -I/home/alexey/openwrt-R4/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include -I/home/alexey/openwrt-R4/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/include/fortify -DNDEBUG   -Os -ggdb -Wall -Werror --std=gnu99 -Wmissing-declarations -MD -MT CMakeFiles/procd.dir/service/instance.c.o -MF CMakeFiles/procd.dir/service/instance.c.o.d -o CMakeFiles/procd.dir/service/instance.c.o -c '/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c'
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c: In function 'instance_start':
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:1818:2: error: unterminated argument list invoking macro "ULOG_WARN"
 1818 | }
      |  ^
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:679:25: error: 'ULOG_WARN' undeclared (first use in this function)
  679 |                         ULOG_WARN("failed adding instance cgroup for %s: %s\n",
      |                         ^~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:679:25: note: each undeclared identifier is reported only once for each function it appears in
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:679:34: error: expected ';' at end of input
  679 |                         ULOG_WARN("failed adding instance cgroup for %s: %s\n",
      |                                  ^
      |                                  ;
......
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:678:17: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
  678 |                 if (ret)
      |                 ^~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:678:17: note: adding '-flarge-source-files' will allow for more column-tracking support, at the expense of compilation time and memory
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:679:25: error: expected declaration or statement at end of input
  679 |                         ULOG_WARN("failed adding instance cgroup for %s: %s\n",
      |                         ^~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:679:25: error: expected declaration or statement at end of input
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c: At top level:
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:469:1: error: 'instance_run' defined but not used [-Werror=unused-function]
  469 | instance_run(struct service_instance *in, int _stdout, int _stderr)
      | ^~~~~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:443:1: error: 'instance_writepid' defined but not used [-Werror=unused-function]
  443 | instance_writepid(struct service_instance *in)
      | ^~~~~~~~~~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:432:1: error: 'instance_removepid' defined but not used [-Werror=unused-function]
  432 | instance_removepid(struct service_instance *in) {
      | ^~~~~~~~~~~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:204:1: error: 'syslog_facility_str_to_int' defined but not used [-Werror=unused-function]
  204 | syslog_facility_str_to_int(const char *facility)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:130:36: error: 'jail_attr' defined but not used [-Werror=unused-const-variable=]
  130 | static const struct blobmsg_policy jail_attr[__JAIL_ATTR_MAX] = {
      |                                    ^~~~~~~~~
/home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/service/instance.c:77:36: error: 'instance_attr' defined but not used [-Werror=unused-const-variable=]
   77 | static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = {
      |                                    ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
make[2]: *** [Makefile:154: /home/alexey/openwrt-R4/build_dir/target-aarch64_cortex-a53_musl/procd-default/procd-2026.02.17~180ffccf/.built] Error 1
make[2]: Leaving directory '/home/alexey/openwrt-R4/package/system/procd'
time: package/system/procd/default/compile#0.14#0.07#0.20
    ERROR: package/system/procd failed to build (build variant: default).
make[1]: *** [package/Makefile:188: package/system/procd/compile] Error 1
make[1]: Leaving directory '/home/alexey/openwrt-R4'

One more parenthesis was missing at the end. Now building

@Alexey71
Copy link

root@OpenWrt:~# logread -e qbittorrent
Sat Feb 21 20:31:39 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 1 seconds since last crash
Sat Feb 21 20:33:30 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 0 seconds since last crash

@dangowrt
Copy link
Member Author

root@OpenWrt:~# logread -e qbittorrent
Sat Feb 21 20:31:39 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 1 seconds since last crash
Sat Feb 21 20:33:30 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 0 seconds since last crash

Strange, no more cgroups related error message at all now. Just that the instance of qbittorrent itself is crashing...

@Alexey71
Copy link

root@OpenWrt:~# logread -e qbittorrent
Sat Feb 21 20:31:39 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 1 seconds since last crash
Sat Feb 21 20:33:30 2026 daemon.info procd: Instance qbittorrent::instance1 s in a crash loop 6 crashes, 0 seconds since last crash

Strange, no more cgroups related error message at all now. Just that the instance of qbittorrent itself is crashing...

I found the reason. I have a rule to save the /etc/qBittorrent folder. When I update the sysupgrade, the entire folder and files are saved. The lockfile and ipc-socket files remain in the /etc/qBittorrent/config/ folder. These files prevent qbittorrent from starting. If I delete them, it starts. Does procd create them?
The ipc-socket file is empty.
The lokfile file contains this

6457
qbittorrent-nox
OpenWrt
b99af2572dd6d7627369e37f6999f313
77827503-08dc-4687-ae16-541228b3e248

2026-02-21_210909
2026-02-21_211237

@Alexey71
Copy link

Alexey71 commented Feb 21, 2026

Previously, the lockfile was created empty. Since February, data has been written to it.
I found, this is created by qbittorrent itself. qbittorrent/qBittorrent@1a471be
Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

procd: cgroup instance creation fails for services started/restarted after boot

3 participants