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

Commit d162f14d authored by Tom Cherry's avatar Tom Cherry
Browse files

logcat: remove the rest of liblogcat

There were big changes made to support liblogcat, which has long since
been removed.  This change removes the rest of those changes.

It moves the rest of the global state into a class, particularly for
the logcatd case.  The original code re-uses the same context, but
that doesn't seem right or safe.

Test: logcat works, logcat-unit-tests
Test: logpersist works, including last log cat and log rotation
Change-Id: Iee6a2a0319265e87be0bc8fec2b11e8fd2b65ed4
parent c8ef0134
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ cc_defaults {
        "-Wall",
        "-Wextra",
        "-Werror",
        "-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION=1",
    ],
    shared_libs: [
        "libbase",
+238 −673

File changed.

Preview size limit exceeded, changes collapsed.

+1 −42
Original line number Diff line number Diff line
@@ -16,45 +16,4 @@

#pragma once

#include <stdio.h>

/*
 * The opaque context
 */
typedef struct android_logcat_context_internal* android_logcat_context;

/* Creates a context associated with this logcat instance
 *
 * Returns a pointer to the context, or a NULL on error.
 */
android_logcat_context create_android_logcat();

/* Collects and outputs the logcat data to output and error file descriptors
 *
 * Will block, performed in-thread and in-process
 *
 * The output file descriptor variable, if greater than or equal to 0, is
 * where the output (ie: stdout) will be sent. The file descriptor is closed
 * on android_logcat_destroy which terminates the instance, or when an -f flag
 * (output redirect to a file) is present in the command.  The error file
 * descriptor variable, if greater than or equal to 0, is where the error
 * stream (ie: stderr) will be sent, also closed on android_logcat_destroy.
 * The error file descriptor can be set to equal to the output file descriptor,
 * which will mix output and error stream content, and will defer closure of
 * the file descriptor on -f flag redirection.  Negative values for the file
 * descriptors will use stdout and stderr FILE references respectively
 * internally, and will not close the references as noted above.
 *
 * Return value is 0 for success, non-zero for errors.
 */
int android_logcat_run_command(android_logcat_context ctx, int output, int error, int argc,
                               char* const* argv, char* const* envp);

/* Finished with context
 *
 * Kill the command thread ASAP (if any), and free up all associated resources.
 *
 * Return value is the result of the android_logcat_run_command, or
 * non-zero for any errors.
 */
int android_logcat_destroy(android_logcat_context* ctx);
int RunLogcat(int argc, char** argv);
 No newline at end of file
+2 −7
Original line number Diff line number Diff line
@@ -19,12 +19,7 @@

#include "logcat.h"

int main(int argc, char** argv, char** envp) {
    android_logcat_context ctx = create_android_logcat();
    if (!ctx) return -1;
int main(int argc, char** argv) {
    signal(SIGPIPE, exit);
    int retval = android_logcat_run_command(ctx, -1, -1, argc, argv, envp);
    int ret = android_logcat_destroy(&ctx);
    if (!ret) ret = retval;
    return ret;
    return RunLogcat(argc, argv);
}
+3 −10
Original line number Diff line number Diff line
@@ -23,10 +23,7 @@

#include "logcat.h"

int main(int argc, char** argv, char** envp) {
    android_logcat_context ctx = create_android_logcat();
    if (!ctx) return -1;

int main(int argc, char** argv) {
    signal(SIGPIPE, exit);

    // Save and detect presence of -L or --last flag
@@ -46,8 +43,7 @@ int main(int argc, char** argv, char** envp) {
    int ret = 0;
    if (last) {
        // Run logcat command with -L flag
        ret = android_logcat_run_command(ctx, -1, -1, argv_hold.size() - 1,
                                         (char* const*)&argv_hold[0], envp);
        ret = RunLogcat(argv_hold.size() - 1, (char**)&argv_hold[0]);
        // Remove -L and --last flags from argument list
        for (std::vector<const char*>::iterator it = argv_hold.begin();
             it != argv_hold.end();) {
@@ -62,10 +58,7 @@ int main(int argc, char** argv, char** envp) {
    }

    // Run logcat command without -L flag
    int retval = android_logcat_run_command(ctx, -1, -1, argv_hold.size() - 1,
                                            (char* const*)&argv_hold[0], envp);
    if (!ret) ret = retval;
    retval = android_logcat_destroy(&ctx);
    int retval = RunLogcat(argv_hold.size() - 1, (char**)&argv_hold[0]);
    if (!ret) ret = retval;
    return ret;
}