Turn on C++11 and make all warnings into errors.
As a consequence:
+ Comment out the names of all unused parameters.
+ Remove all unused variables and functions.
In server/Android.mk, there are a couple of non-trivial changes:
+ Use libcxx instead of stlport. This is needed to fix a bunch of errors due to
specifying -std=c++11.
+ LOCAL_SHARED_LIBRARIES is sorted. Technically, the order in which libraries
are listed has an effect on linking, but nobody should be doing such brittle
things anyway.
Change-Id: I0aff5b745e04609da23144d0e8be4c5694321b8b
diff --git a/server/Android.mk b/server/Android.mk
index f2c9c4b..83184d3 100644
--- a/server/Android.mk
+++ b/server/Android.mk
@@ -1,64 +1,81 @@
-LOCAL_PATH:= $(call my-dir)
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= \
- BandwidthController.cpp \
- ClatdController.cpp \
- CommandListener.cpp \
- DnsProxyListener.cpp \
- FirewallController.cpp \
- FwmarkServer.cpp \
- IdletimerController.cpp \
- InterfaceController.cpp \
- MDnsSdListener.cpp \
- NatController.cpp \
- NetdCommand.cpp \
- NetdConstants.cpp \
- NetlinkHandler.cpp \
- NetlinkManager.cpp \
- NetworkController.cpp \
- Permission.cpp \
- PermissionsController.cpp \
- PppController.cpp \
- ResolverController.cpp \
- RouteController.cpp \
- SecondaryTableController.cpp \
- SoftapController.cpp \
- TetherController.cpp \
- oem_iptables_hook.cpp \
- main.cpp \
-
-
-LOCAL_MODULE:= netd
-
LOCAL_C_INCLUDES := \
- external/mdnsresponder/mDNSShared \
- external/openssl/include \
- external/stlport/stlport \
- bionic \
- bionic/libc/dns/include \
- system/netd/include \
- $(call include-path-for, libhardware_legacy)/hardware_legacy
+ $(call include-path-for, libhardware_legacy)/hardware_legacy \
+ bionic \
+ bionic/libc/dns/include \
+ external/libcxx/include \
+ external/mdnsresponder/mDNSShared \
+ external/openssl/include \
+ system/netd/include \
-LOCAL_CFLAGS := -Werror=format
+LOCAL_CLANG := true
+LOCAL_CPPFLAGS := -std=c++11 -Wall -Werror
+LOCAL_MODULE := netd
-LOCAL_SHARED_LIBRARIES := libstlport libsysutils liblog libcutils libnetutils \
- libcrypto libhardware_legacy libmdnssd libdl \
- liblogwrap
+LOCAL_SHARED_LIBRARIES := \
+ libcrypto \
+ libcutils \
+ libdl \
+ libhardware_legacy \
+ liblog \
+ liblogwrap \
+ libmdnssd \
+ libnetutils \
+ libstlport \
+ libsysutils \
+
+LOCAL_SRC_FILES := \
+ BandwidthController.cpp \
+ ClatdController.cpp \
+ CommandListener.cpp \
+ DnsProxyListener.cpp \
+ FirewallController.cpp \
+ FwmarkServer.cpp \
+ IdletimerController.cpp \
+ InterfaceController.cpp \
+ MDnsSdListener.cpp \
+ NatController.cpp \
+ NetdCommand.cpp \
+ NetdConstants.cpp \
+ NetlinkHandler.cpp \
+ NetlinkManager.cpp \
+ NetworkController.cpp \
+ Permission.cpp \
+ PermissionsController.cpp \
+ PppController.cpp \
+ ResolverController.cpp \
+ RouteController.cpp \
+ SecondaryTableController.cpp \
+ SoftapController.cpp \
+ TetherController.cpp \
+ main.cpp \
+ oem_iptables_hook.cpp \
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= \
- ndc.c \
-LOCAL_MODULE:= ndc
-
-LOCAL_C_INCLUDES :=
-
-LOCAL_CFLAGS :=
-
+LOCAL_CFLAGS := -Wall -Werror
+LOCAL_CLANG := true
+LOCAL_MODULE := ndc
LOCAL_SHARED_LIBRARIES := libcutils
+LOCAL_SRC_FILES := ndc.c
include $(BUILD_EXECUTABLE)
diff --git a/server/BandwidthController.cpp b/server/BandwidthController.cpp
index a7c2c2c..4f9344c 100644
--- a/server/BandwidthController.cpp
+++ b/server/BandwidthController.cpp
@@ -405,7 +405,6 @@
std::list<int /*appUid*/> &specialAppUids,
IptJumpOp jumpHandling, SpecialAppOp appOp) {
- char cmd[MAX_CMD_LEN];
int uidNum;
const char *failLogTemplate;
IptOp op;
@@ -595,7 +594,6 @@
}
int BandwidthController::setInterfaceSharedQuota(const char *iface, int64_t maxBytes) {
- char cmd[MAX_CMD_LEN];
char ifn[MAX_IFACENAME_LEN];
int res = 0;
std::string quotaCmd;
@@ -1266,7 +1264,6 @@
int res;
std::string fullCmd;
FILE *iptOutput;
- const char *cmd;
/*
* Why not use some kind of lib to talk to iptables?
@@ -1292,10 +1289,8 @@
}
void BandwidthController::flushExistingCostlyTables(bool doClean) {
- int res;
std::string fullCmd;
FILE *iptOutput;
- const char *cmd;
/* Only lookup ip4 table names as ip6 will have the same tables ... */
fullCmd = IPTABLES_PATH;
diff --git a/server/CommandListener.cpp b/server/CommandListener.cpp
index 72ff411..154050e 100644
--- a/server/CommandListener.cpp
+++ b/server/CommandListener.cpp
@@ -546,7 +546,6 @@
ALOGD("Setting iface cfg");
struct in_addr addr;
- unsigned flags = 0;
int index = 5;
ifc_init();
@@ -686,7 +685,7 @@
}
int CommandListener::ListTtysCmd::runCommand(SocketClient *cli,
- int argc, char **argv) {
+ int /* argc */, char ** /* argv */) {
TtyCollection *tlist = sPppCtrl->getTtyList();
TtyCollection::iterator it;
@@ -933,7 +932,6 @@
int CommandListener::SoftapCmd::runCommand(SocketClient *cli,
int argc, char **argv) {
int rc = ResponseCode::SoftapStatusResult;
- int flag = 0;
char *retbuf = NULL;
if (sSoftapCtrl == NULL) {
@@ -979,7 +977,6 @@
int CommandListener::ResolverCmd::runCommand(SocketClient *cli, int argc, char **margv) {
int rc = 0;
- struct in_addr addr;
const char **argv = const_cast<const char **>(margv);
if (argc < 2) {
diff --git a/server/Fwmark.h b/server/Fwmark.h
index f2a0f57..768219d 100644
--- a/server/Fwmark.h
+++ b/server/Fwmark.h
@@ -18,7 +18,6 @@
#define NETD_SERVER_FWMARK_H
#include "Permission.h"
-#include "utils/Debug.h"
#include <stdint.h>
@@ -35,11 +34,6 @@
static const unsigned FWMARK_NET_ID_MASK = 0xffff;
-namespace android {
-
-// Ensure that all the fwmark fields fit into 32 bits.
-COMPILE_TIME_ASSERT(sizeof(Fwmark) == sizeof(uint32_t));
-
-} // namespace android
+static_assert(sizeof(Fwmark) == sizeof(uint32_t), "The entire fwmark must fit into 32 bits");
#endif // NETD_SERVER_FWMARK_H
diff --git a/server/MDnsSdListener.cpp b/server/MDnsSdListener.cpp
index 7160028..7e16a6c 100644
--- a/server/MDnsSdListener.cpp
+++ b/server/MDnsSdListener.cpp
@@ -93,8 +93,8 @@
return;
}
-void MDnsSdListenerDiscoverCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
- uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName,
+void MDnsSdListenerDiscoverCallback(DNSServiceRef /* sdRef */, DNSServiceFlags flags,
+ uint32_t /* interfaceIndex */, DNSServiceErrorType errorCode, const char *serviceName,
const char *regType, const char *replyDomain, void *inContext) {
MDnsSdListener::Context *context = reinterpret_cast<MDnsSdListener::Context *>(inContext);
char *msg;
@@ -186,9 +186,9 @@
return;
}
-void MDnsSdListenerRegisterCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
- DNSServiceErrorType errorCode, const char *serviceName, const char *regType,
- const char *domain, void *inContext) {
+void MDnsSdListenerRegisterCallback(DNSServiceRef /* sdRef */, DNSServiceFlags /* flags */,
+ DNSServiceErrorType errorCode, const char *serviceName, const char * /* regType */,
+ const char * /* domain */, void *inContext) {
MDnsSdListener::Context *context = reinterpret_cast<MDnsSdListener::Context *>(inContext);
char *msg;
int refNumber = context->mRefNumber;
@@ -240,9 +240,10 @@
return;
}
-void MDnsSdListenerResolveCallback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interface,
- DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port,
- uint16_t txtLen, const unsigned char *txtRecord, void *inContext) {
+void MDnsSdListenerResolveCallback(DNSServiceRef /* sdRef */, DNSServiceFlags /* flags */,
+ uint32_t /* interface */, DNSServiceErrorType errorCode, const char *fullname,
+ const char *hosttarget, uint16_t port, uint16_t txtLen,
+ const unsigned char * /* txtRecord */, void *inContext) {
MDnsSdListener::Context *context = reinterpret_cast<MDnsSdListener::Context *>(inContext);
char *msg;
int refNumber = context->mRefNumber;
@@ -295,8 +296,8 @@
return;
}
-void MDnsSdListenerGetAddrInfoCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
- uint32_t interface, DNSServiceErrorType errorCode, const char *hostname,
+void MDnsSdListenerGetAddrInfoCallback(DNSServiceRef /* sdRef */, DNSServiceFlags /* flags */,
+ uint32_t /* interface */, DNSServiceErrorType errorCode, const char *hostname,
const struct sockaddr *const sa, uint32_t ttl, void *inContext) {
MDnsSdListener::Context *context = reinterpret_cast<MDnsSdListener::Context *>(inContext);
int refNumber = context->mRefNumber;
@@ -353,7 +354,7 @@
return;
}
-void MDnsSdListenerSetHostnameCallback(DNSServiceRef sdRef, DNSServiceFlags flags,
+void MDnsSdListenerSetHostnameCallback(DNSServiceRef /* sdRef */, DNSServiceFlags /* flags */,
DNSServiceErrorType errorCode, const char *hostname, void *inContext) {
MDnsSdListener::Context *context = reinterpret_cast<MDnsSdListener::Context *>(inContext);
char *msg;
@@ -373,19 +374,19 @@
}
-int MDnsSdListener::Handler::ifaceNameToI(const char *iface) {
+int MDnsSdListener::Handler::ifaceNameToI(const char * /* iface */) {
return 0;
}
-const char *MDnsSdListener::Handler::iToIfaceName(int i) {
+const char *MDnsSdListener::Handler::iToIfaceName(int /* i */) {
return NULL;
}
-DNSServiceFlags MDnsSdListener::Handler::iToFlags(int i) {
+DNSServiceFlags MDnsSdListener::Handler::iToFlags(int /* i */) {
return 0;
}
-int MDnsSdListener::Handler::flagsToI(DNSServiceFlags flags) {
+int MDnsSdListener::Handler::flagsToI(DNSServiceFlags /* flags */) {
return 0;
}
@@ -527,6 +528,27 @@
return NULL;
}
+#define NAP_TIME 200 // 200 ms between polls
+static int wait_for_property(const char *name, const char *desired_value, int maxwait)
+{
+ char value[PROPERTY_VALUE_MAX] = {'\0'};
+ int maxnaps = (maxwait * 1000) / NAP_TIME;
+
+ if (maxnaps < 1) {
+ maxnaps = 1;
+ }
+
+ while (maxnaps-- > 0) {
+ usleep(NAP_TIME * 1000);
+ if (property_get(name, value, NULL)) {
+ if (desired_value == NULL || strcmp(value, desired_value) == 0) {
+ return 0;
+ }
+ }
+ }
+ return -1; /* failure */
+}
+
int MDnsSdListener::Monitor::startService() {
int result = 0;
char property_value[PROPERTY_VALUE_MAX];
@@ -614,7 +636,6 @@
if (VDBG) {
ALOGD("MDnsSdListener::Monitor poll rescanning - size=%d, live=%d", mPollSize, mLiveCount);
}
- int count = 0;
pthread_mutex_lock(&mHeadMutex);
Element **prevPtr = &mHead;
int i = 1;
@@ -707,27 +728,6 @@
pthread_mutex_unlock(&mHeadMutex);
}
-#define NAP_TIME 200 // 200 ms between polls
-static int wait_for_property(const char *name, const char *desired_value, int maxwait)
-{
- char value[PROPERTY_VALUE_MAX] = {'\0'};
- int maxnaps = (maxwait * 1000) / NAP_TIME;
-
- if (maxnaps < 1) {
- maxnaps = 1;
- }
-
- while (maxnaps-- > 0) {
- usleep(NAP_TIME * 1000);
- if (property_get(name, value, NULL)) {
- if (desired_value == NULL || strcmp(value, desired_value) == 0) {
- return 0;
- }
- }
- }
- return -1; /* failure */
-}
-
void MDnsSdListener::Monitor::freeServiceRef(int id) {
if (VDBG) ALOGD("freeServiceRef %d", id);
pthread_mutex_lock(&mHeadMutex);
diff --git a/server/MDnsSdListener.h b/server/MDnsSdListener.h
index a3b14ad..e9c6066 100644
--- a/server/MDnsSdListener.h
+++ b/server/MDnsSdListener.h
@@ -135,6 +135,4 @@
};
};
-static int wait_for_property(const char *name, const char *desired_value, int maxwait);
-
#endif
diff --git a/server/NatController.cpp b/server/NatController.cpp
index fbf5f8a..8391ad7 100644
--- a/server/NatController.cpp
+++ b/server/NatController.cpp
@@ -165,11 +165,9 @@
// 0 1 2 3 4 5
// nat enable intface extface addrcnt nated-ipaddr/prelength
int NatController::enableNat(const int argc, char **argv) {
- int i;
int addrCount = atoi(argv[4]);
const char *intIface = argv[2];
const char *extIface = argv[3];
- int tableNumber;
ALOGV("enableNat(intIface=<%s>, extIface=<%s>)",intIface, extIface);
@@ -271,8 +269,7 @@
if (!add) {
return 0;
}
- char *pair_name, *proc_path;
- int quota_fd;
+ char *pair_name;
asprintf(&pair_name, "%s_%s", intIface, extIface);
if (checkTetherCountingRuleExist(pair_name)) {
@@ -408,11 +405,9 @@
// 0 1 2 3 4 5
// nat enable intface extface addrcnt nated-ipaddr/prelength
int NatController::disableNat(const int argc, char **argv) {
- int i;
int addrCount = atoi(argv[4]);
const char *intIface = argv[2];
const char *extIface = argv[3];
- int tableNumber;
if (!checkInterface(intIface) || !checkInterface(extIface)) {
ALOGE("Invalid interface specified");
diff --git a/server/NetlinkHandler.cpp b/server/NetlinkHandler.cpp
index 9c2984f..4f421c5 100644
--- a/server/NetlinkHandler.cpp
+++ b/server/NetlinkHandler.cpp
@@ -90,7 +90,6 @@
notifyQuotaLimitReached(alertName, iface);
} else if (!strcmp(subsys, "xt_idletimer")) {
- int action = evt->getAction();
const char *label = evt->findParam("INTERFACE");
const char *state = evt->findParam("STATE");
const char *timestamp = evt->findParam("TIME_NS");
diff --git a/server/NetlinkManager.h b/server/NetlinkManager.h
index b7f011e..5187a59 100644
--- a/server/NetlinkManager.h
+++ b/server/NetlinkManager.h
@@ -32,7 +32,6 @@
NetlinkHandler *mUeventHandler;
NetlinkHandler *mRouteHandler;
NetlinkHandler *mQuotaHandler;
- NetlinkHandler *mIfaceIdleTimerHandler;
int mUeventSock;
int mRouteSock;
int mQuotaSock;
diff --git a/server/RouteController.cpp b/server/RouteController.cpp
index 36773d7..592dc35 100644
--- a/server/RouteController.cpp
+++ b/server/RouteController.cpp
@@ -32,7 +32,10 @@
const uint32_t RULE_PRIORITY_PER_NETWORK_NORMAL = 17000;
const uint32_t RULE_PRIORITY_DEFAULT_NETWORK = 19000;
const uint32_t RULE_PRIORITY_MAIN = 20000;
+// TODO: Uncomment once we are sure everything works.
+#if 0
const uint32_t RULE_PRIORITY_UNREACHABLE = 21000;
+#endif
// TODO: These should be turned into per-UID tables once the kernel supports UID-based routing.
const int ROUTE_TABLE_PRIVILEGED_LEGACY = RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX - 901;
diff --git a/server/SoftapController.cpp b/server/SoftapController.cpp
index 7d5da95..3129513 100644
--- a/server/SoftapController.cpp
+++ b/server/SoftapController.cpp
@@ -114,7 +114,6 @@
int SoftapController::setSoftap(int argc, char *argv[]) {
char psk_str[2*SHA256_DIGEST_LENGTH+1];
int ret = ResponseCode::SoftapStatusResult;
- int i = 0;
int fd;
int hidden = 0;
int channel = AP_CHANNEL_DEFAULT;
@@ -201,7 +200,6 @@
*/
int SoftapController::fwReloadSoftap(int argc, char *argv[])
{
- int i = 0;
char *fwpath = NULL;
if (argc < 4) {
diff --git a/server/TetherController.cpp b/server/TetherController.cpp
index 32a0b43..93110e0 100644
--- a/server/TetherController.cpp
+++ b/server/TetherController.cpp
@@ -242,7 +242,6 @@
}
int TetherController::applyDnsInterfaces() {
- int i;
char daemonCmd[MAX_CMD_SIZE];
strcpy(daemonCmd, "update_ifaces");
diff --git a/server/main.cpp b/server/main.cpp
index e09019d..11d4d40 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -36,8 +36,6 @@
#include "MDnsSdListener.h"
#include "FwmarkServer.h"
-static void coldboot(const char *path);
-static void sigchld_handler(int sig);
static void blockSigpipe();
int main() {
@@ -50,7 +48,6 @@
ALOGI("Netd 1.0 starting");
-// signal(SIGCHLD, sigchld_handler);
blockSigpipe();
if (!(nm = NetlinkManager::Instance())) {
@@ -105,56 +102,6 @@
exit(0);
}
-static void do_coldboot(DIR *d, int lvl)
-{
- struct dirent *de;
- int dfd, fd;
-
- dfd = dirfd(d);
-
- fd = openat(dfd, "uevent", O_WRONLY);
- if(fd >= 0) {
- write(fd, "add\n", 4);
- close(fd);
- }
-
- while((de = readdir(d))) {
- DIR *d2;
-
- if (de->d_name[0] == '.')
- continue;
-
- if (de->d_type != DT_DIR && lvl > 0)
- continue;
-
- fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
- if(fd < 0)
- continue;
-
- d2 = fdopendir(fd);
- if(d2 == 0)
- close(fd);
- else {
- do_coldboot(d2, lvl + 1);
- closedir(d2);
- }
- }
-}
-
-static void coldboot(const char *path)
-{
- DIR *d = opendir(path);
- if(d) {
- do_coldboot(d, 0);
- closedir(d);
- }
-}
-
-static void sigchld_handler(int sig) {
- pid_t pid = wait(NULL);
- ALOGD("Child process %d exited", pid);
-}
-
static void blockSigpipe()
{
sigset_t mask;