Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd21d214 authored by Jean-Baptiste Queru's avatar Jean-Baptiste Queru Committed by Android Git Automerger
Browse files

am 72249325: am 428a6e3f: am 13438a93: Merge "logwrapper: reduce verbosity and fix usage"

* commit '72249325':
  logwrapper: reduce verbosity and fix usage
parents 5ae3f93f 72249325
Loading
Loading
Loading
Loading
+11 −6
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <libgen.h>


#include "private/android_filesystem_config.h"
#include "private/android_filesystem_config.h"
#include "cutils/log.h"
#include "cutils/log.h"
@@ -34,13 +35,13 @@ void fatal(const char *msg) {


void usage() {
void usage() {
    fatal(
    fatal(
        "Usage: logwrapper [-x] BINARY [ARGS ...]\n"
        "Usage: logwrapper [-d] BINARY [ARGS ...]\n"
        "\n"
        "\n"
        "Forks and executes BINARY ARGS, redirecting stdout and stderr to\n"
        "Forks and executes BINARY ARGS, redirecting stdout and stderr to\n"
        "the Android logging system. Tag is set to BINARY, priority is\n"
        "the Android logging system. Tag is set to BINARY, priority is\n"
        "always LOG_INFO.\n"
        "always LOG_INFO.\n"
        "\n"
        "\n"
        "-x: Causes logwrapper to SIGSEGV when BINARY terminates\n"
        "-d: Causes logwrapper to SIGSEGV when BINARY terminates\n"
        "    fault address is set to the status of wait()\n");
        "    fault address is set to the status of wait()\n");
}
}


@@ -51,6 +52,10 @@ void parent(const char *tag, int seg_fault_on_exit, int parent_read) {
    int a = 0;  // start index of unprocessed data
    int a = 0;  // start index of unprocessed data
    int b = 0;  // end index of unprocessed data
    int b = 0;  // end index of unprocessed data
    int sz;
    int sz;

    char *btag = basename(tag);
    if (!btag) btag = (char*) tag;

    while ((sz = read(parent_read, &buffer[b], sizeof(buffer) - 1 - b)) > 0) {
    while ((sz = read(parent_read, &buffer[b], sizeof(buffer) - 1 - b)) > 0) {


        sz += b;
        sz += b;
@@ -60,7 +65,7 @@ void parent(const char *tag, int seg_fault_on_exit, int parent_read) {
                buffer[b] = '\0';
                buffer[b] = '\0';
            } else if (buffer[b] == '\n') {
            } else if (buffer[b] == '\n') {
                buffer[b] = '\0';
                buffer[b] = '\0';
                ALOG(LOG_INFO, tag, "%s", &buffer[a]);
                ALOG(LOG_INFO, btag, "%s", &buffer[a]);
                a = b + 1;
                a = b + 1;
            }
            }
        }
        }
@@ -68,7 +73,7 @@ void parent(const char *tag, int seg_fault_on_exit, int parent_read) {
        if (a == 0 && b == sizeof(buffer) - 1) {
        if (a == 0 && b == sizeof(buffer) - 1) {
            // buffer is full, flush
            // buffer is full, flush
            buffer[b] = '\0';
            buffer[b] = '\0';
            ALOG(LOG_INFO, tag, "%s", &buffer[a]);
            ALOG(LOG_INFO, btag, "%s", &buffer[a]);
            b = 0;
            b = 0;
        } else if (a != b) {
        } else if (a != b) {
            // Keep left-overs
            // Keep left-overs
@@ -84,11 +89,11 @@ void parent(const char *tag, int seg_fault_on_exit, int parent_read) {
    // Flush remaining data
    // Flush remaining data
    if (a != b) {
    if (a != b) {
        buffer[b] = '\0';
        buffer[b] = '\0';
        ALOG(LOG_INFO, tag, "%s", &buffer[a]);
        ALOG(LOG_INFO, btag, "%s", &buffer[a]);
    }
    }
    status = 0xAAAA;
    status = 0xAAAA;
    if (wait(&status) != -1) {  // Wait for child
    if (wait(&status) != -1) {  // Wait for child
        if (WIFEXITED(status))
        if (WIFEXITED(status) && WEXITSTATUS(status))
            ALOG(LOG_INFO, "logwrapper", "%s terminated by exit(%d)", tag,
            ALOG(LOG_INFO, "logwrapper", "%s terminated by exit(%d)", tag,
                    WEXITSTATUS(status));
                    WEXITSTATUS(status));
        else if (WIFSIGNALED(status))
        else if (WIFSIGNALED(status))