liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <time.h> |
| 4 | #include <stdio.h> |
| 5 | #include <unistd.h> |
| 6 | #include <sys/socket.h> |
| 7 | #include <time.h> |
| 8 | #include <errno.h> |
| 9 | #include <stdlib.h> |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 10 | #include <sys/file.h> |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 11 | #include <sys/types.h> |
| 12 | #include <sys/stat.h> |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 13 | #include <string.h> |
| 14 | #include <pthread.h> |
b.liu | 3fb0ffe | 2024-11-12 19:24:43 +0800 | [diff] [blame] | 15 | #include <signal.h> |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 16 | |
b.liu | b3b923a | 2024-06-06 15:15:49 +0800 | [diff] [blame] | 17 | #include "json-c/json.h" |
| 18 | #include "json-c/printbuf.h" |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 19 | #include "log_config.h" |
| 20 | |
b.liu | 5fa2fb5 | 2024-06-20 18:26:34 +0800 | [diff] [blame] | 21 | #include "mbtk_type.h" |
xf.li | 4364377 | 2024-03-04 19:39:53 -0800 | [diff] [blame] | 22 | //#define DEBUG 1 |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 23 | |
b.liu | 3fb0ffe | 2024-11-12 19:24:43 +0800 | [diff] [blame] | 24 | #ifdef MBTK_DUMP_SUPPORT |
| 25 | void mbtk_debug_open(const char *log_file, bool thread_support); |
| 26 | #endif |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 27 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 28 | #ifdef DEBUG |
| 29 | #define mbtk_log(...) printf(__VA_ARGS__) |
| 30 | #else |
| 31 | #define mbtk_log(...) |
| 32 | #endif |
| 33 | |
l.yang | d2c71bc | 2024-12-16 19:24:24 -0800 | [diff] [blame] | 34 | int emmc_pro = -1; |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 35 | |
| 36 | #define MAX_BUFFER_SIZE (8*1024) |
l.yang | e4285f2 | 2024-11-13 00:30:41 -0800 | [diff] [blame] | 37 | #define MAX_SLEEP_TIME 2147483647 |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 38 | |
| 39 | int tmp_syslog_fd = -1; |
| 40 | int tmp_rd_fd = -1; |
| 41 | |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 42 | //char syslog_buff[MAX_BUFFER_SIZE] = {0}; |
| 43 | //char radiolog_buff[MAX_BUFFER_SIZE] = {0}; |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 44 | |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 45 | char *radio_globalPtr = NULL; |
| 46 | char *sys_globalPtr = NULL; |
| 47 | |
| 48 | int radio_len = 0; |
| 49 | int sys_len = 0; |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 50 | |
| 51 | static void signal_handler(int signum) |
| 52 | { |
l.yang | d2c71bc | 2024-12-16 19:24:24 -0800 | [diff] [blame] | 53 | printf("Received SIGTERM signal, fflush buffer\n"); |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 54 | if(fcntl(tmp_syslog_fd, F_GETFL) != -1 && sys_globalPtr !=NULL ) |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 55 | { |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 56 | if(write(tmp_syslog_fd, sys_globalPtr, sys_len) < 0) |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 57 | { |
| 58 | perror("write error"); |
| 59 | } |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 60 | // memset(syslog_buff,0,MAX_BUFFER_SIZE); |
| 61 | memset(sys_globalPtr, 0, MAX_BUFFER_SIZE); |
| 62 | sys_globalPtr =NULL; |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 63 | } |
b.liu | 3fb0ffe | 2024-11-12 19:24:43 +0800 | [diff] [blame] | 64 | |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 65 | if(fcntl(tmp_rd_fd, F_GETFL) != -1 && radio_globalPtr !=NULL) |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 66 | { |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 67 | if(write(tmp_rd_fd, radio_globalPtr, radio_len) < 0) |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 68 | { |
| 69 | perror("write error"); |
| 70 | } |
l.yang | fa05af3 | 2024-11-27 00:00:56 -0800 | [diff] [blame] | 71 | |
| 72 | //memset(radiolog_buff,0,MAX_BUFFER_SIZE); |
| 73 | memset(radio_globalPtr, 0, MAX_BUFFER_SIZE); |
| 74 | radio_globalPtr =NULL; |
| 75 | |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 76 | } |
b.liu | 3fb0ffe | 2024-11-12 19:24:43 +0800 | [diff] [blame] | 77 | |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 78 | } |
| 79 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 80 | static void handler_free(log_config_entry* listdata) |
| 81 | { |
| 82 | int i, n; |
| 83 | struct filter_list_t* _filter_list = NULL; |
| 84 | log_config_entry* entry; |
| 85 | |
| 86 | for (i = 0; i < 5; i++) { |
| 87 | entry = listdata + i; |
| 88 | if (entry->name) { |
l.yang | e4285f2 | 2024-11-13 00:30:41 -0800 | [diff] [blame] | 89 | //free(entry->name); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 90 | if (entry->out_path) { |
l.yang | e4285f2 | 2024-11-13 00:30:41 -0800 | [diff] [blame] | 91 | //free(entry->out_path); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 92 | } |
| 93 | if (entry->ip) { |
| 94 | free(entry->ip); |
| 95 | } |
| 96 | _filter_list = entry->filter_list; |
| 97 | for (n = 0; n < 10; n++) { |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 98 | printf("%s %d: malloc %p!\n", __FUNCTION__, __LINE__, _filter_list); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 99 | if (_filter_list) { |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 100 | printf("%s %d: malloc %p!\n", __FUNCTION__, __LINE__, _filter_list->next); |
l.yang | e4285f2 | 2024-11-13 00:30:41 -0800 | [diff] [blame] | 101 | if (_filter_list->tag && _filter_list->tag[0] != '\0') { |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 102 | free(_filter_list->tag); |
| 103 | } |
b.liu | deb8e42 | 2024-12-14 17:36:56 +0800 | [diff] [blame] | 104 | struct filter_list_t* tmp_filter_list = _filter_list; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 105 | _filter_list = _filter_list->next; |
b.liu | deb8e42 | 2024-12-14 17:36:56 +0800 | [diff] [blame] | 106 | free(tmp_filter_list); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 107 | } else { |
| 108 | break; |
| 109 | } |
| 110 | } |
| 111 | } else { |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | int parse_config(log_config_entry* listdata) |
| 118 | { |
| 119 | json_object* jsonobj = NULL; |
| 120 | json_object* tmpjson = NULL; |
| 121 | json_object* datajson = NULL; |
| 122 | json_object* listjson = NULL; |
| 123 | json_object* fileterjson = NULL; |
| 124 | json_object* fileter_listjson = NULL; |
| 125 | log_config_entry* entry; |
xf.li | 4364377 | 2024-03-04 19:39:53 -0800 | [diff] [blame] | 126 | int i, n, ret, array_length; |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 127 | char* cmdval = NULL; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 128 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 129 | printf("MBTK_LOGD: in parse_config\n"); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 130 | jsonobj = json_object_from_file(LOG_CONFIG_PATH); |
| 131 | if (NULL == jsonobj) { |
| 132 | printf("Can't open config file: %s\n", LOG_CONFIG_PATH); |
| 133 | return -1; |
| 134 | } |
| 135 | ret = json_object_object_get_ex(jsonobj, "logd", &tmpjson); |
| 136 | if (!ret) { |
| 137 | printf("get jsondata error ...\n"); |
| 138 | } |
| 139 | |
| 140 | if (NULL == tmpjson) { |
| 141 | printf("the tmpjson : [%s]\n", json_object_to_json_string(tmpjson)); |
| 142 | } |
| 143 | /**获取total***/ |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 144 | cmdval = (char*)json_object_get_string(tmpjson); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 145 | printf("logd enable : %s\n", cmdval); |
| 146 | json_object_put(tmpjson); |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 147 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 148 | /***获取data***/ |
| 149 | json_object_object_get_ex(jsonobj, "buffer_list", &tmpjson); |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 150 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 151 | for (i = 0 ; i < 5; i++) { |
| 152 | struct filter_list_t* _filter_list = NULL; |
| 153 | struct filter_list_t* tmp_filter_list = NULL; |
| 154 | datajson = json_object_array_get_idx(tmpjson, i); |
| 155 | if (NULL == datajson) { |
| 156 | mbtk_log("the datajson exit\n"); |
| 157 | break; |
| 158 | } |
| 159 | entry = listdata + i; |
| 160 | json_object_object_get_ex(datajson, "enable", &listjson); |
| 161 | entry->enable = json_object_get_int(listjson); |
| 162 | mbtk_log("enable: %d\n", entry->enable); |
l.yang | d2c71bc | 2024-12-16 19:24:24 -0800 | [diff] [blame] | 163 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 164 | json_object_object_get_ex(datajson, "name", &listjson); |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 165 | entry->name = (char*)json_object_get_string(listjson); |
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 166 | printf("cmdval: %s\n", entry->name); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 167 | |
| 168 | json_object_object_get_ex(datajson, "log_file", &listjson); |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 169 | entry->out_path = (char*)json_object_get_string(listjson); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 170 | mbtk_log("cmdval: %s\n", entry->out_path); |
| 171 | |
l.yang | d2c71bc | 2024-12-16 19:24:24 -0800 | [diff] [blame] | 172 | json_object_object_get_ex(datajson, "emmc_protect", &listjson); |
| 173 | emmc_pro = json_object_get_int(listjson); |
| 174 | printf("emmc_pro enable: %d\n", emmc_pro); |
| 175 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 176 | json_object_object_get_ex(datajson, "log_stream", &listjson); |
| 177 | if (listjson) { |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 178 | entry->ip = (char*)json_object_get_string(listjson); |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 179 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 180 | cmdval = strstr(entry->ip, ":"); |
| 181 | if (cmdval) { |
| 182 | entry->port = &cmdval[1]; |
| 183 | cmdval[0] = 0; |
| 184 | mbtk_log("cmdval: %s [%s]\n", entry->ip, entry->port); |
| 185 | } else { |
| 186 | printf("Can't find port!!\n"); |
| 187 | free(entry->ip); |
| 188 | entry->ip = NULL; |
| 189 | } |
| 190 | } |
| 191 | json_object_object_get_ex(datajson, "rotate_file_size", &listjson); |
| 192 | entry->rotate_file_size = json_object_get_int(listjson) * 1024; |
| 193 | mbtk_log("rotate_file_size: %d\n", entry->rotate_file_size); |
| 194 | |
| 195 | json_object_object_get_ex(datajson, "rotate_file_count", &listjson); |
| 196 | entry->rotate_file_count = json_object_get_int(listjson); |
| 197 | mbtk_log("rotate_file_count: %d\n", entry->rotate_file_count); |
| 198 | |
| 199 | json_object_object_get_ex(datajson, "filter_list", &listjson); |
| 200 | if (NULL == listjson) { |
| 201 | printf("%s %d: object failure!\n", __FUNCTION__, __LINE__); |
| 202 | json_object_put(listjson); |
| 203 | continue; |
| 204 | } |
| 205 | entry->filter_list = (struct filter_list_t*)malloc(sizeof(struct filter_list_t)); |
| 206 | _filter_list = entry->filter_list; |
| 207 | |
xf.li | 4364377 | 2024-03-04 19:39:53 -0800 | [diff] [blame] | 208 | array_length = json_object_array_length(listjson); |
| 209 | for (n = 0 ; n <= array_length; n++) { |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 210 | fileterjson = json_object_array_get_idx(listjson, n); |
| 211 | if (NULL == fileterjson) { |
| 212 | mbtk_log("the fileterjson exit\n"); |
| 213 | free(tmp_filter_list->next); |
| 214 | tmp_filter_list->next = NULL; |
| 215 | break; |
| 216 | } |
| 217 | memset(_filter_list, 0, sizeof(struct filter_list_t)); |
| 218 | json_object_object_get_ex(fileterjson, "priority", &fileter_listjson); |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 219 | const char* str = json_object_get_string(fileter_listjson); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 220 | if (str) { |
| 221 | _filter_list->priority = str[0]; |
| 222 | mbtk_log("fileter_listjson: %c\n", _filter_list->priority); |
| 223 | } |
| 224 | json_object_object_get_ex(fileterjson, "tag", &fileter_listjson); |
| 225 | // if (NULL == fileter_listjson) { |
| 226 | // printf("%s %d: object failure!\n", __FUNCTION__, __LINE__); |
| 227 | // } |
| 228 | str = json_object_get_string(fileter_listjson); |
| 229 | if (str) { |
| 230 | _filter_list->tag = strdup(str); |
| 231 | mbtk_log("fileter_listjson: %s\n", _filter_list->tag); |
| 232 | } |
xf.li | 4364377 | 2024-03-04 19:39:53 -0800 | [diff] [blame] | 233 | else |
| 234 | { |
| 235 | _filter_list->tag = "\0"; |
| 236 | } |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 237 | |
| 238 | //json_object_put(fileter_listjson); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 239 | _filter_list->next = (struct filter_list_t*)malloc(sizeof(struct filter_list_t)); |
| 240 | if (NULL == _filter_list->next) { |
| 241 | printf("%s %d: malloc failure!\n", __FUNCTION__, __LINE__); |
| 242 | break; |
| 243 | } |
| 244 | tmp_filter_list = _filter_list; |
| 245 | _filter_list = _filter_list->next; |
| 246 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 247 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 248 | |
| 249 | /***释放json对象***/ |
| 250 | json_object_put(jsonobj); |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 251 | printf("MBTK_LOGD: parse_config end\n"); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | #define LOGD_PID "/var/run/mbtk_logd.pid" |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 256 | #if 0 |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 257 | static int save_pid(void) |
| 258 | { |
| 259 | pid_t process_id; |
| 260 | int fd, ret; |
| 261 | char buf[12] = {0}; |
| 262 | |
| 263 | process_id = getpid(); |
| 264 | if(access(LOGD_PID, F_OK) == 0) |
| 265 | { |
| 266 | printf("mbtk_logd 进程已经存在\n"); |
| 267 | return -1; |
| 268 | } |
| 269 | fd = open(LOGD_PID, O_CREAT | O_WRONLY, 0600); |
| 270 | if (fd < 0) { |
| 271 | fprintf(stderr, "failed to open %s: %s\n", LOGD_PID, strerror(errno)); |
| 272 | return -2; |
| 273 | } |
| 274 | snprintf(buf, sizeof(buf), "%d\n", process_id); |
| 275 | ret = write(fd, buf, strlen(buf)); |
| 276 | close(fd); |
| 277 | |
| 278 | if(ret > 0) |
| 279 | return 0; |
| 280 | else |
| 281 | return -2; |
| 282 | } |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 283 | #endif |
xf.li | 4364377 | 2024-03-04 19:39:53 -0800 | [diff] [blame] | 284 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 285 | int main(int argc, char* argv[]) |
| 286 | { |
| 287 | log_config_entry listdata[5]; |
| 288 | pthread_t pid[5] = {0}; |
| 289 | int i, ret; |
| 290 | void* tret; |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 291 | //struct filter_list_t* _filter_list = NULL; |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 292 | |
l.yang | 250444d | 2024-11-12 00:35:10 -0800 | [diff] [blame] | 293 | signal(SIGTERM, signal_handler); |
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 294 | #ifdef MBTK_DUMP_SUPPORT |
| 295 | mbtk_debug_open(NULL, TRUE); |
| 296 | #endif |
| 297 | |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 298 | int lock_file = open("/tmp/mbtk_logd.lock", O_CREAT|O_RDWR, 0666); |
| 299 | int rc = flock(lock_file,LOCK_EX|LOCK_NB); |
| 300 | if(rc) { |
| 301 | if(EWOULDBLOCK == errno) { |
| 302 | printf("Error: cannot restart the mbtk_logd repeatedly\n"); |
| 303 | exit(0); |
| 304 | } |
| 305 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 306 | |
| 307 | memset(listdata, 0, sizeof(log_config_entry) * 5); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 308 | ret = parse_config(listdata); |
| 309 | if (ret) { |
| 310 | return -1; |
| 311 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 312 | |
| 313 | printf("logd %s start !\n", __FUNCTION__); |
| 314 | |
| 315 | for (i = 0; i < 5; ++i) { |
| 316 | if (NULL == listdata[i].name) { |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | if (0 == listdata[i].enable) { |
| 321 | printf("%s log disabled !\n", listdata[i].name); |
| 322 | continue; |
| 323 | } |
| 324 | |
| 325 | if (0 == memcmp(listdata[i].name, "radio", 5)) { |
| 326 | ret = pthread_create(&pid[i], NULL, alog_thread, &listdata[i]); |
| 327 | if (ret != 0) { |
| 328 | fprintf(stderr, "\n%s: Failed to create pthread\n", __FUNCTION__); |
| 329 | } |
| 330 | } else if (0 == memcmp(listdata[i].name, "syslog", 6)) { |
| 331 | ret = pthread_create(&pid[i], NULL, syslog_main, &listdata[i]); |
| 332 | if (ret != 0) { |
| 333 | fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__); |
| 334 | } |
| 335 | } else if (0 == memcmp(listdata[i].name, "local_socket", 12)) { |
| 336 | ret = pthread_create(&pid[i], NULL, socket_log_thread, &listdata[i]); |
| 337 | if (ret != 0) { |
| 338 | fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__); |
| 339 | } |
xf.li | 44e0869 | 2024-01-30 01:54:44 -0800 | [diff] [blame] | 340 | } else if (0 == memcmp(listdata[i].name, "/dev/ttyS0", 8)) { |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 341 | ret = pthread_create(&pid[i], NULL, common_log_thread, &listdata[i]); |
| 342 | if (ret != 0) { |
| 343 | fprintf(stderr, "\n%s %d: Failed to create pthread\n", __FUNCTION__, __LINE__); |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
b.liu | 5fa2fb5 | 2024-06-20 18:26:34 +0800 | [diff] [blame] | 348 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 349 | for (i = 0; i < 5; ++i) { |
| 350 | if (NULL == listdata[i].name) { |
| 351 | break; |
| 352 | } |
| 353 | if (pid[i]) { |
| 354 | if (pthread_join(pid[i], &tret) != 0) { |
b.liu | 0f7ffad | 2024-11-06 19:57:27 +0800 | [diff] [blame] | 355 | printf("Join thread %d : %ld error!\n", i, pid[i]); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 356 | exit(1); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | handler_free(listdata); |
l.yang | e4285f2 | 2024-11-13 00:30:41 -0800 | [diff] [blame] | 361 | sleep(MAX_SLEEP_TIME); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 362 | return 0; |
| 363 | } |