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

Commit 78886a6d authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Android Git Automerger
Browse files

am ce2a0ecf: am ffd72150: am 3e73a99f: Merge "logd: auditd: add logd.auditd.dmesg property"

* commit 'ce2a0ecf':
  logd: auditd: add logd.auditd.dmesg property
parents 7ddea01b ce2a0ecf
Loading
Loading
Loading
Loading
+18 −4
Original line number Original line Diff line number Diff line
@@ -19,15 +19,18 @@
#include <stdarg.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/klog.h>
#include <sys/klog.h>
#include <sys/uio.h>


#include "libaudit.h"
#include "libaudit.h"
#include "LogAudit.h"
#include "LogAudit.h"


LogAudit::LogAudit(LogBuffer *buf, LogReader *reader)
LogAudit::LogAudit(LogBuffer *buf, LogReader *reader, int fdDmsg)
        : SocketListener(getLogSocket(), false)
        : SocketListener(getLogSocket(), false)
        , logbuf(buf)
        , logbuf(buf)
        , reader(reader) {
        , reader(reader)
    logDmsg();
        , fdDmesg(-1) {
    logDmesg();
    fdDmesg = fdDmsg;
}
}


bool LogAudit::onDataAvailable(SocketClient *cli) {
bool LogAudit::onDataAvailable(SocketClient *cli) {
@@ -62,6 +65,17 @@ int LogAudit::logPrint(const char *fmt, ...) {
        return rc;
        return rc;
    }
    }


    if (fdDmesg >= 0) {
        struct iovec iov[2];

        iov[0].iov_base = str;
        iov[0].iov_len = strlen(str);
        iov[1].iov_base = const_cast<char *>("\n");
        iov[1].iov_len = 1;

        writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0]));
    }

    pid_t pid = getpid();
    pid_t pid = getpid();
    pid_t tid = gettid();
    pid_t tid = gettid();
    uid_t uid = getuid();
    uid_t uid = getuid();
@@ -141,7 +155,7 @@ int LogAudit::logPrint(const char *fmt, ...) {
    return rc;
    return rc;
}
}


void LogAudit::logDmsg() {
void LogAudit::logDmesg() {
    int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
    int len = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
    if (len <= 0) {
    if (len <= 0) {
        return;
        return;
+3 −2
Original line number Original line Diff line number Diff line
@@ -23,16 +23,17 @@
class LogAudit : public SocketListener {
class LogAudit : public SocketListener {
    LogBuffer *logbuf;
    LogBuffer *logbuf;
    LogReader *reader;
    LogReader *reader;
    int fdDmesg;


public:
public:
    LogAudit(LogBuffer *buf, LogReader *reader);
    LogAudit(LogBuffer *buf, LogReader *reader, int fdDmesg);


protected:
protected:
    virtual bool onDataAvailable(SocketClient *cli);
    virtual bool onDataAvailable(SocketClient *cli);


private:
private:
    static int getLogSocket();
    static int getLogSocket();
    void logDmsg();
    void logDmesg();
    int logPrint(const char *fmt, ...)
    int logPrint(const char *fmt, ...)
        __attribute__ ((__format__ (__printf__, 2, 3)));
        __attribute__ ((__format__ (__printf__, 2, 3)));
};
};
+9 −1
Original line number Original line Diff line number Diff line
@@ -84,6 +84,13 @@ static int drop_privs() {
// space logger.  Additional transitory per-client threads are created
// space logger.  Additional transitory per-client threads are created
// for each reader once they register.
// for each reader once they register.
int main() {
int main() {
    int fdDmesg = -1;
    char dmesg[PROPERTY_VALUE_MAX];
    property_get("logd.auditd.dmesg", dmesg, "1");
    if (atol(dmesg)) {
        fdDmesg = open("/dev/kmsg", O_WRONLY);
    }

    if (drop_privs() != 0) {
    if (drop_privs() != 0) {
        return -1;
        return -1;
    }
    }
@@ -136,9 +143,10 @@ int main() {
    // and LogReader is notified to send updates to connected clients.
    // and LogReader is notified to send updates to connected clients.


    // failure is an option ... messages are in dmesg (required by standard)
    // failure is an option ... messages are in dmesg (required by standard)
    LogAudit *al = new LogAudit(logBuf, reader);
    LogAudit *al = new LogAudit(logBuf, reader, fdDmesg);
    if (al->startListener()) {
    if (al->startListener()) {
        delete al;
        delete al;
        close(fdDmesg);
    }
    }


    pause();
    pause();