blob: 0845504acf2bdb437fa7d7eb8378434f84671755 [file] [log] [blame]
Mark Salyzyn12bac902014-02-26 09:50:16 -08001/*
Mark Salyzyne6477492014-02-21 13:54:07 -08002 * Copyright (C) 2012-2014 The Android Open Source Project
Mark Salyzyn12bac902014-02-26 09:50:16 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdlib.h>
Mark Salyzyne6477492014-02-21 13:54:07 -080018
Mark Salyzyn1d21d542016-02-23 08:55:43 -080019#include <private/android_filesystem_config.h>
20
Mark Salyzyn12bac902014-02-26 09:50:16 -080021#include "FlushCommand.h"
Mark Salyzyn1d21d542016-02-23 08:55:43 -080022#include "LogBuffer.h"
Mark Salyzyn12bac902014-02-26 09:50:16 -080023#include "LogBufferElement.h"
Mark Salyzyne6477492014-02-21 13:54:07 -080024#include "LogCommand.h"
Mark Salyzyn12bac902014-02-26 09:50:16 -080025#include "LogReader.h"
Mark Salyzyne6477492014-02-21 13:54:07 -080026#include "LogTimes.h"
Mark Salyzync9690862015-12-04 10:59:45 -080027#include "LogUtils.h"
Mark Salyzyn12bac902014-02-26 09:50:16 -080028
Mark Salyzyn12bac902014-02-26 09:50:16 -080029// runSocketCommand is called once for every open client on the
30// log reader socket. Here we manage and associated the reader
31// client tracking and log region locks LastLogTimes list of
32// LogTimeEntrys, and spawn a transitory per-client thread to
33// work at filing data to the socket.
34//
Mark Salyzynd2712b12017-04-18 14:09:45 -070035// global LogTimeEntry::wrlock() is used to protect access,
Mark Salyzyn12bac902014-02-26 09:50:16 -080036// reference counts are used to ensure that individual
37// LogTimeEntry lifetime is managed when not protected.
Mark Salyzyn65059532017-03-10 14:31:54 -080038void FlushCommand::runSocketCommand(SocketClient* client) {
Yi Kong36feb152018-07-13 17:39:22 -070039 LogTimeEntry* entry = nullptr;
Mark Salyzyn65059532017-03-10 14:31:54 -080040 LastLogTimes& times = mReader.logbuf().mTimes;
Mark Salyzyn12bac902014-02-26 09:50:16 -080041
Mark Salyzynd2712b12017-04-18 14:09:45 -070042 LogTimeEntry::wrlock();
Mark Salyzyn12bac902014-02-26 09:50:16 -080043 LastLogTimes::iterator it = times.begin();
Mark Salyzyn65059532017-03-10 14:31:54 -080044 while (it != times.end()) {
Tom Cherry06e478b2018-10-08 17:33:50 -070045 entry = it->get();
Mark Salyzyn12bac902014-02-26 09:50:16 -080046 if (entry->mClient == client) {
Hao Wang10d19f62017-12-04 14:10:40 +080047 if (!entry->isWatchingMultiple(mLogMask)) {
48 LogTimeEntry::unlock();
49 return;
50 }
Mark Salyzync959c642015-11-30 11:35:56 -080051 if (entry->mTimeout.tv_sec || entry->mTimeout.tv_nsec) {
Tom Cherry26319752019-08-21 14:25:06 -070052 LogTimeEntry::unlock();
53 return;
Mark Salyzync959c642015-11-30 11:35:56 -080054 }
Mark Salyzyn12bac902014-02-26 09:50:16 -080055 entry->triggerReader_Locked();
Tom Cherry06e478b2018-10-08 17:33:50 -070056 LogTimeEntry::unlock();
57 return;
Mark Salyzyn12bac902014-02-26 09:50:16 -080058 }
59 it++;
60 }
61
Mark Salyzyn12bac902014-02-26 09:50:16 -080062 LogTimeEntry::unlock();
63}
64
Mark Salyzyn65059532017-03-10 14:31:54 -080065bool FlushCommand::hasReadLogs(SocketClient* client) {
Mark Salyzyne6477492014-02-21 13:54:07 -080066 return clientHasLogCredentials(client);
Mark Salyzyn12bac902014-02-26 09:50:16 -080067}
Mark Salyzynb10f7372016-01-26 14:32:35 -080068
Mark Salyzyn65059532017-03-10 14:31:54 -080069static bool clientHasSecurityCredentials(SocketClient* client) {
Mark Salyzynb10f7372016-01-26 14:32:35 -080070 return (client->getUid() == AID_SYSTEM) || (client->getGid() == AID_SYSTEM);
71}
72
Mark Salyzyn65059532017-03-10 14:31:54 -080073bool FlushCommand::hasSecurityLogs(SocketClient* client) {
Mark Salyzynb10f7372016-01-26 14:32:35 -080074 return clientHasSecurityCredentials(client);
75}