Merge "Reject zip archives whose entry names are not valid UTF-8."
diff --git a/adb/framebuffer_service.c b/adb/framebuffer_service.c
index 8cbe840..61578aa 100644
--- a/adb/framebuffer_service.c
+++ b/adb/framebuffer_service.c
@@ -76,6 +76,7 @@
exit(1);
}
+ close(fds[1]);
fd_screencap = fds[0];
/* read w, h & format */
@@ -173,10 +174,9 @@
}
done:
- TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));
-
close(fds[0]);
- close(fds[1]);
+
+ TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));
pipefail:
close(fd);
}
diff --git a/fastboot/fastboot_protocol.txt b/fastboot/fastboot_protocol.txt
index 2248992..37b1959 100644
--- a/fastboot/fastboot_protocol.txt
+++ b/fastboot/fastboot_protocol.txt
@@ -12,8 +12,8 @@
------------------
* Two bulk endpoints (in, out) are required
-* Max packet size must be 64 bytes for full-speed and 512 bytes for
- high-speed USB
+* Max packet size must be 64 bytes for full-speed, 512 bytes for
+ high-speed and 1024 bytes for Super Speed USB.
* The protocol is entirely host-driven and synchronous (unlike the
multi-channel, bi-directional, asynchronous ADB protocol)
diff --git a/fastboot/protocol.c b/fastboot/protocol.c
index 84e9837..10a84c1 100644
--- a/fastboot/protocol.c
+++ b/fastboot/protocol.c
@@ -216,7 +216,7 @@
}
}
-#define USB_BUF_SIZE 512
+#define USB_BUF_SIZE 1024
static char usb_buf[USB_BUF_SIZE];
static int usb_buf_len;
diff --git a/libpixelflinger/Android.mk b/libpixelflinger/Android.mk
index da9829d..f1bd522 100644
--- a/libpixelflinger/Android.mk
+++ b/libpixelflinger/Android.mk
@@ -36,6 +36,7 @@
ifeq ($(ARCH_ARM_HAVE_NEON),true)
PIXELFLINGER_SRC_FILES_arm += col32cb16blend_neon.S
+PIXELFLINGER_CFLAGS_arm += -D__ARM_HAVE_NEON
endif
PIXELFLINGER_SRC_FILES_arm64 := \
diff --git a/libpixelflinger/codeflinger/load_store.cpp b/libpixelflinger/codeflinger/load_store.cpp
index 0a46eaa..e5a1ae0 100644
--- a/libpixelflinger/codeflinger/load_store.cpp
+++ b/libpixelflinger/codeflinger/load_store.cpp
@@ -20,10 +20,6 @@
#include <cutils/log.h>
#include "GGLAssembler.h"
-#ifdef __ARM_ARCH__
-#include <machine/cpu-features.h>
-#endif
-
namespace android {
// ----------------------------------------------------------------------------
@@ -117,20 +113,6 @@
#endif
assert(h);
-#if __ARM_ARCH__ >= 7
- const int mask = (1<<maskLen)-1;
- if ((h == bits) && !l && (s != d.reg)) {
- MOV(AL, 0, d.reg, s); // component = packed;
- } else if ((h == bits) && l) {
- MOV(AL, 0, d.reg, reg_imm(s, LSR, l)); // component = packed >> l;
- } else if (!l && isValidImmediate(mask)) {
- AND(AL, 0, d.reg, s, imm(mask)); // component = packed & mask;
- } else if (!l && isValidImmediate(~mask)) {
- BIC(AL, 0, d.reg, s, imm(~mask)); // component = packed & mask;
- } else {
- UBFX(AL, d.reg, s, l, maskLen); // component = (packed & mask) >> l;
- }
-#else
if (h != bits) {
const int mask = ((1<<maskLen)-1) << l;
if (isValidImmediate(mask)) {
@@ -153,7 +135,6 @@
if (s != d.reg) {
MOV(AL, 0, d.reg, s);
}
-#endif
d.s = maskLen;
}
diff --git a/libpixelflinger/codeflinger/texturing.cpp b/libpixelflinger/codeflinger/texturing.cpp
index 81950bf..29a3742 100644
--- a/libpixelflinger/codeflinger/texturing.cpp
+++ b/libpixelflinger/codeflinger/texturing.cpp
@@ -25,10 +25,6 @@
#include "GGLAssembler.h"
-#ifdef __ARM_ARCH__
-#include <machine/cpu-features.h>
-#endif
-
namespace android {
// ---------------------------------------------------------------------------
@@ -888,106 +884,6 @@
load(txPtr, texel, 0);
}
-#if __ARM_ARCH__ >= 6
-// ARMv6 version, using UXTB16, and scheduled for Cortex-A8 pipeline
-void GGLAssembler::filter32(
- const fragment_parts_t& parts,
- pixel_t& texel, const texture_unit_t& tmu,
- int U, int V, pointer_t& txPtr,
- int FRAC_BITS)
-{
- const int adjust = FRAC_BITS*2 - 8;
- const int round = 0;
- const int prescale = 16 - adjust;
-
- Scratch scratches(registerFile());
-
- int pixel= scratches.obtain();
- int dh = scratches.obtain();
- int u = scratches.obtain();
- int k = scratches.obtain();
-
- int temp = scratches.obtain();
- int dl = scratches.obtain();
-
- int offsetrt = scratches.obtain();
- int offsetlb = scratches.obtain();
-
- int pixellb = offsetlb;
-
- // RB -> U * V
- CONTEXT_LOAD(offsetrt, generated_vars.rt);
- CONTEXT_LOAD(offsetlb, generated_vars.lb);
- if(!round) {
- MOV(AL, 0, U, reg_imm(U, LSL, prescale));
- }
- ADD(AL, 0, u, offsetrt, offsetlb);
-
- LDR(AL, pixel, txPtr.reg, reg_scale_pre(u));
- if (round) {
- SMULBB(AL, u, U, V);
- RSB(AL, 0, U, U, imm(1<<FRAC_BITS));
- } else {
- SMULWB(AL, u, U, V);
- RSB(AL, 0, U, U, imm(1<<(FRAC_BITS+prescale)));
- }
- UXTB16(AL, temp, pixel, 0);
- if (round) {
- ADD(AL, 0, u, u, imm(1<<(adjust-1)));
- MOV(AL, 0, u, reg_imm(u, LSR, adjust));
- }
- LDR(AL, pixellb, txPtr.reg, reg_scale_pre(offsetlb));
- MUL(AL, 0, dh, temp, u);
- UXTB16(AL, temp, pixel, 8);
- MUL(AL, 0, dl, temp, u);
- RSB(AL, 0, k, u, imm(0x100));
-
- // LB -> (1-U) * V
- if (round) {
- SMULBB(AL, u, U, V);
- } else {
- SMULWB(AL, u, U, V);
- }
- UXTB16(AL, temp, pixellb, 0);
- if (round) {
- ADD(AL, 0, u, u, imm(1<<(adjust-1)));
- MOV(AL, 0, u, reg_imm(u, LSR, adjust));
- }
- MLA(AL, 0, dh, temp, u, dh);
- UXTB16(AL, temp, pixellb, 8);
- MLA(AL, 0, dl, temp, u, dl);
- SUB(AL, 0, k, k, u);
-
- // LT -> (1-U)*(1-V)
- RSB(AL, 0, V, V, imm(1<<FRAC_BITS));
- LDR(AL, pixel, txPtr.reg);
- if (round) {
- SMULBB(AL, u, U, V);
- } else {
- SMULWB(AL, u, U, V);
- }
- UXTB16(AL, temp, pixel, 0);
- if (round) {
- ADD(AL, 0, u, u, imm(1<<(adjust-1)));
- MOV(AL, 0, u, reg_imm(u, LSR, adjust));
- }
- MLA(AL, 0, dh, temp, u, dh);
- UXTB16(AL, temp, pixel, 8);
- MLA(AL, 0, dl, temp, u, dl);
-
- // RT -> U*(1-V)
- LDR(AL, pixel, txPtr.reg, reg_scale_pre(offsetrt));
- SUB(AL, 0, u, k, u);
- UXTB16(AL, temp, pixel, 0);
- MLA(AL, 0, dh, temp, u, dh);
- UXTB16(AL, temp, pixel, 8);
- MLA(AL, 0, dl, temp, u, dl);
-
- UXTB16(AL, dh, dh, 8);
- UXTB16(AL, dl, dl, 8);
- ORR(AL, 0, texel.reg, dh, reg_imm(dl, LSL, 8));
-}
-#else
void GGLAssembler::filter32(
const fragment_parts_t& /*parts*/,
pixel_t& texel, const texture_unit_t& /*tmu*/,
@@ -1075,7 +971,6 @@
AND(AL, 0, dl, dl, reg_imm(mask, LSL, 8));
ORR(AL, 0, texel.reg, dh, dl);
}
-#endif
void GGLAssembler::build_texture_environment(
component_t& fragment,
diff --git a/libutils/Android.mk b/libutils/Android.mk
index e738c15..52de910 100644
--- a/libutils/Android.mk
+++ b/libutils/Android.mk
@@ -53,13 +53,6 @@
endif
endif
-host_commonLdlibs :=
-
-ifeq ($(TARGET_OS),linux)
-host_commonLdlibs += -lrt -ldl
-endif
-
-
# For the host
# =====================================================
include $(CLEAR_VARS)
@@ -93,9 +86,6 @@
endif
LOCAL_CFLAGS += -Werror
-LOCAL_C_INCLUDES += \
- external/zlib
-
LOCAL_STATIC_LIBRARIES := \
libcutils
diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp
index dbad581..ac3dd98 100644
--- a/libutils/SystemClock.cpp
+++ b/libutils/SystemClock.cpp
@@ -68,7 +68,7 @@
*/
#define DEBUG_TIMESTAMP 0
-#if DEBUG_TIMESTAMP && defined(ARCH_ARM)
+#if DEBUG_TIMESTAMP && defined(__arm__)
static inline void checkTimeStamps(int64_t timestamp,
int64_t volatile *prevTimestampPtr,
int volatile *prevMethodPtr,
diff --git a/libziparchive/Android.mk b/libziparchive/Android.mk
index b801a4b..ba7b74d 100644
--- a/libziparchive/Android.mk
+++ b/libziparchive/Android.mk
@@ -16,7 +16,6 @@
LOCAL_PATH := $(call my-dir)
source_files := zip_archive.cc
-includes := external/zlib
include $(CLEAR_VARS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
@@ -25,16 +24,13 @@
LOCAL_STATIC_LIBRARIES := libz
LOCAL_SHARED_LIBRARIES := libutils
LOCAL_MODULE:= libziparchive
-LOCAL_C_INCLUDES += ${includes}
LOCAL_CFLAGS := -Werror
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_MODULE := libziparchive
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := ${source_files}
-LOCAL_C_INCLUDES += ${includes}
LOCAL_STATIC_LIBRARIES := libz libutils
LOCAL_MODULE:= libziparchive-host
LOCAL_CFLAGS := -Werror
@@ -46,10 +42,8 @@
include $(CLEAR_VARS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_MODULE := libziparchive
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := ${source_files}
-LOCAL_C_INCLUDES += ${includes}
LOCAL_STATIC_LIBRARIES := libz libutils
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE:= libziparchive-host
diff --git a/libzipfile/Android.mk b/libzipfile/Android.mk
index 12a2229..f054e15 100644
--- a/libzipfile/Android.mk
+++ b/libzipfile/Android.mk
@@ -7,13 +7,10 @@
centraldir.c \
zipfile.c
-LOCAL_STATIC_LIBRARIES := \
- libunz
+LOCAL_STATIC_LIBRARIES := libz
LOCAL_MODULE:= libzipfile
-LOCAL_C_INCLUDES += external/zlib
-
LOCAL_CFLAGS := -Werror
LOCAL_MULTILIB := both
@@ -27,13 +24,10 @@
centraldir.c \
zipfile.c
-LOCAL_STATIC_LIBRARIES := \
- libunz
+LOCAL_STATIC_LIBRARIES := libz
LOCAL_MODULE:= libzipfile
-LOCAL_C_INCLUDES += external/zlib
-
LOCAL_CFLAGS := -Werror
include $(BUILD_STATIC_LIBRARY)
@@ -45,12 +39,10 @@
LOCAL_SRC_FILES:= \
test_zipfile.c
-LOCAL_STATIC_LIBRARIES := libzipfile libunz
+LOCAL_STATIC_LIBRARIES := libzipfile libz
LOCAL_MODULE := test_zipfile
-LOCAL_C_INCLUDES += external/zlib
-
LOCAL_CFLAGS := -Werror
include $(BUILD_HOST_EXECUTABLE)
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 6306f5c..79f2ebd 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -455,36 +455,31 @@
delete dev;
}
- dev = devices = new log_device_t("main", false, 'm');
- android::g_devCount = 1;
- if (android_name_to_log_id("system") == LOG_ID_SYSTEM) {
- dev->next = new log_device_t("system", false, 's');
- if (dev->next) {
- dev = dev->next;
- android::g_devCount++;
+ devices = dev = NULL;
+ android::g_devCount = 0;
+ needBinary = false;
+ for(int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
+ const char *name = android_log_id_to_name((log_id_t)i);
+ log_id_t log_id = android_name_to_log_id(name);
+
+ if (log_id != (log_id_t)i) {
+ continue;
}
- }
- if (android_name_to_log_id("radio") == LOG_ID_RADIO) {
- dev->next = new log_device_t("radio", false, 'r');
- if (dev->next) {
- dev = dev->next;
- android::g_devCount++;
+
+ bool binary = strcmp(name, "events") == 0;
+ log_device_t* d = new log_device_t(name, binary, *name);
+
+ if (dev) {
+ dev->next = d;
+ dev = d;
+ } else {
+ devices = dev = d;
}
- }
- if (android_name_to_log_id("events") == LOG_ID_EVENTS) {
- dev->next = new log_device_t("events", true, 'e');
- if (dev->next) {
- dev = dev->next;
- android::g_devCount++;
+ android::g_devCount++;
+ if (binary) {
needBinary = true;
}
}
- if (android_name_to_log_id("crash") == LOG_ID_CRASH) {
- dev->next = new log_device_t("crash", false, 'c');
- if (dev->next) {
- android::g_devCount++;
- }
- }
break;
}
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp
index ee2f32d..c7c0249 100644
--- a/logd/LogAudit.cpp
+++ b/logd/LogAudit.cpp
@@ -19,7 +19,6 @@
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
-#include <sys/klog.h>
#include <sys/prctl.h>
#include <sys/uio.h>
#include <syslog.h>
@@ -33,21 +32,23 @@
'0' + (LOG_AUTH | (PRI)) % 10, \
'>'
-LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmsg)
+LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmesg)
: SocketListener(getLogSocket(), false)
, logbuf(buf)
, reader(reader)
- , fdDmesg(-1) {
+ , fdDmesg(fdDmesg)
+ , initialized(false) {
static const char auditd_message[] = { KMSG_PRIORITY(LOG_INFO),
'l', 'o', 'g', 'd', '.', 'a', 'u', 'd', 'i', 't', 'd', ':',
' ', 's', 't', 'a', 'r', 't', '\n' };
- write(fdDmsg, auditd_message, sizeof(auditd_message));
- logDmesg();
- fdDmesg = fdDmsg;
+ write(fdDmesg, auditd_message, sizeof(auditd_message));
}
bool LogAudit::onDataAvailable(SocketClient *cli) {
- prctl(PR_SET_NAME, "logd.auditd");
+ if (!initialized) {
+ prctl(PR_SET_NAME, "logd.auditd");
+ initialized = true;
+ }
struct audit_message rep;
@@ -60,7 +61,8 @@
return false;
}
- logPrint("type=%d %.*s", rep.nlh.nlmsg_type, rep.nlh.nlmsg_len, rep.data);
+ logPrint("type=%d %.*s",
+ rep.nlh.nlmsg_type, rep.nlh.nlmsg_len, rep.data);
return true;
}
@@ -87,7 +89,7 @@
}
bool info = strstr(str, " permissive=1") || strstr(str, " policy loaded ");
- if (fdDmesg >= 0) {
+ if ((fdDmesg >= 0) && initialized) {
struct iovec iov[3];
static const char log_info[] = { KMSG_PRIORITY(LOG_INFO) };
static const char log_warning[] = { KMSG_PRIORITY(LOG_WARNING) };
@@ -213,34 +215,23 @@
return rc;
}
-void LogAudit::logDmesg() {
- int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
- if (len <= 0) {
- return;
+int LogAudit::log(char *buf) {
+ char *audit = strstr(buf, " audit(");
+ if (!audit) {
+ return 0;
}
- len++;
- char buf[len];
+ *audit = '\0';
- int rc = klogctl(KLOG_READ_ALL, buf, len);
-
- buf[len - 1] = '\0';
-
- for(char *tok = buf; (rc >= 0) && ((tok = strtok(tok, "\r\n"))); tok = NULL) {
- char *audit = strstr(tok, " audit(");
- if (!audit) {
- continue;
- }
-
- *audit++ = '\0';
-
- char *type = strstr(tok, "type=");
- if (type) {
- rc = logPrint("%s %s", type, audit);
- } else {
- rc = logPrint("%s", audit);
- }
+ int rc;
+ char *type = strstr(buf, "type=");
+ if (type) {
+ rc = logPrint("%s %s", type, audit + 1);
+ } else {
+ rc = logPrint("%s", audit + 1);
}
+ *audit = ' ';
+ return rc;
}
int LogAudit::getLogSocket() {
diff --git a/logd/LogAudit.h b/logd/LogAudit.h
index 111030a..f977be9 100644
--- a/logd/LogAudit.h
+++ b/logd/LogAudit.h
@@ -24,16 +24,17 @@
LogBuffer *logbuf;
LogReader *reader;
int fdDmesg;
+ bool initialized;
public:
LogAudit(LogBuffer *buf, LogReader *reader, int fdDmesg);
+ int log(char *buf);
protected:
virtual bool onDataAvailable(SocketClient *cli);
private:
static int getLogSocket();
- void logDmesg();
int logPrint(const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
};
diff --git a/logd/main.cpp b/logd/main.cpp
index 54da7e3..946a9a0 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/capability.h>
+#include <sys/klog.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -195,6 +196,23 @@
if (auditd) {
// failure is an option ... messages are in dmesg (required by standard)
LogAudit *al = new LogAudit(logBuf, reader, fdDmesg);
+
+ int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
+ if (len > 0) {
+ len++;
+ char buf[len];
+
+ int rc = klogctl(KLOG_READ_ALL, buf, len);
+
+ buf[len - 1] = '\0';
+
+ for(char *ptr, *tok = buf;
+ (rc >= 0) && ((tok = strtok_r(tok, "\r\n", &ptr)));
+ tok = NULL) {
+ rc = al->log(tok);
+ }
+ }
+
if (al->startListener()) {
delete al;
close(fdDmesg);
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 6fdf610..249f91e 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -7,6 +7,10 @@
-I$(LOCAL_PATH)/upstream-netbsd/include/ \
-include bsd-compatibility.h \
+# Temporary, remove after cleanup. b/18632512
+common_cflags += -Wno-unused-variable \
+ -Wno-unused-but-set-variable
+
include $(CLEAR_VARS)
LOCAL_SRC_FILES := upstream-netbsd/bin/cat/cat.c
@@ -64,13 +68,6 @@
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := upstream-netbsd/bin/kill/kill.c
-LOCAL_CFLAGS += $(common_cflags) -Dmain=kill_main
-LOCAL_MODULE := libtoolbox_kill
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
LOCAL_SRC_FILES := upstream-netbsd/bin/ln/ln.c
LOCAL_CFLAGS += $(common_cflags) -Dmain=ln_main
LOCAL_MODULE := libtoolbox_ln
@@ -108,7 +105,6 @@
dd \
du \
grep \
- kill \
ln \
mv \
rm \
@@ -159,7 +155,6 @@
touch \
umount \
uptime \
- vmstat \
watchprops \
wipe \
diff --git a/toolbox/upstream-netbsd/bin/kill/kill.c b/toolbox/upstream-netbsd/bin/kill/kill.c
deleted file mode 100644
index 0592577..0000000
--- a/toolbox/upstream-netbsd/bin/kill/kill.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/* $NetBSD: kill.c,v 1.27 2011/08/29 14:51:18 joerg Exp $ */
-
-/*
- * Copyright (c) 1988, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if !defined(lint) && !defined(SHELL)
-__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95";
-#else
-__RCSID("$NetBSD: kill.c,v 1.27 2011/08/29 14:51:18 joerg Exp $");
-#endif
-#endif /* not lint */
-
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <inttypes.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <locale.h>
-#include <sys/ioctl.h>
-
-#ifdef SHELL /* sh (aka ash) builtin */
-int killcmd(int, char *argv[]);
-#define main killcmd
-#include "../../bin/sh/bltin/bltin.h"
-#endif /* SHELL */
-
-__dead static void nosig(char *);
-static void printsignals(FILE *);
-static int signame_to_signum(char *);
-__dead static void usage(void);
-
-int
-main(int argc, char *argv[])
-{
- int errors;
- intmax_t numsig, pid;
- char *ep;
-
- setprogname(argv[0]);
- setlocale(LC_ALL, "");
- if (argc < 2)
- usage();
-
- numsig = SIGTERM;
-
- argc--, argv++;
- if (strcmp(*argv, "-l") == 0) {
- argc--, argv++;
- if (argc > 1)
- usage();
- if (argc == 1) {
- if (isdigit((unsigned char)**argv) == 0)
- usage();
- numsig = strtoimax(*argv, &ep, 10);
- /* check for correctly parsed number */
- if (*ep != '\0' || numsig == INTMAX_MIN || numsig == INTMAX_MAX) {
- errx(EXIT_FAILURE, "illegal signal number: %s",
- *argv);
- /* NOTREACHED */
- }
- if (numsig >= 128)
- numsig -= 128;
- /* and whether it fits into signals range */
- if (numsig <= 0 || numsig >= NSIG)
- nosig(*argv);
- printf("%s\n", sys_signame[(int) numsig]);
- exit(0);
- }
- printsignals(stdout);
- exit(0);
- }
-
- if (!strcmp(*argv, "-s")) {
- argc--, argv++;
- if (argc < 1) {
- warnx("option requires an argument -- s");
- usage();
- }
- if (strcmp(*argv, "0")) {
- if ((numsig = signame_to_signum(*argv)) < 0)
- nosig(*argv);
- } else
- numsig = 0;
- argc--, argv++;
- } else if (**argv == '-') {
- char *sn = *argv + 1;
- if (isalpha((unsigned char)*sn)) {
- if ((numsig = signame_to_signum(sn)) < 0)
- nosig(sn);
- } else if (isdigit((unsigned char)*sn)) {
- numsig = strtoimax(sn, &ep, 10);
- /* check for correctly parsed number */
- if (*ep || numsig == INTMAX_MIN || numsig == INTMAX_MAX ) {
- errx(EXIT_FAILURE, "illegal signal number: %s",
- sn);
- /* NOTREACHED */
- }
- /* and whether it fits into signals range */
- if (numsig < 0 || numsig >= NSIG)
- nosig(sn);
- } else
- nosig(sn);
- argc--, argv++;
- }
-
- if (argc == 0)
- usage();
-
- for (errors = 0; argc; argc--, argv++) {
-#ifdef SHELL
- extern int getjobpgrp(const char *);
- if (*argv[0] == '%') {
- pid = getjobpgrp(*argv);
- if (pid == 0) {
- warnx("illegal job id: %s", *argv);
- errors = 1;
- continue;
- }
- } else
-#endif
- {
- pid = strtoimax(*argv, &ep, 10);
- /* make sure the pid is a number and fits into pid_t */
- if (!**argv || *ep || pid == INTMAX_MIN ||
- pid == INTMAX_MAX || pid != (pid_t) pid) {
-
- warnx("illegal process id: %s", *argv);
- errors = 1;
- continue;
- }
- }
- if (kill((pid_t) pid, (int) numsig) == -1) {
- warn("%s", *argv);
- errors = 1;
- }
-#ifdef SHELL
- /* Wakeup the process if it was suspended, so it can
- exit without an explicit 'fg'. */
- if (numsig == SIGTERM || numsig == SIGHUP)
- kill((pid_t) pid, SIGCONT);
-#endif
- }
-
- exit(errors);
- /* NOTREACHED */
-}
-
-static int
-signame_to_signum(char *sig)
-{
- int n;
-
- if (strncasecmp(sig, "sig", 3) == 0)
- sig += 3;
- for (n = 1; n < NSIG; n++) {
- if (!strcasecmp(sys_signame[n], sig))
- return (n);
- }
- return (-1);
-}
-
-static void
-nosig(char *name)
-{
-
- warnx("unknown signal %s; valid signals:", name);
- printsignals(stderr);
- exit(1);
- /* NOTREACHED */
-}
-
-static void
-printsignals(FILE *fp)
-{
- int sig;
- int len, nl;
- const char *name;
- int termwidth = 80;
-
- if (isatty(fileno(fp))) {
- struct winsize win;
- if (ioctl(fileno(fp), TIOCGWINSZ, &win) == 0 && win.ws_col > 0)
- termwidth = win.ws_col;
- }
-
- for (len = 0, sig = 1; sig < NSIG; sig++) {
- name = sys_signame[sig];
- nl = 1 + strlen(name);
-
- if (len + nl >= termwidth) {
- fprintf(fp, "\n");
- len = 0;
- } else
- if (len != 0)
- fprintf(fp, " ");
- len += nl;
- fprintf(fp, "%s", name);
- }
- if (len != 0)
- fprintf(fp, "\n");
-}
-
-static void
-usage(void)
-{
-
- fprintf(stderr, "usage: %s [-s signal_name] pid ...\n"
- " %s -l [exit_status]\n"
- " %s -signal_name pid ...\n"
- " %s -signal_number pid ...\n",
- getprogname(), getprogname(), getprogname(), getprogname());
- exit(1);
- /* NOTREACHED */
-}
diff --git a/toolbox/vmstat.c b/toolbox/vmstat.c
deleted file mode 100644
index 4086ed0..0000000
--- a/toolbox/vmstat.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (c) 2008, The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google, Inc. nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/param.h>
-#include <unistd.h>
-
-struct state {
- long procs_r;
- long procs_b;
-
- long mem_free;
- long mem_mapped;
- long mem_anon;
- long mem_slab;
-
- long sys_in;
- long sys_cs;
- long sys_flt;
-
- long cpu_us;
- long cpu_ni;
- long cpu_sy;
- long cpu_id;
- long cpu_wa;
- long cpu_ir;
- long cpu_si;
-};
-
-#define MAX_LINE 256
-
-char line[MAX_LINE];
-
-static void read_state(struct state *s);
-static int read_meminfo(struct state *s);
-static int read_stat(struct state *s);
-static int read_vmstat(struct state *s);
-static void print_header(void);
-static void print_line(struct state *old, struct state *new);
-static void usage(char *cmd);
-
-int vmstat_main(int argc, char *argv[]) {
- struct state s[2];
- int iterations, delay, header_interval;
- int toggle, count;
- int i;
-
- iterations = -1;
- delay = 1;
- header_interval = 20;
-
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-n")) {
- if (i >= argc - 1) {
- fprintf(stderr, "Option -n requires an argument.\n");
- exit(EXIT_FAILURE);
- }
- iterations = atoi(argv[++i]);
- continue;
- }
- if (!strcmp(argv[i], "-d")) {
- if (i >= argc - 1) {
- fprintf(stderr, "Option -d requires an argument.\n");
- exit(EXIT_FAILURE);
- }
- delay = atoi(argv[++i]);
- continue;
- }
- if (!strcmp(argv[i], "-r")) {
- if (i >= argc - 1) {
- fprintf(stderr, "Option -r requires an argument.\n");
- exit(EXIT_FAILURE);
- }
- header_interval = atoi(argv[++i]);
- continue;
- }
- if (!strcmp(argv[i], "-h")) {
- usage(argv[0]);
- exit(EXIT_SUCCESS);
- }
- fprintf(stderr, "Invalid argument \"%s\".\n", argv[i]);
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- toggle = 0;
- count = 0;
-
- if (!header_interval)
- print_header();
- read_state(&s[1 - toggle]);
- while ((iterations < 0) || (iterations-- > 0)) {
- sleep(delay);
- read_state(&s[toggle]);
- if (header_interval) {
- if (count == 0)
- print_header();
- count = (count + 1) % header_interval;
- }
- print_line(&s[1 - toggle], &s[toggle]);
- toggle = 1 - toggle;
- }
-
- return 0;
-}
-
-static void read_state(struct state *s) {
- int error;
-
- error = read_meminfo(s);
- if (error) {
- fprintf(stderr, "vmstat: could not read /proc/meminfo: %s\n", strerror(error));
- exit(EXIT_FAILURE);
- }
-
- error = read_stat(s);
- if (error) {
- fprintf(stderr, "vmstat: could not read /proc/stat: %s\n", strerror(error));
- exit(EXIT_FAILURE);
- }
-
- error = read_vmstat(s);
- if (error) {
- fprintf(stderr, "vmstat: could not read /proc/vmstat: %s\n", strerror(error));
- exit(EXIT_FAILURE);
- }
-}
-
-static int read_meminfo(struct state *s) {
- FILE *f;
-
- f = fopen("/proc/meminfo", "r");
- if (!f) return errno;
-
- while (fgets(line, MAX_LINE, f)) {
- sscanf(line, "MemFree: %ld kB", &s->mem_free);
- sscanf(line, "AnonPages: %ld kB", &s->mem_anon);
- sscanf(line, "Mapped: %ld kB", &s->mem_mapped);
- sscanf(line, "Slab: %ld kB", &s->mem_slab);
- }
-
- fclose(f);
-
- return 0;
-}
-
-static int read_stat(struct state *s) {
- FILE *f;
-
- f = fopen("/proc/stat", "r");
- if (!f) return errno;
-
- while (fgets(line, MAX_LINE, f)) {
- if (!strncmp(line, "cpu ", 4)) {
- sscanf(line, "cpu %ld %ld %ld %ld %ld %ld %ld",
- &s->cpu_us, &s->cpu_ni, &s->cpu_sy, &s->cpu_id, &s->cpu_wa,
- &s->cpu_ir, &s->cpu_si);
- }
- sscanf(line, "intr %ld", &s->sys_in);
- sscanf(line, "ctxt %ld", &s->sys_cs);
- sscanf(line, "procs_running %ld", &s->procs_r);
- sscanf(line, "procs_blocked %ld", &s->procs_b);
- }
-
- fclose(f);
-
- return 0;
-}
-
-static int read_vmstat(struct state *s) {
- FILE *f;
-
- f = fopen("/proc/vmstat", "r");
- if (!f) return errno;
-
- while (fgets(line, MAX_LINE, f)) {
- sscanf(line, "pgmajfault %ld", &s->sys_flt);
- }
-
- fclose(f);
-
- return 0;
-}
-
-static void print_header(void) {
- printf("%-5s %-27s %-14s %-17s\n", "procs", "memory", "system", "cpu");
- printf("%2s %2s %6s %6s %6s %6s %4s %4s %4s %2s %2s %2s %2s %2s %2s\n", "r", "b", "free", "mapped", "anon", "slab", "in", "cs", "flt", "us", "ni", "sy", "id", "wa", "ir");
-}
-
-/* Jiffies to percent conversion */
-#define JP(jif) ((jif) * 100 / (HZ))
-#define NORM(var) ((var) = (((var) > 99) ? (99) : (var)))
-
-static void print_line(struct state *old, struct state *new) {
- int us, ni, sy, id, wa, ir;
- us = JP(new->cpu_us - old->cpu_us); NORM(us);
- ni = JP(new->cpu_ni - old->cpu_ni); NORM(ni);
- sy = JP(new->cpu_sy - old->cpu_sy); NORM(sy);
- id = JP(new->cpu_id - old->cpu_id); NORM(id);
- wa = JP(new->cpu_wa - old->cpu_wa); NORM(wa);
- ir = JP(new->cpu_ir - old->cpu_ir); NORM(ir);
- printf("%2ld %2ld %6ld %6ld %6ld %6ld %4ld %4ld %4ld %2d %2d %2d %2d %2d %2d\n",
- new->procs_r ? (new->procs_r - 1) : 0, new->procs_b,
- new->mem_free, new->mem_mapped, new->mem_anon, new->mem_slab,
- new->sys_in - old->sys_in, new->sys_cs - old->sys_cs, new->sys_flt - old->sys_flt,
- us, ni, sy, id, wa, ir);
-}
-
-static void usage(char *cmd) {
- fprintf(stderr, "Usage: %s [ -h ] [ -n iterations ] [ -d delay ] [ -r header_repeat ]\n"
- " -n iterations How many rows of data to print.\n"
- " -d delay How long to sleep between rows.\n"
- " -r header_repeat How many rows to print before repeating\n"
- " the header. Zero means never repeat.\n"
- " -h Displays this help screen.\n",
- cmd);
-}