xref: /aosp_15_r20/system/logging/liblog/log_event_write.cpp (revision 598139dc91b21518d67c408eaea2644226490971)
1*598139dcSAndroid Build Coastguard Worker /*
2*598139dcSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*598139dcSAndroid Build Coastguard Worker  *
4*598139dcSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*598139dcSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*598139dcSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*598139dcSAndroid Build Coastguard Worker  *
8*598139dcSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*598139dcSAndroid Build Coastguard Worker  *
10*598139dcSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*598139dcSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*598139dcSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*598139dcSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*598139dcSAndroid Build Coastguard Worker  * limitations under the License.
15*598139dcSAndroid Build Coastguard Worker  */
16*598139dcSAndroid Build Coastguard Worker 
17*598139dcSAndroid Build Coastguard Worker #include <errno.h>
18*598139dcSAndroid Build Coastguard Worker #include <stdint.h>
19*598139dcSAndroid Build Coastguard Worker 
20*598139dcSAndroid Build Coastguard Worker #include <log/log.h>
21*598139dcSAndroid Build Coastguard Worker #include <log/log_event_list.h>
22*598139dcSAndroid Build Coastguard Worker 
23*598139dcSAndroid Build Coastguard Worker #define MAX_SUBTAG_LEN 32
24*598139dcSAndroid Build Coastguard Worker 
__android_log_error_write(int tag,const char * subTag,int32_t uid,const char * data,uint32_t dataLen)25*598139dcSAndroid Build Coastguard Worker int __android_log_error_write(int tag, const char* subTag, int32_t uid, const char* data,
26*598139dcSAndroid Build Coastguard Worker                               uint32_t dataLen) {
27*598139dcSAndroid Build Coastguard Worker   int ret = -EINVAL;
28*598139dcSAndroid Build Coastguard Worker 
29*598139dcSAndroid Build Coastguard Worker   if (subTag && (data || !dataLen)) {
30*598139dcSAndroid Build Coastguard Worker     android_log_context ctx = create_android_logger(tag);
31*598139dcSAndroid Build Coastguard Worker 
32*598139dcSAndroid Build Coastguard Worker     ret = -ENOMEM;
33*598139dcSAndroid Build Coastguard Worker     if (ctx) {
34*598139dcSAndroid Build Coastguard Worker       ret = android_log_write_string8_len(ctx, subTag, MAX_SUBTAG_LEN);
35*598139dcSAndroid Build Coastguard Worker       if (ret >= 0) {
36*598139dcSAndroid Build Coastguard Worker         ret = android_log_write_int32(ctx, uid);
37*598139dcSAndroid Build Coastguard Worker         if (ret >= 0) {
38*598139dcSAndroid Build Coastguard Worker           ret = android_log_write_string8_len(ctx, data, dataLen);
39*598139dcSAndroid Build Coastguard Worker           if (ret >= 0) {
40*598139dcSAndroid Build Coastguard Worker             ret = android_log_write_list(ctx, LOG_ID_EVENTS);
41*598139dcSAndroid Build Coastguard Worker           }
42*598139dcSAndroid Build Coastguard Worker         }
43*598139dcSAndroid Build Coastguard Worker       }
44*598139dcSAndroid Build Coastguard Worker       android_log_destroy(&ctx);
45*598139dcSAndroid Build Coastguard Worker     }
46*598139dcSAndroid Build Coastguard Worker   }
47*598139dcSAndroid Build Coastguard Worker   return ret;
48*598139dcSAndroid Build Coastguard Worker }
49