0

I am getting a weird behavior with diag_mdlog executable. I am executing it from my Android app as

su -c /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg

The issue is:

  • if the android app has granted android.permission.READ_EXTERNAL_STORAGE or android.permission.WRITE_EXTERNAL_STORAGE then it exits with permissions denied error as the following logs:
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag_mdlog: command = o
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag_mdlog: command = f
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag: No Session is active for the given mask
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag_mdlog: Error creating: /sdcard/abc, errno: 13
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag_mdlog: Attempting to use default directory
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag:In main failed to create xml file
01-20 17:56:35.403 19087 19087 E Diag_Lib:
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag_mdlog: Continuing with default directory path /sdcard/diag_logs/20200120_175635
01-20 17:56:35.403 19087 19087 E Diag_Lib: diag_mdlog: Unable to create directory, errno: 13 Exiting....
  • OTOH, if the app has not granted both the permissions then it works fine as the following logs:
01-20 17:57:38.258 19364 19364 E Diag_Lib: diag_mdlog: command = o
01-20 17:57:38.258 19364 19364 E Diag_Lib: diag_mdlog: command = f
01-20 17:57:38.258 19364 19364 E Diag_Lib: diag: No Session is active for the given mask
01-20 17:57:38.259 19364 19364 E Diag_Lib: diag_mdlog: Warning output directory already exists: /sdcard/abc
01-20 17:57:38.259 19364 19364 E Diag_Lib: diag_mdlog: Proceeding...
01-20 17:57:38.270 19364 19364 E Diag_Lib:
01-20 17:57:38.270 19364 19364 E Diag_Lib: diag_mdlog: Diag_LSM_Init succeeded.
01-20 17:57:38.270 19364 19364 E Diag_Lib:
01-20 17:57:38.270 19364 19364 E Diag_Lib:  REMOTE PROCESSOR MASK 0
01-20 17:57:38.270 19364 19364 E Diag_Lib: diag:kernel supported: NUM_PERIPHERALS = 6, DIAG_CON_ALL: 127
01-20 17:57:38.271 19364 19364 E Diag_Lib:  logging switched
01-20 17:57:38.271 19364 19364 E Diag_Lib: Output dirs /sdcard/abc --- /sdcard/abc
01-20 17:57:38.271 19364 19364 E Diag_Lib:
01-20 17:57:38.271 19364 19364 E Diag_Lib: diag_mdlog: Reading mask for MSM, proc_type: 0
01-20 17:57:38.271 19364 19364 E Diag_Lib: Reading the mask file: /sdcard/Test.cfg
01-20 17:57:38.271 19364 19364 E Diag_Lib: diag: Determining contents of directory /sdcard/abc for circular logging ...
01-20 17:57:42.446 19364 19368 E Diag_Lib:  creating new file /sdcard/abc/diag_log_20200120_1757421579523262440.qmdl

Now, if I will deny write permissions from Android settings then I will get further error logs as the following:

01-20 18:00:18.799 19364 19368 E Diag_Lib: diag: In log_to_device, error writing to sd card, Permission denied, errno: 13
01-20 18:00:18.799 19364 19368 E Diag_Lib:  failed to write to file, device may be absent, errno: 13
01-20 18:00:18.799 19364 19368 E Diag_Lib:  File open error, please check
01-20 18:00:18.799 19364 19368 E Diag_Lib:  memory device -1, errno: 13
01-20 18:00:18.800 19364 19368 E Diag_Lib:  File open error, please check
01-20 18:00:18.800 19364 19368 E Diag_Lib:  memory device -1, errno: 13

Update 1 I have just tried to play with quotes around the command and it has following result:


DL is diag_mdlog logs
PL is java.lang.Process :: error stream logs

# Samsung S10 5G
    * Read/Write permissions GRANTED

        - su -c /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg
        DL: - diag_mdlog: Unable to create directory, errno: 13 Exiting....

        - su -c '/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg'
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: not found

        - su -c `/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg`
        DL: - diag_mdlog: Unable to create directory, errno: 13 Exiting....

        - su -c "/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg"
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: not found

    * Read/Write permissions Denied

        - su -c /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg
        * Run FINE.

        - su -c '/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg'
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: not found

        - su -c `/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg`
        * Run FINE.

        - su -c "/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg"
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: not found


# Mi K20 PRO
    * Read/Write permissions GRANTED

        - su -c /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg
        DL: - diag_mdlog: Unable to create directory, errno: 13 Exiting....

        - su -c '/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg'
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: inaccessible or not found

        - su -c `/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg`
        DL: - diag_mdlog: Unable to create directory, errno: 13 Exiting....

        - su -c "/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg"
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: inaccessible or not found

    * Read/Write permissions Denied

        - su -c /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg
        * Run FINE.

        - su -c '/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg'
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: inaccessible or not found

        - su -c `/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg`
        * Run FINE.

        - su -c "/vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg"
        PL: - /system/bin/sh: /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg: inaccessible or not found

Update 2 I was just wondering to run it in background process with

su -c /vendor/bin/diag_mdlog -o /sdcard/abc -f /sdcard/Test.cfg & but it is also not working.

Even creating the following shell script at /system/script/ with giving 755 permissions and executing it doesn't help me.

exec_diag_mdlog.sh:

raphaelin:/system/scripts # cat exec_diag_mdlog.sh
#!/system/bin/sh

diag_mdlog -o /sdcard/oem_logs -f /sdcard/Test.cfg &

raphaelin:/system/scripts #

Any suggestion to let the command will not execute in the context of app?

Any solution to this problem?

6
  • Read about how Android makes use of mount namespaces to control storage permissions. And UIDs/GIDs 1015, 9997. Does the command work from Termux? Also quote the whole command like: su -c '...'. Commented Jan 21, 2020 at 3:22
  • It does work with adb shell and also from any app that doesn't have Write permissions granted. Commented Jan 21, 2020 at 5:10
  • No luck with a single quote. I have updated the question with more detail. Commented Jan 21, 2020 at 11:43
  • @IrfanLatif Is it possible to run a command to create a process that runs diag_mdlog executable beyond the context of an android application? (I know I can do this with init scripts but I want something that I can execute from my app directly) Commented Jan 21, 2020 at 11:45
  • 1
    Yes it's definitely possible. Executing directly from app should also work (if it works from a terminal emulator app; directly on terminal and in shell script). But it's more about app development how you need to execute it from within app. When executing su you run it with Magisk context, not app context. As I mentioned in my first comment, do take care of mount namespace separation regarding storage permission. Run with strace to get more specific reason of failure. Commented Jan 22, 2020 at 7:51

0

You must log in to answer this question.

Browse other questions tagged .