summaryrefslogtreecommitdiff
path: root/server/main.cpp
diff options
context:
space:
mode:
authorJoel Scherpelz <jscherpelz@google.com>2017-06-14 10:27:47 +0900
committerJoel Scherpelz <jscherpelz@google.com>2017-06-14 10:40:47 +0900
commit519ffc3fbce7fa8113fa81d44ca313da6e6305ea (patch)
tree0ab8611edbb6fcc80d38f3268d4af2fb7647d8a8 /server/main.cpp
parent341e77d1705bfb902630e6fcad55021b00c14e4a (diff)
downloadnetd-519ffc3fbce7fa8113fa81d44ca313da6e6305ea.tar.gz
Avoid netlink socket address conflict
NetlinkManager previously bound all netlink sockets with nl_pid = getpid(). Unfortunately only the first such socket is allowed to claim nl_pid = getpid(). The kernel is happy to assign this value automatically if nl_pid = 0. For more information on nl_pid see "man 7 netlink". When NFLogListener was added, it created a socket with a kernel assigned nl_pid, unfortunately the kernel assigns getpid() to the first such socket and listener was initialized earlier in the startup process than NetlinkManager. This change alters NetlinkManager to request a kernel assigned nl_pid and defensively moves the initialization of NFLogListener later in the startup sequence to favor proper operation of existing code in NetlinkManager. Error logging is also slightly improved. Test: as follows - built - flashed - booted - "runtest -x .../netd_unit_test.cpp" passes - "cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.cts.StrictModeTest" passes Bug: 62353125 Change-Id: I9c1c76e5769de75ff624bf43634ac4061c447a72
Diffstat (limited to 'server/main.cpp')
-rw-r--r--server/main.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/server/main.cpp b/server/main.cpp
index 50570fd3..27596f7d 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -83,19 +83,8 @@ int main() {
exit(1);
};
- std::unique_ptr<NFLogListener> logListener;
- {
- auto result = makeNFLogListener();
- if (!isOk(result)) {
- ALOGE("Unable to create NFLogListener: %s", result.status().msg().c_str());
- exit(1);
- }
- logListener = std::move(result.value());
- }
-
gCtls = new android::net::Controllers();
gCtls->init();
- gCtls->wakeupCtrl.init(logListener.get());
CommandListener cl;
nm->setBroadcaster((SocketListener *) &cl);
@@ -105,6 +94,21 @@ int main() {
exit(1);
}
+ std::unique_ptr<NFLogListener> logListener;
+ {
+ auto result = makeNFLogListener();
+ if (!isOk(result)) {
+ ALOGE("Unable to create NFLogListener: %s", toString(result).c_str());
+ exit(1);
+ }
+ logListener = std::move(result.value());
+ auto status = gCtls->wakeupCtrl.init(logListener.get());
+ if (!isOk(result)) {
+ ALOGE("Unable to init WakeupController: %s", toString(result).c_str());
+ // We can still continue without wakeup packet logging.
+ }
+ }
+
// Set local DNS mode, to prevent bionic from proxying
// back to this service, recursively.
setenv("ANDROID_DNS_MODE", "local", 1);