blob: 1e746cd5c69196398c617ecbc8a4a9b7c9f9ef4f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Egnor52952b12010-01-13 12:27:50 -080017#include <errno.h>
18#include <fcntl.h>
19#include <limits.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <sys/resource.h>
Dan Egnor52952b12010-01-13 12:27:50 -080024#include <sys/stat.h>
25#include <sys/time.h>
Dan Egnorefd13932010-03-08 13:04:13 -080026#include <sys/wait.h>
Dan Egnor52952b12010-01-13 12:27:50 -080027#include <unistd.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Dan Egnor52952b12010-01-13 12:27:50 -080029#include <cutils/properties.h>
30
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031#include "private/android_filesystem_config.h"
32
Mike Lockwoodbb6fa172009-10-05 23:23:40 -040033#define LOG_TAG "dumpstate"
34#include <utils/Log.h>
35
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include "dumpstate.h"
37
Dan Egnor52952b12010-01-13 12:27:50 -080038/* read before root is shed */
39static char cmdline_buf[16384] = "(unknown)";
40static const char *dump_traces_path = NULL;
San Mehat30b9f572009-09-01 13:27:20 -070041
Daniel Sandler27e1a792010-07-27 14:46:34 -040042static char screenshot_path[PATH_MAX] = "";
43
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044/* dumps the current system state to stdout */
Dan Egnor52952b12010-01-13 12:27:50 -080045static void dumpstate() {
46 time_t now = time(NULL);
47 char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
48 char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];
49 char network[PROPERTY_VALUE_MAX], date[80];
John Michelau790d2e42011-07-05 15:20:03 -050050 char build_type[PROPERTY_VALUE_MAX];
Dan Egnor52952b12010-01-13 12:27:50 -080051
52 property_get("ro.build.display.id", build, "(unknown)");
53 property_get("ro.build.fingerprint", fingerprint, "(unknown)");
John Michelau790d2e42011-07-05 15:20:03 -050054 property_get("ro.build.type", build_type, "(unknown)");
Dan Egnor52952b12010-01-13 12:27:50 -080055 property_get("ro.baseband", radio, "(unknown)");
56 property_get("ro.bootloader", bootloader, "(unknown)");
57 property_get("gsm.operator.alpha", network, "(unknown)");
58 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));
59
60 printf("========================================================\n");
61 printf("== dumpstate: %s\n", date);
62 printf("========================================================\n");
63
64 printf("\n");
65 printf("Build: %s\n", build);
Jeff Brownad5b28a2011-11-11 14:56:27 -080066 printf("Build fingerprint: '%s'\n", fingerprint); /* format is important for other tools */
Dan Egnor52952b12010-01-13 12:27:50 -080067 printf("Bootloader: %s\n", bootloader);
68 printf("Radio: %s\n", radio);
69 printf("Network: %s\n", network);
70
71 printf("Kernel: ");
72 dump_file(NULL, "/proc/version");
73 printf("Command line: %s\n", strtok(cmdline_buf, "\n"));
74 printf("\n");
75
Colin Cross5965ba32011-09-20 15:49:14 -070076 run_command("UPTIME", 10, "uptime", NULL);
Dan Egnor52952b12010-01-13 12:27:50 -080077 dump_file("MEMORY INFO", "/proc/meminfo");
78 run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-t", NULL);
79 run_command("PROCRANK", 20, "procrank", NULL);
80 dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat");
81 dump_file("VMALLOC INFO", "/proc/vmallocinfo");
82 dump_file("SLAB INFO", "/proc/slabinfo");
83 dump_file("ZONEINFO", "/proc/zoneinfo");
Arve Hjønnevåg351e74de12011-08-15 19:43:35 -070084 dump_file("PAGETYPEINFO", "/proc/pagetypeinfo");
JP Abgrall2eb8e362011-08-24 11:24:33 -070085 dump_file("BUDDYINFO", "/proc/buddyinfo");
Dan Egnor52952b12010-01-13 12:27:50 -080086
Daniel Sandler27e1a792010-07-27 14:46:34 -040087 if (screenshot_path[0]) {
88 LOGI("taking screenshot\n");
89 run_command(NULL, 5, "su", "root", "screenshot", screenshot_path, NULL);
90 LOGI("wrote screenshot: %s\n", screenshot_path);
91 }
92
Wink Saville2f791fd2010-10-07 13:38:09 -070093 run_command("SYSTEM LOG", 20, "logcat", "-v", "threadtime", "-d", "*:v", NULL);
Dan Egnor52952b12010-01-13 12:27:50 -080094
95 /* show the traces we collected in main(), if that was done */
96 if (dump_traces_path != NULL) {
97 dump_file("VM TRACES JUST NOW", dump_traces_path);
98 }
99
100 /* only show ANR traces if they're less than 15 minutes old */
101 struct stat st;
102 char anr_traces_path[PATH_MAX];
103 property_get("dalvik.vm.stack-trace-file", anr_traces_path, "");
Dan Egnorefd13932010-03-08 13:04:13 -0800104 if (!anr_traces_path[0]) {
105 printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n");
106 } else if (stat(anr_traces_path, &st)) {
107 printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno));
108 } else {
Dan Egnor52952b12010-01-13 12:27:50 -0800109 dump_file("VM TRACES AT LAST ANR", anr_traces_path);
110 }
111
112 // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");
Wink Saville2f791fd2010-10-07 13:38:09 -0700113 run_command("EVENT LOG", 20, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL);
114 run_command("RADIO LOG", 20, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL);
Dan Egnor52952b12010-01-13 12:27:50 -0800115
Dmitry Shmidt2c3197b2010-11-03 16:59:47 -0700116 run_command("NETWORK INTERFACES", 10, "su", "root", "netcfg", NULL);
JP Abgrall20e93c02011-09-19 22:29:18 -0700117 dump_file("NETWORK DEV INFO", "/proc/net/dev");
118 dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");
119 dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");
120 run_command("QTAGUID STATS INFO", 10, "su", "root", "cat", "/proc/net/xt_qtaguid/stats", NULL);
121
Dan Egnor52952b12010-01-13 12:27:50 -0800122 dump_file("NETWORK ROUTES", "/proc/net/route");
Robert Greenwalt5f2ff422011-04-28 17:10:23 -0700123 dump_file("NETWORK ROUTES IPV6", "/proc/net/ipv6_route");
Dmitry Shmidt84b72ec2010-02-23 15:21:11 -0800124 dump_file("ARP CACHE", "/proc/net/arp");
JP Abgrall2eb8e362011-08-24 11:24:33 -0700125 run_command("IPTABLES", 10, "su", "root", "iptables", "-L", "-nvx", NULL);
126 run_command("IP6TABLES", 10, "su", "root", "ip6tables", "-L", "-nvx", NULL);
John Michelauac745512011-07-25 20:42:50 -0500127 run_command("IPTABLE NAT", 10, "su", "root", "iptables", "-t", "nat", "-L", "-n", NULL);
JP Abgrall2eb8e362011-08-24 11:24:33 -0700128 run_command("IPT6ABLE NAT", 10, "su", "root", "ip6tables", "-t", "nat", "-L", "-n", NULL);
Dan Egnor52952b12010-01-13 12:27:50 -0800129
Dmitry Shmidt631e0f12010-05-26 10:57:11 -0700130 run_command("WIFI NETWORKS", 20,
131 "su", "root", "wpa_cli", "list_networks", NULL);
132
Dmitry Shmidt9abfeb42011-03-28 13:45:21 -0700133 property_get("dhcp.wlan0.gateway", network, "");
134 if (network[0])
135 run_command("PING GATEWAY", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);
136 property_get("dhcp.wlan0.dns1", network, "");
137 if (network[0])
138 run_command("PING DNS1", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);
139 property_get("dhcp.wlan0.dns2", network, "");
140 if (network[0])
141 run_command("PING DNS2", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);
Dmitry Shmidt64bf3d52009-12-16 16:05:08 -0800142#ifdef FWDUMP_bcm4329
Dmitry Shmidt5500c4f2010-09-01 16:18:14 -0700143 run_command("DUMP WIFI STATUS", 20,
Dmitry Shmidt285a8f52011-02-14 11:08:01 -0800144 "su", "root", "dhdutil", "-i", "wlan0", "dump", NULL);
Dmitry Shmidt2b799192010-11-04 14:39:24 -0700145 run_command("DUMP WIFI INTERNAL COUNTERS", 20,
146 "su", "root", "wlutil", "counters", NULL);
Dmitry Shmidt64bf3d52009-12-16 16:05:08 -0800147#endif
San Mehat30b9f572009-09-01 13:27:20 -0700148
JP Abgrallcb4d1a92011-05-17 21:35:54 -0700149#ifdef BROKEN_VRIL_IS_FIXED_B_4442803
150 char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};
John Michelau71bbe7a2010-09-22 16:49:19 -0500151 property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30");
John Michelau790d2e42011-07-05 15:20:03 -0500152 if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) {
153 if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) {
154 // su does not exist on user builds, so try running without it.
155 // This way any implementations of vril-dump that do not require
156 // root can run on user builds.
157 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
158 "vril-dump", NULL);
159 } else {
160 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
161 "su", "root", "vril-dump", NULL);
162 }
John Michelau71bbe7a2010-09-22 16:49:19 -0500163 }
JP Abgrallcb4d1a92011-05-17 21:35:54 -0700164#endif
John Michelau71bbe7a2010-09-22 16:49:19 -0500165
Dan Egnor52952b12010-01-13 12:27:50 -0800166 print_properties();
Iliyan Malchev326e3e22009-11-15 18:28:06 -0800167
Dan Egnor52952b12010-01-13 12:27:50 -0800168 run_command("KERNEL LOG", 20, "dmesg", NULL);
Iliyan Malchev326e3e22009-11-15 18:28:06 -0800169
Dan Egnor52952b12010-01-13 12:27:50 -0800170 dump_file("KERNEL WAKELOCKS", "/proc/wakelocks");
171 dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
Mike Lockwood2ecf3f5e02009-10-04 17:21:05 -0400172
San Mehat9e3f8c62010-03-17 09:50:25 -0700173 run_command("VOLD DUMP", 10, "vdc", "dump", NULL);
San Mehat54aa5772010-03-08 08:58:03 -0800174 run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL);
San Mehat54aa5772010-03-08 08:58:03 -0800175
Dan Egnor52952b12010-01-13 12:27:50 -0800176 run_command("PROCESSES", 10, "ps", "-P", NULL);
177 run_command("PROCESSES AND THREADS", 10, "ps", "-t", "-p", "-P", NULL);
178 run_command("LIBRANK", 10, "librank", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179
Dianne Hackbornf123e492010-09-24 11:16:23 -0700180 dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log");
181 dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log");
182 dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions");
183 dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats");
184 dump_file("BINDER STATE", "/sys/kernel/debug/binder/state");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185
JP Abgrall8935bca2011-01-21 22:32:00 -0800186 run_command("FILESYSTEMS & FREE SPACE", 10, "su", "root", "df", NULL);
Dan Egnor52952b12010-01-13 12:27:50 -0800187
188 dump_file("PACKAGE SETTINGS", "/data/system/packages.xml");
189 dump_file("PACKAGE UID ERRORS", "/data/system/uiderrors.txt");
190
191 dump_file("LAST KMSG", "/proc/last_kmsg");
192 run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);
193 dump_file("LAST PANIC CONSOLE", "/data/dontpanic/apanic_console");
194 dump_file("LAST PANIC THREADS", "/data/dontpanic/apanic_threads");
195
San Mehat57fff782010-04-27 10:53:35 -0700196 for_each_pid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");
197
Dan Egnorea116542010-01-26 17:04:26 -0800198 printf("------ BACKLIGHTS ------\n");
Dan Egnor52952b12010-01-13 12:27:50 -0800199 printf("LCD brightness=");
200 dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness");
201 printf("Button brightness=");
202 dump_file(NULL, "/sys/class/leds/button-backlight/brightness");
203 printf("Keyboard brightness=");
204 dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness");
205 printf("ALS mode=");
206 dump_file(NULL, "/sys/class/leds/lcd-backlight/als");
207 printf("LCD driver registers:\n");
208 dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");
209 printf("\n");
210
Jeff Brownc74a0282011-08-11 20:07:39 -0700211 run_command("LIST OF OPEN FILES", 10, "su", "root", "lsof", NULL);
212
Dianne Hackborn51234682011-11-03 19:19:28 -0700213 for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");
214
Colin Cross1e9f56c2011-07-18 16:56:35 -0700215#ifdef BOARD_HAS_DUMPSTATE
216 printf("========================================================\n");
217 printf("== Board\n");
218 printf("========================================================\n");
219
220 dumpstate_board();
221 printf("\n");
222#endif
223
Dan Egnor52952b12010-01-13 12:27:50 -0800224 printf("========================================================\n");
225 printf("== Android Framework Services\n");
226 printf("========================================================\n");
227
228 /* the full dumpsys is starting to take a long time, so we need
229 to increase its timeout. we really need to do the timeouts in
230 dumpsys itself... */
231 run_command("DUMPSYS", 60, "dumpsys", NULL);
Joe Onoratoeb95b082010-10-21 14:54:19 -0400232
233 printf("========================================================\n");
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700234 printf("== Running Application Activities\n");
Joe Onoratoeb95b082010-10-21 14:54:19 -0400235 printf("========================================================\n");
236
Dianne Hackborne17aeb32011-04-07 15:11:57 -0700237 run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL);
238
239 printf("========================================================\n");
240 printf("== Running Application Services\n");
241 printf("========================================================\n");
242
243 run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL);
Joe Onoratoeb95b082010-10-21 14:54:19 -0400244
Colin Cross1e9f56c2011-07-18 16:56:35 -0700245 printf("========================================================\n");
246 printf("== dumpstate: done\n");
247 printf("========================================================\n");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248}
249
Dan Egnor52952b12010-01-13 12:27:50 -0800250static void usage() {
Daniel Sandler27e1a792010-07-27 14:46:34 -0400251 fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s]\n"
Dan Egnor52952b12010-01-13 12:27:50 -0800252 " -o: write to file (instead of stdout)\n"
Daniel Sandler27e1a792010-07-27 14:46:34 -0400253 " -d: append date to filename (requires -o)\n"
254 " -z: gzip output (requires -o)\n"
255 " -p: capture screenshot to filename.png (requires -o)\n"
Dan Egnor52952b12010-01-13 12:27:50 -0800256 " -s: write output to control socket (for init)\n"
Daniel Sandler27e1a792010-07-27 14:46:34 -0400257 " -b: play sound file instead of vibrate, at beginning of job\n"
258 " -e: play sound file instead of vibrate, at end of job\n"
259 );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260}
261
262int main(int argc, char *argv[]) {
Dan Egnor52952b12010-01-13 12:27:50 -0800263 int do_add_date = 0;
264 int do_compress = 0;
265 char* use_outfile = 0;
Paul Easthambfb071d2010-08-06 14:11:55 -0700266 char* begin_sound = 0;
267 char* end_sound = 0;
Dan Egnor52952b12010-01-13 12:27:50 -0800268 int use_socket = 0;
Daniel Sandler27e1a792010-07-27 14:46:34 -0400269 int do_fb = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270
Mike Lockwoodbb6fa172009-10-05 23:23:40 -0400271 LOGI("begin\n");
272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 /* set as high priority, and protect from OOM killer */
274 setpriority(PRIO_PROCESS, 0, -20);
Dan Egnor52952b12010-01-13 12:27:50 -0800275 FILE *oom_adj = fopen("/proc/self/oom_adj", "w");
276 if (oom_adj) {
277 fputs("-17", oom_adj);
278 fclose(oom_adj);
279 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280
Dan Egnor52952b12010-01-13 12:27:50 -0800281 /* very first thing, collect VM traces from Dalvik (needs root) */
282 dump_traces_path = dump_vm_traces();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283
Dan Egnor52952b12010-01-13 12:27:50 -0800284 int c;
Daniel Sandler27e1a792010-07-27 14:46:34 -0400285 while ((c = getopt(argc, argv, "b:de:ho:svzp")) != -1) {
Mike Lockwood8d533732009-09-02 18:01:05 -0400286 switch (c) {
Paul Easthambfb071d2010-08-06 14:11:55 -0700287 case 'b': begin_sound = optarg; break;
Dan Egnor52952b12010-01-13 12:27:50 -0800288 case 'd': do_add_date = 1; break;
Paul Easthambfb071d2010-08-06 14:11:55 -0700289 case 'e': end_sound = optarg; break;
Dan Egnor52952b12010-01-13 12:27:50 -0800290 case 'o': use_outfile = optarg; break;
291 case 's': use_socket = 1; break;
292 case 'v': break; // compatibility no-op
293 case 'z': do_compress = 6; break;
Daniel Sandler27e1a792010-07-27 14:46:34 -0400294 case 'p': do_fb = 1; break;
Dan Egnor52952b12010-01-13 12:27:50 -0800295 case '?': printf("\n");
296 case 'h':
297 usage();
Mike Lockwood8d533732009-09-02 18:01:05 -0400298 exit(1);
299 }
Dan Egnor52952b12010-01-13 12:27:50 -0800300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301
Dan Egnor52952b12010-01-13 12:27:50 -0800302 /* open the vibrator before dropping root */
303 FILE *vibrator = fopen("/sys/class/timed_output/vibrator/enable", "w");
304 if (vibrator) fcntl(fileno(vibrator), F_SETFD, FD_CLOEXEC);
305
306 /* read /proc/cmdline before dropping root */
307 FILE *cmdline = fopen("/proc/cmdline", "r");
308 if (cmdline != NULL) {
309 fgets(cmdline_buf, sizeof(cmdline_buf), cmdline);
310 fclose(cmdline);
311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312
Nick Kralevich77d87aa2010-10-21 09:14:14 -0700313 if (getuid() == 0) {
314 /* switch to non-root user and group */
John Michelau790d2e42011-07-05 15:20:03 -0500315 gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT, AID_INET };
Nick Kralevich77d87aa2010-10-21 09:14:14 -0700316 if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
317 LOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
318 return -1;
319 }
320 if (setgid(AID_SHELL) != 0) {
321 LOGE("Unable to setgid, aborting: %s\n", strerror(errno));
322 return -1;
323 }
324 if (setuid(AID_SHELL) != 0) {
325 LOGE("Unable to setuid, aborting: %s\n", strerror(errno));
326 return -1;
327 }
Nick Kralevich05f03822010-08-31 18:17:31 -0700328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
Dan Egnor52952b12010-01-13 12:27:50 -0800330 char path[PATH_MAX], tmp_path[PATH_MAX];
331 pid_t gzip_pid = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332
Dan Egnor52952b12010-01-13 12:27:50 -0800333 if (use_socket) {
334 redirect_to_socket(stdout, "dumpstate");
335 } else if (use_outfile) {
336 strlcpy(path, use_outfile, sizeof(path));
337 if (do_add_date) {
338 char date[80];
339 time_t now = time(NULL);
340 strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", localtime(&now));
341 strlcat(path, date, sizeof(path));
Mike Lockwood8d533732009-09-02 18:01:05 -0400342 }
Daniel Sandler27e1a792010-07-27 14:46:34 -0400343 if (do_fb) {
344 strlcpy(screenshot_path, path, sizeof(screenshot_path));
345 strlcat(screenshot_path, ".png", sizeof(screenshot_path));
346 }
Dan Egnor52952b12010-01-13 12:27:50 -0800347 strlcat(path, ".txt", sizeof(path));
348 if (do_compress) strlcat(path, ".gz", sizeof(path));
349 strlcpy(tmp_path, path, sizeof(tmp_path));
350 strlcat(tmp_path, ".tmp", sizeof(tmp_path));
351 gzip_pid = redirect_to_file(stdout, tmp_path, do_compress);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 }
353
Paul Easthambfb071d2010-08-06 14:11:55 -0700354 if (begin_sound) {
355 play_sound(begin_sound);
356 } else if (vibrator) {
Dan Egnor52952b12010-01-13 12:27:50 -0800357 fputs("150", vibrator);
358 fflush(vibrator);
359 }
360
361 dumpstate();
362
Paul Easthambfb071d2010-08-06 14:11:55 -0700363 if (end_sound) {
364 play_sound(end_sound);
365 } else if (vibrator) {
Dan Egnor52952b12010-01-13 12:27:50 -0800366 int i;
367 for (i = 0; i < 3; i++) {
368 fputs("75\n", vibrator);
369 fflush(vibrator);
370 usleep((75 + 50) * 1000);
371 }
372 fclose(vibrator);
373 }
374
375 /* wait for gzip to finish, otherwise it might get killed when we exit */
376 if (gzip_pid > 0) {
377 fclose(stdout);
378 waitpid(gzip_pid, NULL, 0);
379 }
380
381 /* rename the (now complete) .tmp file to its final location */
382 if (use_outfile && rename(tmp_path, path)) {
383 fprintf(stderr, "rename(%s, %s): %s\n", tmp_path, path, strerror(errno));
384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385
Mike Lockwoodbb6fa172009-10-05 23:23:40 -0400386 LOGI("done\n");
387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 return 0;
389}