Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 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 | |
Jerry Zhang | cadf4ed | 2018-05-02 16:56:00 -0700 | [diff] [blame] | 17 | #ifndef _LOGGING_H |
| 18 | #define _LOGGING_H |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 19 | |
Tao Bao | 245c522 | 2017-10-18 11:06:36 -0700 | [diff] [blame] | 20 | #include <stddef.h> |
xunchang | 2239b9e | 2019-04-15 15:24:24 -0700 | [diff] [blame] | 21 | #include <sys/stat.h> |
Tao Bao | 245c522 | 2017-10-18 11:06:36 -0700 | [diff] [blame] | 22 | #include <sys/types.h> |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 23 | |
Jerry Zhang | cadf4ed | 2018-05-02 16:56:00 -0700 | [diff] [blame] | 24 | #include <string> |
xunchang | 2239b9e | 2019-04-15 15:24:24 -0700 | [diff] [blame] | 25 | #include <vector> |
Jerry Zhang | cadf4ed | 2018-05-02 16:56:00 -0700 | [diff] [blame] | 26 | |
Tao Bao | 245c522 | 2017-10-18 11:06:36 -0700 | [diff] [blame] | 27 | #include <log/log_id.h> |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 28 | |
Tao Bao | 245c522 | 2017-10-18 11:06:36 -0700 | [diff] [blame] | 29 | static constexpr int KEEP_LOG_COUNT = 10; |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 30 | |
xunchang | 316e971 | 2019-04-12 16:22:15 -0700 | [diff] [blame] | 31 | struct selabel_handle; |
| 32 | |
xunchang | 2239b9e | 2019-04-15 15:24:24 -0700 | [diff] [blame] | 33 | struct saved_log_file { |
| 34 | std::string name; |
| 35 | struct stat sb; |
| 36 | std::string data; |
| 37 | }; |
| 38 | |
| 39 | void SetLoggingSehandle(selabel_handle* handle); |
| 40 | |
Tao Bao | 245c522 | 2017-10-18 11:06:36 -0700 | [diff] [blame] | 41 | ssize_t logbasename(log_id_t id, char prio, const char* filename, const char* buf, size_t len, |
| 42 | void* arg); |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 43 | |
Tao Bao | 245c522 | 2017-10-18 11:06:36 -0700 | [diff] [blame] | 44 | ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len, |
| 45 | void* arg); |
Tianjie Xu | e113e4d | 2016-10-21 17:46:13 -0700 | [diff] [blame] | 46 | |
| 47 | // Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max. |
| 48 | // Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max. |
| 49 | // Overwrite any existing last_log.$max and last_kmsg.$max. |
| 50 | void rotate_logs(const char* last_log_file, const char* last_kmsg_file); |
| 51 | |
Jerry Zhang | cadf4ed | 2018-05-02 16:56:00 -0700 | [diff] [blame] | 52 | // In turn fflush(3)'s, fsync(3)'s and fclose(3)'s the given stream. |
| 53 | void check_and_fclose(FILE* fp, const std::string& name); |
| 54 | |
| 55 | void copy_log_file_to_pmsg(const std::string& source, const std::string& destination); |
Tianjie Xu | 164c60a | 2019-05-15 13:59:39 -0700 | [diff] [blame] | 56 | void copy_logs(bool save_current_log); |
Jerry Zhang | cadf4ed | 2018-05-02 16:56:00 -0700 | [diff] [blame] | 57 | void reset_tmplog_offset(); |
| 58 | |
| 59 | void save_kernel_log(const char* destination); |
| 60 | |
xunchang | 2239b9e | 2019-04-15 15:24:24 -0700 | [diff] [blame] | 61 | std::vector<saved_log_file> ReadLogFilesToMemory(); |
| 62 | |
| 63 | bool RestoreLogFilesAfterFormat(const std::vector<saved_log_file>& log_files); |
| 64 | |
Jerry Zhang | cadf4ed | 2018-05-02 16:56:00 -0700 | [diff] [blame] | 65 | #endif //_LOGGING_H |