Check if a file contains a string by "grep -q" in JNI - android

I am writing a small Android program that can check how many files contains a certain string without reading completely their contents
Therefore, I've found a good way to do it is using grep -q command. Because of executing the command doesn't output but a exit code (0 : match, 1 : not match)
However I have no idea that how to get the exit code after executing the command completed by C language in JNI.

Related

How to solve this valgrind issue?

I'm trying to run valgrind on an android OS but it couldn't start and it shows this errors that i couldn't find how to solve:
valgrind: Startup or configuration error:
Can't create client cmdline file in /tmp/valgrind_proc_87_cmdline_876a7612
valgrind: Unable to start up properly. Giving up.
Thanks in advance !
I tried to change the default path that valgrind use and which is shown on the error log but i couldn't make it
The problem is happening in the code where the Valgrind host is creating a fake /proc/<pid>/cmdline.
This file should be created in the location given by the first valid item in the following list:
The TMPDIR environment variable
The constant VG_TMPDIR that gets baked into the binary via a configure time option. This defaults to /tmp but can be overriden using configure --with-tmpdir=/your/tmp/dir. That would require that you get the Valgrind source and configure and build it. It is possible that you are using a package that was built using this option and is not compatible with your system.
Last resort, "/tmp"
All of the above checks just test that the string is non-null and not empty. They do not test for the existance and accessibility of the directory. That gets determined by the Valgrind version of mkstemp and the error message comes from 'valgrind_main'.
Valgrind needs to create a file TMPDIR/valgrind_proc_PID_cmdline_RAND where TMPDIR is described above, PID is the pid of the Valgrind process and RAND is a random number.
There is at least one other similar files that get created, for auxv.
There are no Valgrind command line options to turn off the creation of these files.

Automation testing error while starting Test Cases

What is causing this error when I run my Android app's automated testing?
C:\Users\sujan\PycharmProjects\code\auto_env\OTT_Client
Traceback (most recent call last):
File "src/Utilities_test/Convert_csvToPy.py", line 13, in <module>
from template.cases_template import test_case_dict
ImportError: bad magic number in 'template': b'\x03\xf3\r\n'
command 'python src/Utilities_test/Convert_csvToPy.py Test_cases.csv' return with error (code 1): b''
This error probably is a result of a mix between 2.7 & 3+ versions, also happens if you have manually named your file with an extension .pyc
the error isn't actually coming from your test cases. The magic number comes from UNIX-type systems where the first few bytes of a file held a marker indicating the file type. Python puts a similar marker into its pyc files when it creates them.
Then the python interpreter makes sure this number is correct when loading it.
Anything that corrupts this magic number will cause your problem, like if you edit a pyc file or your trying to run from a different version of python
as for fixing it you could try a few things. You could try to do a clean on the pyc files something like
find . -name "*.pyc" -exec rm -f {} \;
The command above will delete all pyc files recursively. then just run again and it should recompile
or if you cloned something from a repo just delete and and reclone

Android does not see the executable file

I wrote a simple program in C that displays the string. I compiled it for the ARM architect and sent it via FTP to my rooted Leagoo M5.
I mounted the memory as RW and moved the program to /data/local.
I used 'chmod + x armexe' to add execute attributes. Despite this, after executing './armexe' the message './sh: ./data/local/armexe: No drunk file or directory' pops up.
This section from the terminal probably shows it best:
root#M5:/data/local # ls && ./armexe
armexe
tmp
sush: ./armexe: No such file or directory
This error seems strange to me, and somehow I could not find the answer to other forums.
Sorry for my English. I hope you understood me :)

executing static program from android init.rc

I want to start a custom program in the init process. I compiled this program statically that run fine from my booted up android stock ROM.
From the android init.rc docs I read that the exec command is what I need.
BTW all I can see in dmesg is that my program exit with code -1 (I can't return that).
init.rc snippet:
on post-fs-data
write /dev/kmsg "launching test"
exec /data/test
All I see in dmesg is this:
<4>[ 6.336816] launching test
<6>[ 6.336902] init: command 'write' r=0
<6>[ 6.337115] init: command 'exec' r=-1
Here you are the executable source code: http://pastebin.com/Hym1APWx
UPDATE
I tried to statically compile and run this program:
int main(){return 0; }
But the result is always command 'exec' r=-1. Maybe user uselen are right, maybe I cannot run executables from /data in the early-boot phase.
As christian said, it looks like exec isn't even implemented. I'm beginning to think that a lot of features documented for init.rc aren't implemented. Here's a way you can get your program to launch however.
Instead of running this as an "exec" command, set this up as a service instead.
In your init.rc, or another file included by it:
service my_service /data/test
class main
oneshot
If it's in class main, and not disabled, it should run after /data is mounted.
I had the same issue today. In my case the solution was simple: The exec function wasn't implemented yet and contained just a return -1. You should take a look at builtin.c and search for do_exec(). This code is executed when init.rc contains an exec statement.

"Run Command" file editing (i.e. " *.rc " files): Echoing to the terminal like Linux?

I am editing the Android phone file "init.tuna.rc" so that it prints to me some basic debugging checkpoint messages so I can analyze how far the phone gets in the boot process.
Does anyone know if you can simply insert the shell scripting syntax for console printing into a "run command" file (.rc)?
(I need to know this if someone can help me before I rebuild all of my code for the Android tree to test this debugging code, given the process can a while)
Will the following work? I want to insert in the following code snippet into the "init.tuna.rc" file:
# Boot debugging Checkpoint #2
echo "Check #2: Successfully wrote the file system data, including the wifi directories!"
If this does not work, what can I do to get the "rc" file to print messages to the actual terminal as it executes?
Android Boot Language is documented in a readme.txt file in the source tree under <android>/system/core/init.
No echo is mentioned, but you can try. Also remember that you should write to a file because stderr and stdout are redirected to /dev/null.
See https://github.com/aosp-mirror/platform_system_core/blob/master/init/README.md

Categories

Resources