summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2016-04-18 18:40:32 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-04-18 18:40:32 +0000
commitb2ec4ab3ab3fdcfa0c0725599287b714ced54bd2 (patch)
tree7c44e20b1143464260845e761d7ec5ec9fce87ef
parentc3574f7b0141c69fdca25ccafb80ff334462f9a3 (diff)
parentceeb64281d012cfac99827adbcdb5800b2ce0542 (diff)
Merge "Added -v option to bugreportz." into nyc-dev
-rw-r--r--cmds/bugreportz/bugreportz.cpp52
-rw-r--r--cmds/bugreportz/readme.md12
2 files changed, 57 insertions, 7 deletions
diff --git a/cmds/bugreportz/bugreportz.cpp b/cmds/bugreportz/bugreportz.cpp
index b6856bb402..19d2d64310 100644
--- a/cmds/bugreportz/bugreportz.cpp
+++ b/cmds/bugreportz/bugreportz.cpp
@@ -15,6 +15,7 @@
*/
#include <errno.h>
+#include <getopt.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
@@ -23,9 +24,47 @@
#include <cutils/properties.h>
#include <cutils/sockets.h>
-// TODO: code below was copy-and-pasted from bugreport.cpp (except by the timeout value);
-// should be reused instead.
-int main() {
+static constexpr char VERSION[] = "1.0";
+
+static void show_usage() {
+ fprintf(stderr,
+ "usage: bugreportz [-h | -v]\n"
+ " -h: to display this help message\n"
+ " -v: to display the version\n"
+ " or no arguments to generate a zipped bugreport\n");
+}
+
+static void show_version() {
+ fprintf(stderr, "%s\n", VERSION);
+}
+
+int main(int argc, char *argv[]) {
+
+ if (argc > 1) {
+ /* parse arguments */
+ int c;
+ while ((c = getopt(argc, argv, "vh")) != -1) {
+ switch (c) {
+ case 'h':
+ show_usage();
+ return EXIT_SUCCESS;
+ case 'v':
+ show_version();
+ return EXIT_SUCCESS;
+ default:
+ show_usage();
+ return EXIT_FAILURE;
+ }
+ }
+ // passed an argument not starting with -
+ if (optind > 1 || argv[optind] != nullptr) {
+ show_usage();
+ return EXIT_FAILURE;
+ }
+ }
+
+ // TODO: code below was copy-and-pasted from bugreport.cpp (except by the timeout value);
+ // should be reused instead.
// Start the dumpstatez service.
property_set("ctl.start", "dumpstatez");
@@ -42,7 +81,7 @@ int main() {
if (s == -1) {
printf("Failed to connect to dumpstatez service: %s\n", strerror(errno));
- return 1;
+ return EXIT_FAILURE;
}
// Set a timeout so that if nothing is read in 10 minutes, we'll stop
@@ -81,13 +120,12 @@ int main() {
printf(
"Failed to write data to stdout: read %zd, trying to send %zd (%s)\n",
bytes_read, bytes_to_send, strerror(errno));
- return 1;
+ return EXIT_FAILURE;
}
bytes_to_send -= bytes_written;
} while (bytes_written != 0 && bytes_to_send > 0);
}
close(s);
- return 0;
-
+ return EXIT_SUCCESS;
}
diff --git a/cmds/bugreportz/readme.md b/cmds/bugreportz/readme.md
new file mode 100644
index 0000000000..85aafcefe4
--- /dev/null
+++ b/cmds/bugreportz/readme.md
@@ -0,0 +1,12 @@
+# bugreportz protocol
+
+`bugreportz` is used to generate a zippped bugreport whose path is passed back to `adb`, using
+the simple protocol defined below.
+
+
+## Version 1.0
+On version 1.0, `bugreportz` does not generate any output on `stdout` until the bugreport is
+finished, when it then prints one line with the result:
+
+- `OK:<path_to_bugreport_file>` in case of success.
+- `FAIL:<error message>` in case of failure.