Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS#3854 - procd / inittab does not restart compiled c application when it closes #8860

Open
openwrt-bot opened this issue Jun 4, 2021 · 3 comments
Labels

Comments

@openwrt-bot
Copy link

kse:

Supply the following if possible:

  • Device problem occurs on
  • Software versions of OpenWrt/LEDE release, packages, etc.
  • Steps to reproduce

Issue Overview: I have a test application that should be respawned via procd when/if it is ever closed. Procd doesn't re-launch this application. I have built a test app (detailed below) to limit the variables in testing.

Device: GL-iNet GL-MT300N-V2
Software Versions: OpenWRT Version 19.07.7 (All versions of 19.07 -> 21.02 I have used are currently been experiencing this. 18.06 does not appear to have this issue for me) - Packages included (selected with imagebuilder):
CONFIG_TARGET_ramips=y
CONFIG_TARGET_ramips_mt76x8=y
CONFIG_TARGET_MULTI_PROFILE=y
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_alfa-network_awusfree1=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_alfa-network_awusfree1=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_wcr-1166ds=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_wcr-1166ds=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_cudy_wr1000=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_cudy_wr1000=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_duzun-dm06=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_duzun-dm06=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_gl-mt300n-v2=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_gl-mt300n-v2=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_glinet_vixmini=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_glinet_vixmini=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_hilink_hlk-7628n=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_hilink_hlk-7628n=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_hc5661a=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_hc5661a=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_hiwifi_hc5861b=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_hiwifi_hc5861b=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_LinkIt7688=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_LinkIt7688=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_mt7628=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_mt7628=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_mac1200r-v2=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_mac1200r-v2=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_netgear_r6120=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_netgear_r6120=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_omega2=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_omega2=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_omega2p=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_omega2p=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_pbr-d1=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_pbr-d1=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_rakwireless_rak633=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_rakwireless_rak633=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_skylab_skw92a=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_skylab_skw92a=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tama_w06=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tama_w06=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_totolink_lr1200=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_totolink_lr1200=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_c20-v4=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_c20-v4=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_c50-v3=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_c50-v3=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_c50-v4=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_c50-v4=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_tl-mr3020-v3=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_tl-mr3020-v3=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_tl-mr3420-v5=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_tl-mr3420-v5=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_tl-wa801nd-v5=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_tl-wa801nd-v5=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_tl-wr802n-v4=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_tl-wr802n-v4=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tl-wr840n-v4=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tl-wr840n-v4=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tl-wr841n-v13=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tl-wr841n-v13=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_tl-wr842n-v5=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_tl-wr842n-v5=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_tplink_tl-wr902ac-v3=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_tplink_tl-wr902ac-v3=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_u7628-01-128M-16M=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_u7628-01-128M-16M=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_vocore2=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_vocore2=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_vocore2lite=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_vocore2lite=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_wavlink_wl-wn570ha1=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_wavlink_wl-wn570ha1=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_wavlink_wl-wn575a3=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_wavlink_wl-wn575a3=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_widora_neo-16m=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_widora_neo-16m=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_widora_neo-32m=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_widora_neo-32m=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_wiznet_wizfi630s=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_wiznet_wizfi630s=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_wrtnode2p=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_wrtnode2p=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_wrtnode2r=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_wrtnode2r=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_xiaomi_mir4a-100m=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_xiaomi_mir4a-100m=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_miwifi-nano=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_miwifi-nano=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_zbtlink_zbt-we1226=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_zbtlink_zbt-we1226=""
CONFIG_TARGET_DEVICE_ramips_mt76x8_DEVICE_zyxel_keenetic-extra-ii=y
CONFIG_TARGET_DEVICE_PACKAGES_ramips_mt76x8_DEVICE_zyxel_keenetic-extra-ii=""
CONFIG_DEVEL=y
CONFIG_TARGET_PER_DEVICE_ROOTFS=y
CONFIG_LIBCURL_NGHTTP2=y
CONFIG_LIBCURL_THREADED_RESOLVER=y
CONFIG_LIBCURL_ZLIB=y
CONFIG_PACKAGE_arp-scan=y
CONFIG_PACKAGE_arp-scan-database=y
CONFIG_PACKAGE_ca-bundle=y
CONFIG_PACKAGE_libcurl=y
CONFIG_PACKAGE_libmbedtls=y
CONFIG_PACKAGE_libnghttp2=y
CONFIG_PACKAGE_liboping=y
CONFIG_PACKAGE_libpcap=y
CONFIG_PACKAGE_librt=y
CONFIG_PACKAGE_zlib=y
CONFIG_ZLIB_OPTIMIZE_SPEED=y

I am building a fairly a stripped-down build of OpenWRT. However, from what I can tell at least, I should have at least the minimum required dependencies/packages/etc. for the application to be respawned correctly.

Repro steps:
I've written a test application to isolate issues. This test app is configured to respawn in the exact same way I have my primary application configured. After testing with the test app, this issue persists I can confirm it will not respawn when the application is closed. I can also confirm that the applications themselves will launch and run correctly on the machine if executed. The only thing I cannot get to work at the moment is the procd respawn. However, I should also add that I have a shell script does respawn correctly.

Source code for this app:
Base app:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

Launcher (This is what should respawn on app end)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
pid_t pid = fork();

if(pid == 0)
{
	char * args[2];
	args[0] = malloc(strlen("HelloWorldBase") + 1);
	strcpy(args[0], "HelloWorldBase");
	args[1] = NULL;
	execve("HelloWorldBase", args, NULL);
	abort();
}

int status = 0;
wait(&status);
return 0;

}

inittab file:
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
::respawn:/root/app/HelloWorldBaseLauncher
::askconsole:/bin/login
::respawn:/bin/sh /bin/working-script

I have confirmed that application is compiled correctly and will run correctly when it is directly run. I have also confirmed that shell script in /bin/ folder will respawn as expected. It just seems that the compiled application itself will not respawn.
Additionally, I do not see any console output or errors visible from logread when the application should respawn.

@openwrt-bot
Copy link
Author

jow-:

Is your "HelloWorldBase" program spawning further childs? Is your wait() call actually reaping the result of the execve() invoked process or just some unrelated child process? Does it work if you ignore the SIGCHLD signal in the parent process?

procd itself will also waitpid() for the respawn process, if that does not return due to unreaped child zombies, the process ius never considered finished and will not get respawned.

@openwrt-bot
Copy link
Author

kse:

Thanks for the resopnse,

  1. No - no further children. HelloWorldBase simply prints, returns, and the launcher awaits it and returns. Yes the wait call is waiting the result of the base app called by execve - sorry for the confusion there. I can try modifying the application further to see if it works, however I did more testing of my own (attached console logs). As I said in my original post, I had a script that was correctly being respawned - and since then I've found that it's not being respawned correctly. (The script itself never actually dies, so it never necessitates respawning, I just had it set to respawn as a safety net) However, I have reproduced the issue by killing the processes and noting that no attempt at respawn is happening.

After looking at the git page for procd and attempting to educate myself on exactly how things work and what may have changed, I tend to agree it's hard to believe there would be a bug with procd itself - however, I feel as if I've done my best to isolate any variables on my end:

I have an application and a script
I built OpenWRT - One on 18.06.07 and one on 19.07.07 - both built with the same packages (that are available to both)
On one build (18.06), my script and application respawn via procd, on the other, they don't

@openwrt-bot
Copy link
Author

kse:

Any updates on this? I installed 21.02 fresh and can verify that respawn isn't working with a simple script. Runs once and does NOT respawn. So the initial run of the respawn works and the respawn itself never happens. I have fully moved my app/script over to a procd init script to work on 19.07, but it's not ideal.

Docs suggest that respawn works via inittab and in every case I've tried so far, even with a simple script that just says 'hello' and exits, it will not respawn.

https://openwrt.org/docs/techref/procd

This seems to be due to handing all of the busybox init duties over to procd? Am I mistaken there?

After testing it pretty extensively with many different builds, the respawn just isn't working, so either the docs are wrong or I'm wrong with the suggested functionality. But I would think that just having a simple script that exits would respawn if I told it to with inittab.

Script (Located in /bin/script):

#!/bin/sh

logger -t '' Hello

sleep 10

exit 0

I tried without and with the exit.

Inittab:

::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
::askconsole:/usr/libexec/login.sh
::respawn:/bin/script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant