am 0516aded: Merge "logd: libsysutils: logd startup outside init environment"

* commit '0516aded0e3006272ec390fd418d311e06b1d328':
  logd: libsysutils: logd startup outside init environment
This commit is contained in:
Mark Salyzyn 2014-04-17 23:16:38 +00:00 committed by Android Git Automerger
commit fe545b9cb7
8 changed files with 78 additions and 3 deletions

View File

@ -36,6 +36,7 @@ private:
public:
FrameworkListener(const char *socketName);
FrameworkListener(const char *socketName, bool withSeq);
FrameworkListener(int sock);
virtual ~FrameworkListener() {}
protected:

View File

@ -39,6 +39,11 @@ FrameworkListener::FrameworkListener(const char *socketName) :
init(socketName, false);
}
FrameworkListener::FrameworkListener(int sock) :
SocketListener(sock, true) {
init(NULL, false);
}
void FrameworkListener::init(const char *socketName UNUSED, bool withSeq) {
mCommands = new FrameworkCommandCollection();
errorRate = 0;

View File

@ -24,6 +24,7 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <cutils/sockets.h>
#include <private/android_filesystem_config.h>
#include <sysutils/SocketClient.h>
@ -32,7 +33,7 @@
CommandListener::CommandListener(LogBuffer *buf, LogReader * /*reader*/,
LogListener * /*swl*/)
: FrameworkListener("logd")
: FrameworkListener(getLogSocket())
, mBuf(*buf) {
// registerCmd(new ShutdownCmd(buf, writer, swl));
registerCmd(new ClearCmd(buf));
@ -283,3 +284,16 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli,
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;
}

View File

@ -31,6 +31,8 @@ public:
virtual ~CommandListener() {}
private:
static int getLogSocket();
class ShutdownCmd : public LogCommand {
LogBuffer &mBuf;
LogReader &mReader;

View File

@ -107,7 +107,15 @@ bool LogListener::onDataAvailable(SocketClient *cli) {
}
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;
if (setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0) {
return -1;

View File

@ -17,13 +17,14 @@
#include <ctype.h>
#include <poll.h>
#include <sys/socket.h>
#include <cutils/sockets.h>
#include "LogReader.h"
#include "FlushCommand.h"
LogReader::LogReader(LogBuffer *logbuf)
: SocketListener("logdr", true)
: SocketListener(getLogSocket(), true)
, mLogbuf(*logbuf)
{ }
@ -167,3 +168,16 @@ void LogReader::doSocketDelete(SocketClient *cli) {
}
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;
}

View File

@ -34,6 +34,8 @@ protected:
virtual bool onDataAvailable(SocketClient *cli);
private:
static int getLogSocket();
void doSocketDelete(SocketClient *cli);
};

View File

@ -36,6 +36,35 @@
#include "LogListener.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() {
struct sched_param param;
memset(&param, 0, sizeof(param));