From bc1d2aeff9d909e9d8829e99ba3e55074ee7e78c Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 22 Feb 2017 15:06:21 -0800 Subject: [PATCH] logd: test: logd.sepolicy* errors If setcon fails, try alternate setcon, and then if it still fails call getcon to confirm if it is an OK sepolicy context anyways. Test: gTest logd-unit-tests --gtest_filter=logd.sepolicy* Change-Id: Iaf20b8a1a4a7312247288e1879884a54893c15ae --- logd/tests/logd_test.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp index d0101edf6..88cb67a96 100644 --- a/logd/tests/logd_test.cpp +++ b/logd/tests/logd_test.cpp @@ -999,16 +999,18 @@ static pid_t sepolicy_rate(unsigned rate, unsigned num) { } // We may have DAC, but let's not have MAC - if (setcon("u:object_r:shell:s0") < 0) { + if ((setcon("u:object_r:shell:s0") < 0) && (setcon("u:r:shell:s0") < 0)) { int save_errno = errno; security_context_t context; getcon(&context); - fprintf(stderr, "setcon(\"u:r:shell:s0\") failed @\"%s\" %s\n", context, - strerror(save_errno)); - freecon(context); - _exit(-1); - // NOTREACHED - return 0; + if (strcmp(context, "u:r:shell:s0")) { + fprintf(stderr, "setcon(\"u:r:shell:s0\") failed @\"%s\" %s\n", + context, strerror(save_errno)); + freecon(context); + _exit(-1); + // NOTREACHED + return 0; + } } // The key here is we are root, but we are in u:r:shell:s0,