diff options
| -rw-r--r-- | adb/Android.mk | 33 | ||||
| -rw-r--r-- | include/cutils/jstring.h | 2 | ||||
| -rw-r--r-- | libcutils/properties.c | 11 | ||||
| -rw-r--r-- | libcutils/socket_inaddr_any_server.c | 13 | ||||
| -rw-r--r-- | libcutils/socket_local_client.c | 9 | ||||
| -rw-r--r-- | libcutils/socket_local_server.c | 11 | ||||
| -rw-r--r-- | libcutils/socket_loopback_client.c | 15 | ||||
| -rw-r--r-- | libcutils/socket_loopback_server.c | 15 | ||||
| -rw-r--r-- | libcutils/socket_network_client.c | 15 | ||||
| -rw-r--r-- | libcutils/uevent.c | 15 | ||||
| -rw-r--r-- | libnetutils/ifc_utils.c | 50 | ||||
| -rw-r--r-- | libnetutils/packet.c | 17 | ||||
| -rw-r--r-- | logcat/logcat.cpp | 6 |
13 files changed, 139 insertions, 73 deletions
diff --git a/adb/Android.mk b/adb/Android.mk index 3e23ac7a..3bed53bf 100644 --- a/adb/Android.mk +++ b/adb/Android.mk @@ -72,7 +72,16 @@ else LOCAL_SRC_FILES += fdevent.c endif -LOCAL_CFLAGS += -O2 -g -DADB_HOST=1 -Wall -Wno-unused-parameter +LOCAL_CFLAGS += -g -DADB_HOST=1 -Wall -Wno-unused-parameter +# adb can't be built without optimizations, so we enforce -O2 if no +# other optimization flag is set - but we don't override what the global +# flags are saying if something else is given (-Os or -O3 are useful) +ifeq ($(findstring -O, $(HOST_GLOBAL_CFLAGS)),) +LOCAL_CFLAGS += -O2 +endif +ifneq ($(findstring -O0, $(HOST_GLOBAL_CFLAGS)),) +LOCAL_CFLAGS += -O2 +endif LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE LOCAL_MODULE := adb @@ -114,7 +123,16 @@ LOCAL_SRC_FILES := \ log_service.c \ utils.c -LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter +LOCAL_CFLAGS := -g -DADB_HOST=0 -Wall -Wno-unused-parameter +# adb can't be built without optimizations, so we enforce -O2 if no +# other optimization flag is set - but we don't override what the global +# flags are saying if something else is given (-Os or -O3 are useful) +ifeq ($(findstring -O, $(TARGET_GLOBAL_CFLAGS)),) +LOCAL_CFLAGS += -O2 +endif +ifneq ($(findstring -O0, $(TARGET_GLOBAL_CFLAGS)),) +LOCAL_CFLAGS += -O2 +endif LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) @@ -160,7 +178,6 @@ LOCAL_SRC_FILES := \ fdevent.c LOCAL_CFLAGS := \ - -O2 \ -g \ -DADB_HOST=1 \ -DADB_HOST_ON_TARGET=1 \ @@ -169,6 +186,16 @@ LOCAL_CFLAGS := \ -D_XOPEN_SOURCE \ -D_GNU_SOURCE +# adb can't be built without optimizations, so we enforce -O2 if no +# other optimization flag is set - but we don't override what the global +# flags are saying if something else is given (-Os or -O3 are useful) +ifeq ($(findstring -O, $(TARGET_GLOBAL_CFLAGS)),) +LOCAL_CFLAGS += -O2 +endif +ifneq ($(findstring -O0, $(TARGET_GLOBAL_CFLAGS)),) +LOCAL_CFLAGS += -O2 +endif + LOCAL_MODULE := adb LOCAL_STATIC_LIBRARIES := libzipfile libunz libcutils diff --git a/include/cutils/jstring.h b/include/cutils/jstring.h index ee0018fc..bf729731 100644 --- a/include/cutils/jstring.h +++ b/include/cutils/jstring.h @@ -24,7 +24,9 @@ extern "C" { #endif +#if __cplusplus < 201103L && !defined(__GXX_EXPERIMENTAL_CXX0X__) typedef uint16_t char16_t; +#endif extern char * strndup16to8 (const char16_t* s, size_t n); extern size_t strnlen16to8 (const char16_t* s, size_t n); diff --git a/libcutils/properties.c b/libcutils/properties.c index 9c46b795..6c3aab88 100644 --- a/libcutils/properties.c +++ b/libcutils/properties.c @@ -100,7 +100,10 @@ static int connectToServer(const char* fileName) int sock = -1; int cc; - struct sockaddr_un addr; + union { + struct sockaddr_un un; + struct sockaddr generic; + } addr; sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -109,9 +112,9 @@ static int connectToServer(const char* fileName) } /* connect to socket; fails if file doesn't exist */ - strcpy(addr.sun_path, fileName); // max 108 bytes - addr.sun_family = AF_UNIX; - cc = connect(sock, (struct sockaddr*) &addr, SUN_LEN(&addr)); + strcpy(addr.un.sun_path, fileName); // max 108 bytes + addr.un.sun_family = AF_UNIX; + cc = connect(sock, &addr.generic, SUN_LEN(&addr.un)); if (cc < 0) { // ENOENT means socket file doesn't exist // ECONNREFUSED means socket exists but nobody is listening diff --git a/libcutils/socket_inaddr_any_server.c b/libcutils/socket_inaddr_any_server.c index 7d5dab4c..d57db118 100644 --- a/libcutils/socket_inaddr_any_server.c +++ b/libcutils/socket_inaddr_any_server.c @@ -35,14 +35,17 @@ /* open listen() port on any interface */ int socket_inaddr_any_server(int port, int type) { - struct sockaddr_in addr; + union { + struct sockaddr_in in; + struct sockaddr generic; + } addr; size_t alen; int s, n; memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = htonl(INADDR_ANY); + addr.in.sin_family = AF_INET; + addr.in.sin_port = htons(port); + addr.in.sin_addr.s_addr = htonl(INADDR_ANY); s = socket(AF_INET, type, 0); if(s < 0) return -1; @@ -50,7 +53,7 @@ int socket_inaddr_any_server(int port, int type) n = 1; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)); - if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if(bind(s, &addr.generic, sizeof(addr.in)) < 0) { close(s); return -1; } diff --git a/libcutils/socket_local_client.c b/libcutils/socket_local_client.c index 036ce2ef..45466a17 100644 --- a/libcutils/socket_local_client.c +++ b/libcutils/socket_local_client.c @@ -124,18 +124,21 @@ error: int socket_local_client_connect(int fd, const char *name, int namespaceId, int type) { - struct sockaddr_un addr; + union { + struct sockaddr_un un; + struct sockaddr generic; + } addr; socklen_t alen; size_t namelen; int err; - err = socket_make_sockaddr_un(name, namespaceId, &addr, &alen); + err = socket_make_sockaddr_un(name, namespaceId, &addr.un, &alen); if (err < 0) { goto error; } - if(connect(fd, (struct sockaddr *) &addr, alen) < 0) { + if(connect(fd, &addr.generic, alen) < 0) { goto error; } diff --git a/libcutils/socket_local_server.c b/libcutils/socket_local_server.c index 4971b1b1..830fd0f0 100644 --- a/libcutils/socket_local_server.c +++ b/libcutils/socket_local_server.c @@ -52,12 +52,15 @@ int socket_local_server(const char *name, int namespaceId, int type) */ int socket_local_server_bind(int s, const char *name, int namespaceId) { - struct sockaddr_un addr; + union { + struct sockaddr_un un; + struct sockaddr generic; + } addr; socklen_t alen; int n; int err; - err = socket_make_sockaddr_un(name, namespaceId, &addr, &alen); + err = socket_make_sockaddr_un(name, namespaceId, &addr.un, &alen); if (err < 0) { return -1; @@ -71,13 +74,13 @@ int socket_local_server_bind(int s, const char *name, int namespaceId) || namespaceId == ANDROID_SOCKET_NAMESPACE_FILESYSTEM) { #endif /*ignore ENOENT*/ - unlink(addr.sun_path); + unlink(addr.un.sun_path); } n = 1; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)); - if(bind(s, (struct sockaddr *) &addr, alen) < 0) { + if(bind(s, &addr.generic, alen) < 0) { return -1; } diff --git a/libcutils/socket_loopback_client.c b/libcutils/socket_loopback_client.c index cb82c5ed..f7c749c5 100644 --- a/libcutils/socket_loopback_client.c +++ b/libcutils/socket_loopback_client.c @@ -36,19 +36,22 @@ */ int socket_loopback_client(int port, int type) { - struct sockaddr_in addr; + union { + struct sockaddr_in in; + struct sockaddr generic; + } addr; socklen_t alen; int s; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + memset(&addr.in, 0, sizeof(addr.in)); + addr.in.sin_family = AF_INET; + addr.in.sin_port = htons(port); + addr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); s = socket(AF_INET, type, 0); if(s < 0) return -1; - if(connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if(connect(s, &addr.generic, sizeof(addr.in)) < 0) { close(s); return -1; } diff --git a/libcutils/socket_loopback_server.c b/libcutils/socket_loopback_server.c index 3208488a..bed6f94b 100644 --- a/libcutils/socket_loopback_server.c +++ b/libcutils/socket_loopback_server.c @@ -35,14 +35,17 @@ /* open listen() port on loopback interface */ int socket_loopback_server(int port, int type) { - struct sockaddr_in addr; + union { + struct sockaddr_in in; + struct sockaddr generic; + } addr; size_t alen; int s, n; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(port); - addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + memset(&addr.in, 0, sizeof(addr.in)); + addr.in.sin_family = AF_INET; + addr.in.sin_port = htons(port); + addr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); s = socket(AF_INET, type, 0); if(s < 0) return -1; @@ -50,7 +53,7 @@ int socket_loopback_server(int port, int type) n = 1; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)); - if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if(bind(s, &addr.generic, sizeof(addr.in)) < 0) { close(s); return -1; } diff --git a/libcutils/socket_network_client.c b/libcutils/socket_network_client.c index a64006cd..37e1c6cc 100644 --- a/libcutils/socket_network_client.c +++ b/libcutils/socket_network_client.c @@ -39,22 +39,25 @@ int socket_network_client(const char *host, int port, int type) { struct hostent *hp; - struct sockaddr_in addr; + union { + struct sockaddr_in in; + struct sockaddr generic; + } addr; socklen_t alen; int s; hp = gethostbyname(host); if(hp == 0) return -1; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = hp->h_addrtype; - addr.sin_port = htons(port); - memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); + memset(&addr.in, 0, sizeof(addr.in)); + addr.in.sin_family = hp->h_addrtype; + addr.in.sin_port = htons(port); + memcpy(&addr.in.sin_addr, hp->h_addr, hp->h_length); s = socket(hp->h_addrtype, type, 0); if(s < 0) return -1; - if(connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if(connect(s, &addr.generic, sizeof(addr.in)) < 0) { close(s); return -1; } diff --git a/libcutils/uevent.c b/libcutils/uevent.c index 97a81e30..42d9d901 100644 --- a/libcutils/uevent.c +++ b/libcutils/uevent.c @@ -95,14 +95,17 @@ out: int uevent_open_socket(int buf_sz, bool passcred) { - struct sockaddr_nl addr; + union { + struct sockaddr_nl nl; + struct sockaddr generic; + } addr; int on = passcred; int s; - memset(&addr, 0, sizeof(addr)); - addr.nl_family = AF_NETLINK; - addr.nl_pid = getpid(); - addr.nl_groups = 0xffffffff; + memset(&addr.nl, 0, sizeof(addr.nl)); + addr.nl.nl_family = AF_NETLINK; + addr.nl.nl_pid = getpid(); + addr.nl.nl_groups = 0xffffffff; s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); if(s < 0) @@ -111,7 +114,7 @@ int uevent_open_socket(int buf_sz, bool passcred) setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &buf_sz, sizeof(buf_sz)); setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); - if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if(bind(s, &addr.generic, sizeof(addr.nl)) < 0) { close(s); return -1; } diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index c52268ab..a3579a4c 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c @@ -248,7 +248,11 @@ int ifc_set_addr(const char *name, in_addr_t addr) int ifc_act_on_address(int action, const char *name, const char *address, int prefixlen) { int ifindex, s, len, ret; - struct sockaddr_storage ss; + union { + struct sockaddr_storage ss; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + } sa; void *addr; size_t addrlen; struct { @@ -260,11 +264,13 @@ int ifc_act_on_address(int action, const char *name, const char *address, NLMSG_ALIGN(INET6_ADDRLEN)]; } req; struct rtattr *rta; - struct nlmsghdr *nh; struct nlmsgerr *err; - char buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + - NLMSG_ALIGN(sizeof(struct nlmsgerr)) + - NLMSG_ALIGN(sizeof(struct nlmsghdr))]; + union { + struct nlmsghdr nh; + char buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + + NLMSG_ALIGN(sizeof(struct nlmsgerr)) + + NLMSG_ALIGN(sizeof(struct nlmsghdr))]; + } buf; // Get interface ID. ifindex = if_nametoindex(name); @@ -273,19 +279,17 @@ int ifc_act_on_address(int action, const char *name, const char *address, } // Convert string representation to sockaddr_storage. - ret = string_to_ip(address, &ss); + ret = string_to_ip(address, &sa.ss); if (ret) { return ret; } // Determine address type and length. - if (ss.ss_family == AF_INET) { - struct sockaddr_in *sin = (struct sockaddr_in *) &ss; - addr = &sin->sin_addr; + if (sa.ss.ss_family == AF_INET) { + addr = &sa.sin.sin_addr; addrlen = INET_ADDRLEN; - } else if (ss.ss_family == AF_INET6) { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &ss; - addr = &sin6->sin6_addr; + } else if (sa.ss.ss_family == AF_INET6) { + addr = &sa.sin6.sin6_addr; addrlen = INET6_ADDRLEN; } else { return -EAFNOSUPPORT; @@ -301,7 +305,7 @@ int ifc_act_on_address(int action, const char *name, const char *address, req.n.nlmsg_pid = getpid(); // Interface address message header. - req.r.ifa_family = ss.ss_family; + req.r.ifa_family = sa.ss.ss_family; req.r.ifa_prefixlen = prefixlen; req.r.ifa_index = ifindex; @@ -318,18 +322,17 @@ int ifc_act_on_address(int action, const char *name, const char *address, return -errno; } - len = recv(s, buf, sizeof(buf), 0); + len = recv(s, buf.buf, sizeof(buf.buf), 0); close(s); if (len < 0) { return -errno; } // Parse the acknowledgement to find the return code. - nh = (struct nlmsghdr *) buf; - if (!NLMSG_OK(nh, (unsigned) len) || nh->nlmsg_type != NLMSG_ERROR) { + if (!NLMSG_OK(&buf.nh, (unsigned) len) || buf.nh.nlmsg_type != NLMSG_ERROR) { return -EINVAL; } - err = NLMSG_DATA(nh); + err = NLMSG_DATA(&buf.nh); // Return code is negative errno. return err->error; @@ -463,7 +466,10 @@ int ifc_get_addr(const char *name, in_addr_t *addr) if (ret < 0) { *addr = 0; } else { - *addr = ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr; + struct sockaddr_in in; + memcpy(&in, &ifr.ifr_addr, sizeof(ifr.ifr_addr)); + memcpy(&addr, &in.sin_addr.s_addr, sizeof(struct sockaddr_in)); + //*addr = ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr; } } return ret; @@ -478,7 +484,9 @@ int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength, unsigned if(ioctl(ifc_ctl_sock, SIOCGIFADDR, &ifr) < 0) { *addr = 0; } else { - *addr = ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr; + struct sockaddr_in in; + memcpy(&in, &ifr.ifr_addr, sizeof(in)); + *addr = in.sin_addr.s_addr; } } @@ -486,8 +494,10 @@ int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength, unsigned if(ioctl(ifc_ctl_sock, SIOCGIFNETMASK, &ifr) < 0) { *prefixLength = 0; } else { + struct sockaddr_in in; + memcpy(&in, &ifr.ifr_addr, sizeof(in)); *prefixLength = ipv4NetmaskToPrefixLength((int) - ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr); + in.sin_addr.s_addr); } } diff --git a/libnetutils/packet.c b/libnetutils/packet.c index 3ec83fe0..c1c6381f 100644 --- a/libnetutils/packet.c +++ b/libnetutils/packet.c @@ -42,20 +42,23 @@ int fatal(); int open_raw_socket(const char *ifname, uint8_t *hwaddr, int if_index) { int s, flag; - struct sockaddr_ll bindaddr; + union { + struct sockaddr_ll ll; + struct sockaddr generic; + } bindaddr; if((s = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { return fatal("socket(PF_PACKET)"); } memset(&bindaddr, 0, sizeof(bindaddr)); - bindaddr.sll_family = AF_PACKET; - bindaddr.sll_protocol = htons(ETH_P_IP); - bindaddr.sll_halen = ETH_ALEN; - memcpy(bindaddr.sll_addr, hwaddr, ETH_ALEN); - bindaddr.sll_ifindex = if_index; + bindaddr.ll.sll_family = AF_PACKET; + bindaddr.ll.sll_protocol = htons(ETH_P_IP); + bindaddr.ll.sll_halen = ETH_ALEN; + memcpy(bindaddr.ll.sll_addr, hwaddr, ETH_ALEN); + bindaddr.ll.sll_ifindex = if_index; - if (bind(s, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) { + if (bind(s, &bindaddr.generic, sizeof(bindaddr.ll)) < 0) { return fatal("Cannot bind raw socket to interface"); } diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index ef637c47..9d9a7219 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -669,14 +669,14 @@ int main(int argc, char **argv) } if (!devices) { - devices = new log_device_t(strdup("/dev/"LOGGER_LOG_MAIN), false, 'm'); + devices = new log_device_t(strdup("/dev/" LOGGER_LOG_MAIN), false, 'm'); android::g_devCount = 1; int accessmode = (mode & O_RDONLY) ? R_OK : 0 | (mode & O_WRONLY) ? W_OK : 0; // only add this if it's available - if (0 == access("/dev/"LOGGER_LOG_SYSTEM, accessmode)) { - devices->next = new log_device_t(strdup("/dev/"LOGGER_LOG_SYSTEM), false, 's'); + if (0 == access("/dev/" LOGGER_LOG_SYSTEM, accessmode)) { + devices->next = new log_device_t(strdup("/dev/" LOGGER_LOG_SYSTEM), false, 's'); android::g_devCount++; } } |
