Good day, please help solve the problem:

There is an android daemon written for Android NDK, a simple tcp server. It compiles to .so lib and runs on a device / emulator in daemon mode.

The problem is running.

If I go into the shell:

adb shell 

And then I write the command:

 su -c /dir/daemon 55000 

Then everything starts and works, but if I want to do:

 adb shell su -c /dir/daemon 55000 

That command is executed, but there are no errors and the daemon does not start. I tried various options with installing single and double quotes. If you spam this command several times on the console, then at some point adb locks the console and then the daemon is started. But I would like the result to be after the first attempt.

I need to run this daemon from the Qt application. I do it through QProcess.

I can not understand the reason for this behavior. I climbed in sorts but found nothing sensible.

Demon worker, if you run with your hands, then everything works as it should. I put simple logging into the daemon code right at the entrance to the main function, but we don’t even get there if we try to start from the console via

 adb -s <dev_name> shell su -c /dir/daemon <port_number> 

I tried to generate a shell script inside Qt with a port number and run like this:

 adb -s <dev_name> shell sh /dir/script.sh 

The result is the same, it works only if you first enter the adb shell

Update: I noticed that this problem is present only when we need to start in daemon mode, i.e. either with the daemon () function or with the & at the end of the command. In other cases, everything runs fine even from the console.

  • And the phone is exactly rutted? That concludes adb su (does the sign of the invitation change)? Is it allowed to use root rights in adb (developer settings, root mode). - pavel
  • Changes, the phone is rutted, and I'm testing on the emulator. The bottom line is that the teams are working, if you pull directly from the adb shell, but when you try to pull the OS console, nothing happens, the command passes, but there is no demon in adb shell ps. It can only work if you spam a command into the console several times. It feels like there are some timeouts. That-if I'm an idiot that-whether skis do not go - Pavel Korban

1 answer 1

I suggested this solution:

adb shell su -c "/ dir> / dev / null 2> / dev / null </ dev / null &" However, it does not work on all versions of api, most likely due to differences in the parsing of commands from the adb shell. Those. somewhere we need additional quotes, somewhere they interfere. So I pulled the source code from nohup, added it to my ndk project as executable lib and compiled for all architectures.

Now I launch the daemon like this:

 shell su -c /data/local/tmp/start_daemon.sh 

The script code itself:

 #!/system/bin/sh /data/local/tmp/nohup /data/local/tmp/daemon <portn_number> &