Merge "logd: libsysutils: logd startup outside init environment"
This commit is contained in:
commit
0516aded0e
8 changed files with 78 additions and 3 deletions
|
|
@ -36,6 +36,7 @@ private:
|
||||||
public:
|
public:
|
||||||
FrameworkListener(const char *socketName);
|
FrameworkListener(const char *socketName);
|
||||||
FrameworkListener(const char *socketName, bool withSeq);
|
FrameworkListener(const char *socketName, bool withSeq);
|
||||||
|
FrameworkListener(int sock);
|
||||||
virtual ~FrameworkListener() {}
|
virtual ~FrameworkListener() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,11 @@ FrameworkListener::FrameworkListener(const char *socketName) :
|
||||||
init(socketName, false);
|
init(socketName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FrameworkListener::FrameworkListener(int sock) :
|
||||||
|
SocketListener(sock, true) {
|
||||||
|
init(NULL, false);
|
||||||
|
}
|
||||||
|
|
||||||
void FrameworkListener::init(const char *socketName UNUSED, bool withSeq) {
|
void FrameworkListener::init(const char *socketName UNUSED, bool withSeq) {
|
||||||
mCommands = new FrameworkCommandCollection();
|
mCommands = new FrameworkCommandCollection();
|
||||||
errorRate = 0;
|
errorRate = 0;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <cutils/sockets.h>
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
#include <sysutils/SocketClient.h>
|
#include <sysutils/SocketClient.h>
|
||||||
|
|
||||||
|
|
@ -32,7 +33,7 @@
|
||||||
|
|
||||||
CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/,
|
CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/,
|
||||||
LogListener * /*swl*/)
|
LogListener * /*swl*/)
|
||||||
: FrameworkListener("logd")
|
: FrameworkListener(getLogSocket())
|
||||||
, mBuf(*buf) {
|
, mBuf(*buf) {
|
||||||
// registerCmd(new ShutdownCmd(buf, writer, swl));
|
// registerCmd(new ShutdownCmd(buf, writer, swl));
|
||||||
registerCmd(new ClearCmd(buf));
|
registerCmd(new ClearCmd(buf));
|
||||||
|
|
@ -283,3 +284,16 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CommandListener::getLogSocket() {
|
||||||
|
static const char socketName[] = "logd";
|
||||||
|
int sock = android_get_control_socket(socketName);
|
||||||
|
|
||||||
|
if (sock < 0) {
|
||||||
|
sock = socket_local_server(socketName,
|
||||||
|
ANDROID_SOCKET_NAMESPACE_RESERVED,
|
||||||
|
SOCK_STREAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ public:
|
||||||
virtual ~CommandListener() {}
|
virtual ~CommandListener() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static int getLogSocket();
|
||||||
|
|
||||||
class ShutdownCmd : public LogCommand {
|
class ShutdownCmd : public LogCommand {
|
||||||
LogBuffer &mBuf;
|
LogBuffer &mBuf;
|
||||||
LogReader &mReader;
|
LogReader &mReader;
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,15 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LogListener::getLogSocket() {
|
int LogListener::getLogSocket() {
|
||||||
int sock = android_get_control_socket("logdw");
|
static const char socketName[] = "logdw";
|
||||||
|
int sock = android_get_control_socket(socketName);
|
||||||
|
|
||||||
|
if (sock < 0) {
|
||||||
|
sock = socket_local_server(socketName,
|
||||||
|
ANDROID_SOCKET_NAMESPACE_RESERVED,
|
||||||
|
SOCK_DGRAM);
|
||||||
|
}
|
||||||
|
|
||||||
int on = 1;
|
int on = 1;
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) {
|
if (setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,14 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
|
|
||||||
#include "LogReader.h"
|
#include "LogReader.h"
|
||||||
#include "FlushCommand.h"
|
#include "FlushCommand.h"
|
||||||
|
|
||||||
LogReader::LogReader(LogBuffer *logbuf)
|
LogReader::LogReader(LogBuffer *logbuf)
|
||||||
: SocketListener("logdr", true)
|
: SocketListener(getLogSocket(), true)
|
||||||
, mLogbuf(*logbuf)
|
, mLogbuf(*logbuf)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
@ -167,3 +168,16 @@ void LogReader::doSocketDelete(SocketClient *cli) {
|
||||||
}
|
}
|
||||||
LogTimeEntry::unlock();
|
LogTimeEntry::unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LogReader::getLogSocket() {
|
||||||
|
static const char socketName[] = "logdr";
|
||||||
|
int sock = android_get_control_socket(socketName);
|
||||||
|
|
||||||
|
if (sock < 0) {
|
||||||
|
sock = socket_local_server(socketName,
|
||||||
|
ANDROID_SOCKET_NAMESPACE_RESERVED,
|
||||||
|
SOCK_SEQPACKET);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ protected:
|
||||||
virtual bool onDataAvailable(SocketClient *cli);
|
virtual bool onDataAvailable(SocketClient *cli);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static int getLogSocket();
|
||||||
|
|
||||||
void doSocketDelete(SocketClient *cli);
|
void doSocketDelete(SocketClient *cli);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,35 @@
|
||||||
#include "LogListener.h"
|
#include "LogListener.h"
|
||||||
#include "LogAudit.h"
|
#include "LogAudit.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// The service is designed to be run by init, it does not respond well
|
||||||
|
// to starting up manually. When starting up manually the sockets will
|
||||||
|
// fail to open typically for one of the following reasons:
|
||||||
|
// EADDRINUSE if logger is running.
|
||||||
|
// EACCESS if started without precautions (below)
|
||||||
|
//
|
||||||
|
// Here is a cookbook procedure for starting up logd manually assuming
|
||||||
|
// init is out of the way, pedantically all permissions and selinux
|
||||||
|
// security is put back in place:
|
||||||
|
//
|
||||||
|
// setenforce 0
|
||||||
|
// rm /dev/socket/logd*
|
||||||
|
// chmod 777 /dev/socket
|
||||||
|
// # here is where you would attach the debugger or valgrind for example
|
||||||
|
// runcon u:r:logd:s0 /system/bin/logd </dev/null >/dev/null 2>&1 &
|
||||||
|
// sleep 1
|
||||||
|
// chmod 755 /dev/socket
|
||||||
|
// chown logd.logd /dev/socket/logd*
|
||||||
|
// restorecon /dev/socket/logd*
|
||||||
|
// setenforce 1
|
||||||
|
//
|
||||||
|
// If minimalism prevails, typical for debugging and security is not a concern:
|
||||||
|
//
|
||||||
|
// setenforce 0
|
||||||
|
// chmod 777 /dev/socket
|
||||||
|
// logd
|
||||||
|
//
|
||||||
|
|
||||||
static int drop_privs() {
|
static int drop_privs() {
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
memset(¶m, 0, sizeof(param));
|
memset(¶m, 0, sizeof(param));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue