Search code examples
adbexit-code

Why does adb return zero exit status in case of "failed to connect"?


Why does adb return zero exit status in case of "failed to connect"?

Demo:

$ adb connect 123.123.123.123:123
failed to connect to '123.123.123.123:123': Connection refused
$ echo $?
0

Is it considered normal with adb?


Solution

  • According to source code here, behind the scene the adb connect invokes adb_query that returns a char array. This char array contains the result of the socket request call, something that can be displayed as string in the terminal (your 'connection refused' message for instance).

    adb_query handles error scenarios as well but the issues that can be captured are more related to file descriptor (for socket communication) or memory allocation. When such cases happen then echo $? will return 1.

    That said, the answer to your question is, yes, this is the intended behaviour.