Put the Android security check in its own function
Bug: 9469682
Change-Id: I60253008333edd7c8f2efe63f31059dc22adda63
diff --git a/ping.c b/ping.c
index bf69fb0..23613c8 100644
--- a/ping.c
+++ b/ping.c
@@ -73,10 +73,6 @@
};
#endif
-#ifdef ANDROID
-#include <sys/auxv.h>
-#endif
-
#define MAXIPLEN 60
#define MAXICMPLEN 76
#define NROUTES 9 /* number of record route slots */
@@ -135,10 +131,7 @@
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
#ifdef ANDROID
- if (getauxval(AT_SECURE) != 0) {
- fprintf(stderr, "This version of ping should NOT run with privileges. Aborting\n");
- exit(1);
- }
+ android_check_security();
#endif
limit_capabilities();
diff --git a/ping_common.c b/ping_common.c
index 1710d14..9c0e8f5 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -198,6 +198,14 @@
#endif
}
+void android_check_security(void)
+{
+ if (getauxval(AT_SECURE) != 0) {
+ fprintf(stderr, "This version of ping should NOT run with privileges. Aborting\n");
+ exit(1);
+ }
+}
+
/* Fills all the outpack, excluding ICMP header, but _including_
* timestamp area with supplied pattern.
*/
diff --git a/ping_common.h b/ping_common.h
index f9330aa..bc59700 100644
--- a/ping_common.h
+++ b/ping_common.h
@@ -35,6 +35,7 @@
#ifdef ANDROID
#include <linux/icmp.h>
+#include <sys/auxv.h>
#endif
#include "SNAPSHOT.h"
@@ -273,6 +274,7 @@
static inline int disable_capability_admin(void) { return modify_capability(0); };
#endif
extern void drop_capabilities(void);
+extern void android_check_security(void);
extern int send_probe(void);
extern int receive_error_msg(void);