From: hyunuktak Date: Wed, 21 Nov 2018 07:48:05 +0000 (+0900) Subject: Separate debug log with info config X-Git-Tag: accepted/tizen/unified/20181212.062514~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f2380cadc63c01f6dee9780e7f3ab6ce19ee8faa;hp=0b23a20ddb9cebc70d966936a54f5b1082ea38b7;p=platform%2Fcore%2Fconnectivity%2Fstc-manager.git Separate debug log with info config Change-Id: I87608b9729a8ad5872c8edc69b1a2aac896421af Signed-off-by: hyunuktak --- diff --git a/include/stc-manager-util.h b/include/stc-manager-util.h index b12fff9..4b2eb94 100755 --- a/include/stc-manager-util.h +++ b/include/stc-manager-util.h @@ -330,7 +330,11 @@ static inline bool strstart_with(const char *str, const char *with) #define INFO_STORAGE_DIR "/var/lib/stc" #define INFO_CONFIG "info.config" -#define INFO_DEBUGLOG "debuglog" +#define INFO_DEBUG_LOG "debug_log" +#define INFO_STAT_LOG "stat_log" +#define INFO_RSTN_LOG "rstn_log" +#define INFO_FW_LOG "fw_log" +#define INFO_PCAP_LOG "pcap_log" #define MAX_PATH_LENGTH 512 #define MAX_NAME_LENGTH 256 @@ -395,12 +399,22 @@ enum stc_counter_state { STC_UPDATE_REQUESTED = 1 << 5, }; +typedef enum { + DEBUG_LOG_INFO, + STAT_LOG_INFO, + RSTN_LOG_INFO, + FW_LOG_INFO, + PCAP_LOG_INFO, + MAX_LOG_INFO +} log_info_e; + gboolean stc_util_get_config_bool(char *key); gchar * stc_util_get_config_str(char *key); int stc_util_get_config_int(char *key); -void stc_util_set_debuglog(int debuglog); -int stc_util_get_debuglog(void); +void stc_util_update_log_state(void); +void stc_util_set_log_state(log_info_e info, int state); +int stc_util_get_log_state(log_info_e info); void stc_util_initialize_config(void); diff --git a/include/stc-manager.h b/include/stc-manager.h index fabbbb1..0b930eb 100755 --- a/include/stc-manager.h +++ b/include/stc-manager.h @@ -39,7 +39,11 @@ #define STC_CMD_INSERT "-I" #define STC_CMD_SIZE 256 -#define STC_DEBUG_LOG (stc_util_get_debuglog()) +#define STC_DEBUG_LOG (stc_util_get_log_state(DEBUG_LOG_INFO)) +#define STC_STAT_LOG (stc_util_get_log_state(STAT_LOG_INFO)) +#define STC_RSTN_LOG (stc_util_get_log_state(RSTN_LOG_INFO)) +#define STC_FW_LOG (stc_util_get_log_state(FW_LOG_INFO)) +#define STC_PCAP_LOG (stc_util_get_log_state(PCAP_LOG_INFO)) typedef enum { STC_CANCEL = 0, /**< cancel */ diff --git a/plugin/appstatus/stc-plugin-appstatus.c b/plugin/appstatus/stc-plugin-appstatus.c old mode 100644 new mode 100755 index 2fd1b9e..98fab81 --- a/plugin/appstatus/stc-plugin-appstatus.c +++ b/plugin/appstatus/stc-plugin-appstatus.c @@ -87,7 +87,7 @@ static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection, else apptype = STC_APP_TYPE_GUI; - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { STC_LOGD("\033[1;34mAPP STATUS\033[0;m: PkgID[\033[0;34m%s\033[0;m] " "AppID[\033[0;32m%s\033[0;m] PID[\033[1;33m%d\033[0;m] Status[%s] Type[%s]", pkgid, appid, pid, statstr, pkgtype); diff --git a/plugin/exception/stc-plugin-exception.c b/plugin/exception/stc-plugin-exception.c old mode 100644 new mode 100755 index 4769c3e..cdb47c4 --- a/plugin/exception/stc-plugin-exception.c +++ b/plugin/exception/stc-plugin-exception.c @@ -99,7 +99,7 @@ static void __excn_hash_foreach_print(gpointer key, gpointer value, const char *process_name = key; const char *exe_type = value; - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGI("Process_name[%s] exe_type[%s]", process_name, exe_type); } @@ -258,7 +258,7 @@ int stc_plugin_exception_fill_list(void) table_exceptions_foreach(__insert_exception_cb, NULL); pkginfo_exceptions_foreach(__insert_exception_cb, NULL); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) __excn_hash_printall(); g_excns_timer_id = g_timeout_add_seconds(EXCNS_TIMER_INTERVAL, @@ -273,7 +273,7 @@ int stc_plugin_exception_update_list(void) __remove_exception_appall(); pkginfo_exceptions_foreach(__insert_exception_cb, NULL); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) __excn_hash_printall(); return STC_ERROR_NONE; diff --git a/plugin/pcap/stc-plugin-pcap.c b/plugin/pcap/stc-plugin-pcap.c index 8cba6bd..22dddb7 100755 --- a/plugin/pcap/stc-plugin-pcap.c +++ b/plugin/pcap/stc-plugin-pcap.c @@ -117,18 +117,20 @@ static void __pcap_ntp_info(const u_char *packet) __pcap_ntp_time_info(ntp_h->rectime.second, rectime); __pcap_ntp_time_info(ntp_h->xmttime.second, xmttime); - STC_LOGD("Flags[0x%02x] Stratum[%u] Poll[%u:%us] Precision[%u] " - "Root delay[%u.%06us] Root dispersion[%u.%06us] Ref ID[%s]", - ntp_h->flags, ntp_h->stratum, ntp_h->poll, - ntp_h->precision, 1 << ntp_h->precision, - ntohs(ntp_h->rootdelay.second), - __pcap_ntp_fraction_info(ntp_h->rootdelay.fraction), - ntohs(ntp_h->rootdisp.second), - __pcap_ntp_fraction_info(ntp_h->rootdisp.fraction), - refid); - - STC_LOGD("Reference[%s] Origin[%s] Receive[%s] Transmit[%s]", - reftime, orgtime, rectime, xmttime); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Flags[0x%02x] Stratum[%u] Poll[%u:%us] Precision[%u] " + "Root delay[%u.%06us] Root dispersion[%u.%06us] Ref ID[%s]", + ntp_h->flags, ntp_h->stratum, ntp_h->poll, + ntp_h->precision, 1 << ntp_h->precision, + ntohs(ntp_h->rootdelay.second), + __pcap_ntp_fraction_info(ntp_h->rootdelay.fraction), + ntohs(ntp_h->rootdisp.second), + __pcap_ntp_fraction_info(ntp_h->rootdisp.fraction), + refid); + + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Reference[%s] Origin[%s] Receive[%s] Transmit[%s]", + reftime, orgtime, rectime, xmttime); } static const char *__pcap_dhcp_client_id_info(uint8_t data) @@ -224,7 +226,8 @@ static void __pcap_bootp_magic_info(uint32_t magic, char buf[BOOTP_MOPTION_LEN]; uint8_t *opt = moption; - STC_LOGD("Magic cookie[DHCP]"); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Magic cookie[DHCP]"); while(len > 0) { uint8_t tag = opt[0]; @@ -237,60 +240,73 @@ static void __pcap_bootp_magic_info(uint32_t magic, case DHCP_TAG_SUBNET_MASK: inet_ntop(AF_INET, (struct in_addr *)data, addr, BUFF_SIZE_IP); - STC_LOGD("Subnet mask[%s]", addr); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Subnet mask[%s]", addr); break; case DHCP_TAG_ROUTER: inet_ntop(AF_INET, (struct in_addr *)data, addr, BUFF_SIZE_IP); - STC_LOGD("Router[%s]", addr); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Router[%s]", addr); break; case DHCP_TAG_DNS: inet_ntop(AF_INET, (struct in_addr *)data, addr, BUFF_SIZE_IP); - STC_LOGD("Domain name server[%s]", addr); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Domain name server[%s]", addr); break; case DHCP_TAG_HOST_NAME: snprintf(buf, ((length < BOOTP_MOPTION_LEN) ? (length + 1) : BOOTP_MOPTION_LEN), "%s", (char *)data); - STC_LOGD("Host name[%s]", buf); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Host name[%s]", buf); break; case DHCP_TAG_REQUESTED_IP: inet_ntop(AF_INET, (struct in_addr *)data, addr, BUFF_SIZE_IP); - STC_LOGD("Requested IP[%s]", addr); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Requested IP[%s]", addr); break; case DHCP_TAG_IP_LEASE_TIME: - STC_LOGD("IP address lease time[%us]", - ntohl(*(uint32_t *)data)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("IP address lease time[%us]", + ntohl(*(uint32_t *)data)); break; case DHCP_TAG_MSG_TYPE: - STC_LOGD("DHCP message type[%u:%s]", *data, - __pcap_dhcp_msg_type_info(*data)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("DHCP message type[%u:%s]", *data, + __pcap_dhcp_msg_type_info(*data)); break; case DHCP_TAG_SERVER_ID: inet_ntop(AF_INET, (struct in_addr *)data, addr, BUFF_SIZE_IP); - STC_LOGD("DHCP server identifier[%s]", addr); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("DHCP server identifier[%s]", addr); break; case DHCP_TAG_MSG_SIZE: - STC_LOGD("Maximum DHCP message size[%u]", - ntohs(*(uint16_t *)data)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Maximum DHCP message size[%u]", + ntohs(*(uint16_t *)data)); break; case DHCP_TAG_CLIENT_ID: - STC_LOGD("Client identifier HW type[0x%02x:%s]", *data, - __pcap_dhcp_client_id_info(*data)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Client identifier HW type[0x%02x:%s]", *data, + __pcap_dhcp_client_id_info(*data)); if (*data == DHCP_CLIENT_ID_ETHERNET) { g_strlcpy(host, ether_ntoa((const struct ether_addr *)&data[1]), sizeof(host)); - STC_LOGD("Client identifier MAC[%s]", host); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Client identifier MAC[%s]", host); } break; case DHCP_TAG_END: - STC_LOGD("End"); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("End"); return; default: - STC_LOGD("Unknown[%u]", tag); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Unknown[%u]", tag); break; } @@ -341,15 +357,17 @@ static void __pcap_bootp_info(const u_char *packet) ether_ntoa((const struct ether_addr *)bootp_h->chaddr), sizeof(chaddr)); - STC_LOGD("Message type[%u:%s] HW type[0x%02x] HW len[%u] Hops[%u] " - "Transaction ID[0x%08x] Seconds elapsed[%u] Flags[0x%04x]", - bootp_h->op, __pcap_bootp_op_info(bootp_h->op), - bootp_h->htype, bootp_h->hlen, bootp_h->hops, - ntohl(bootp_h->xid), ntohs(bootp_h->secs), ntohs(bootp_h->flags)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Message type[%u:%s] HW type[0x%02x] HW len[%u] Hops[%u] " + "Transaction ID[0x%08x] Seconds elapsed[%u] Flags[0x%04x]", + bootp_h->op, __pcap_bootp_op_info(bootp_h->op), + bootp_h->htype, bootp_h->hlen, bootp_h->hops, + ntohl(bootp_h->xid), ntohs(bootp_h->secs), ntohs(bootp_h->flags)); - STC_LOGD("Client[%s] Your(client)[%s] Next server[%s] " - "Relay agent[%s] Client MAC[%s]", - ciaddr, yiaddr, siaddr, giaddr, chaddr); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Client[%s] Your(client)[%s] Next server[%s] " + "Relay agent[%s] Client MAC[%s]", + ciaddr, yiaddr, siaddr, giaddr, chaddr); len = ntohs(udp_h->len); __pcap_bootp_magic_info(bootp_h->magic, bootp_h->moption, len); @@ -460,8 +478,10 @@ static void __pcap_dns_data_info(const u_char *packet) uint16_t type; uint16_t class; - if (i == 0) - STC_LOGD("[Queries]"); + if (i == 0) { + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("[Queries]"); + } data = __pcap_dns_name_info((uint8_t *)dns_h, data, name); if (data == NULL) @@ -470,9 +490,10 @@ static void __pcap_dns_data_info(const u_char *packet) type = ntohs(*(uint16_t *)&data[0]); class = ntohs(*(uint16_t *)&data[2]); - STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s]", - name, type, __pcap_dns_type_info(type), - class, __pcap_dns_class_info(class)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s]", + name, type, __pcap_dns_type_info(type), + class, __pcap_dns_class_info(class)); data += 4; } @@ -486,8 +507,10 @@ static void __pcap_dns_data_info(const u_char *packet) uint16_t length; char ip[BUFF_SIZE_IP]; - if (i == 0) - STC_LOGD("[Answers]"); + if (i == 0) { + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("[Answers]"); + } data = __pcap_dns_name_info((uint8_t *)dns_h, data, name); if (data == NULL) @@ -503,30 +526,33 @@ static void __pcap_dns_data_info(const u_char *packet) case DNS_QTYPE_A: inet_ntop(AF_INET, (struct in_addr *)&data[10], ip, BUFF_SIZE_IP); - STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " - "TTL[%u] Data length[%u] Address[%s]", - name, type, __pcap_dns_type_info(type), - class, __pcap_dns_class_info(class), - ttl, length, ip); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " + "TTL[%u] Data length[%u] Address[%s]", + name, type, __pcap_dns_type_info(type), + class, __pcap_dns_class_info(class), + ttl, length, ip); break; case DNS_QTYPE_CNAME: __pcap_dns_name_info((uint8_t *)dns_h, &data[10], cname); if (data == NULL) return; - STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " - "TTL[%u] Data length[%u] CName[%s]", - name, type, __pcap_dns_type_info(type), - class, __pcap_dns_class_info(class), - ttl, length, cname); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " + "TTL[%u] Data length[%u] CName[%s]", + name, type, __pcap_dns_type_info(type), + class, __pcap_dns_class_info(class), + ttl, length, cname); break; case DNS_QTYPE_AAAA: break; default: - STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " - "TTL[%u] Data length[%u]", - name, type, __pcap_dns_type_info(type), - class, __pcap_dns_class_info(class), - ttl, length); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Name[%s] Type[%u:%s] Class[0x%04x:%s] " + "TTL[%u] Data length[%u]", + name, type, __pcap_dns_type_info(type), + class, __pcap_dns_class_info(class), + ttl, length); break; } } @@ -540,11 +566,12 @@ static void __pcap_dns_info(const u_char *packet) dns_t *dns_h = (dns_t *)(packet + SIZE_ETHER_HEADER + SIZE_IP_HEADER + SIZE_UDP_HEADER); - STC_LOGD("Transaction ID[0x%x] Flags[0x%x] Questions[%u] " - "Answer RRs[%u] Authority RRs[%u] Additional RRs[%u]", - ntohs(dns_h->id), ntohs(dns_h->flags), - ntohs(dns_h->questions), ntohs(dns_h->answerRR), - ntohs(dns_h->authorityRR), ntohs(dns_h->additionalRR)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Transaction ID[0x%x] Flags[0x%x] Questions[%u] " + "Answer RRs[%u] Authority RRs[%u] Additional RRs[%u]", + ntohs(dns_h->id), ntohs(dns_h->flags), + ntohs(dns_h->questions), ntohs(dns_h->answerRR), + ntohs(dns_h->authorityRR), ntohs(dns_h->additionalRR)); __pcap_dns_data_info(packet); } @@ -699,10 +726,11 @@ static void __pcap_icmp_info(const u_char *packet) icmp_t *icmp_h = (icmp_t *)(packet + SIZE_ETHER_HEADER + SIZE_IP_HEADER); - STC_LOGD("Type[%u:%s] Code[%u:%s] Checksum[0x%x]", - icmp_h->type, __pcap_icmp_type_info(icmp_h->type), - icmp_h->code, __pcap_icmp_code_info(icmp_h->type, icmp_h->code), - ntohs(icmp_h->checksum)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Type[%u:%s] Code[%u:%s] Checksum[0x%x]", + icmp_h->type, __pcap_icmp_type_info(icmp_h->type), + icmp_h->code, __pcap_icmp_code_info(icmp_h->type, icmp_h->code), + ntohs(icmp_h->checksum)); } static void __pcap_tcp_info(const u_char *packet) @@ -712,13 +740,15 @@ static void __pcap_tcp_info(const u_char *packet) u_int16_t source = ntohs(tcp_h->source); u_int16_t dest = ntohs(tcp_h->dest); - STC_LOGD("Source[%u] Destination[%u] Sequence[%u] " - "Acknowledgment seq[%u] Window size[%u] ", - ntohs(tcp_h->source), ntohs(tcp_h->dest), - ntohl(tcp_h->seq), ntohl(tcp_h->ack_seq), - ntohs(tcp_h->window)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Source[%u] Destination[%u] Sequence[%u] " + "Acknowledgment seq[%u] Window size[%u] ", + ntohs(tcp_h->source), ntohs(tcp_h->dest), + ntohl(tcp_h->seq), ntohl(tcp_h->ack_seq), + ntohs(tcp_h->window)); - STC_LOGD("Checksum[0x%x] URG[%u] ACK[%u] PUSH[%u] " + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Checksum[0x%x] URG[%u] ACK[%u] PUSH[%u] " "RST[%u] SYN[%u] FIN[%u]", ntohs(tcp_h->check), tcp_h->urg, tcp_h->ack, tcp_h->psh, @@ -735,8 +765,9 @@ static void __pcap_udp_info(const u_char *packet) u_int16_t source = ntohs(udp_h->source); u_int16_t dest = ntohs(udp_h->dest); - STC_LOGD("Source[%u] Destination[%u] Len[%u] Checksum[0x%x]", - source, dest, ntohs(udp_h->len), ntohs(udp_h->check)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Source[%u] Destination[%u] Len[%u] Checksum[0x%x]", + source, dest, ntohs(udp_h->len), ntohs(udp_h->check)); if (IS_SRC_OR_DST_PORT(PORT_DNS)) __pcap_dns_info(packet); @@ -827,16 +858,18 @@ static void __pcap_arp_info(const u_char *packet) ar_pro = ntohs(arp_h->ar_pro); - STC_LOGD("HW type[%u] Protocol type[0x%04x:%s] " - "HW size[%u] Protocol size[%u] Opcode[%u:%s] ", - ntohs(arp_h->ar_hrd), ar_pro, - __pcap_eth_type_info(ar_pro), - arp_h->ar_hln, arp_h->ar_pln, - ar_op, __pcap_arp_opcode_info(ar_op)); - - STC_LOGD("Sender MAC[%s] Sender IP[%s] " - "Target MAC[%s] Target IP[%s]", - sma, sia, tma, tia); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("HW type[%u] Protocol type[0x%04x:%s] " + "HW size[%u] Protocol size[%u] Opcode[%u:%s] ", + ntohs(arp_h->ar_hrd), ar_pro, + __pcap_eth_type_info(ar_pro), + arp_h->ar_hln, arp_h->ar_pln, + ar_op, __pcap_arp_opcode_info(ar_op)); + + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Sender MAC[%s] Sender IP[%s] " + "Target MAC[%s] Target IP[%s]", + sma, sia, tma, tia); } static const char *__pcap_ip_protocol_info(u_int8_t p) @@ -882,11 +915,12 @@ static void __pcap_ipv6_info(const u_char *packet) inet_ntop(AF_INET6, &ip6_h->ip6_src, ip6_src, BUFF_SIZE_IP6); inet_ntop(AF_INET6, &ip6_h->ip6_dst, ip6_dst, BUFF_SIZE_IP6); - STC_LOGD("Flow[0x%08x] Payload len[%u] Next hdr[%u:%s] " - "Hop limit[%u] Source[%s] Destination[%s]", - ntohl(ip6_h->ip6_flow), ntohs(ip6_h->ip6_plen), - ip6_h->ip6_nxt, __pcap_ip_protocol_info(ip6_h->ip6_nxt), - ip6_h->ip6_hlim, ip6_src, ip6_dst); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Flow[0x%08x] Payload len[%u] Next hdr[%u:%s] " + "Hop limit[%u] Source[%s] Destination[%s]", + ntohl(ip6_h->ip6_flow), ntohs(ip6_h->ip6_plen), + ip6_h->ip6_nxt, __pcap_ip_protocol_info(ip6_h->ip6_nxt), + ip6_h->ip6_hlim, ip6_src, ip6_dst); switch (ip6_h->ip6_nxt) { case IPPROTO_IP: @@ -917,15 +951,16 @@ static void __pcap_ip_info(const u_char *packet) inet_ntop(AF_INET, &ip_h->ip_src, ip_src, BUFF_SIZE_IP); inet_ntop(AF_INET, &ip_h->ip_dst, ip_dst, BUFF_SIZE_IP); - STC_LOGD("Header len[%u] TOS[0x%02x] Total len[%u] " - "ID[0x%04x] Flags[0x%02x] TTL[%u] Protocol[%u:%s] " - "Checksum[0x%04x] Source[%s] Destination[%s]", - ip_h->ip_hl << 2, ip_h->ip_tos, - ntohs(ip_h->ip_len), ntohs(ip_h->ip_id), - (ntohs(ip_h->ip_off) & 0xe000) >> 13, - ip_h->ip_ttl, ip_h->ip_p, - __pcap_ip_protocol_info(ip_h->ip_p), - ntohs(ip_h->ip_sum), ip_src, ip_dst); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Header len[%u] TOS[0x%02x] Total len[%u] " + "ID[0x%04x] Flags[0x%02x] TTL[%u] Protocol[%u:%s] " + "Checksum[0x%04x] Source[%s] Destination[%s]", + ip_h->ip_hl << 2, ip_h->ip_tos, + ntohs(ip_h->ip_len), ntohs(ip_h->ip_id), + (ntohs(ip_h->ip_off) & 0xe000) >> 13, + ip_h->ip_ttl, ip_h->ip_p, + __pcap_ip_protocol_info(ip_h->ip_p), + ntohs(ip_h->ip_sum), ip_src, ip_dst); switch (ip_h->ip_p) { case IPPROTO_ICMP: @@ -961,8 +996,9 @@ static void __pcap_eth_info(const u_char *packet) ether_type = ntohs(eth_h->ether_type); - STC_LOGD("Source[%s] Destination[%s] Type[0x%04x:%s]", - shost, dhost, ether_type, __pcap_eth_type_info(ether_type)); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Source[%s] Destination[%s] Type[0x%04x:%s]", + shost, dhost, ether_type, __pcap_eth_type_info(ether_type)); } static void __pcap_fm_info(const struct pcap_pkthdr *pkthdr) @@ -982,11 +1018,12 @@ static void __pcap_fm_info(const struct pcap_pkthdr *pkthdr) len = strlen(curr); curr[len - 1] = '\0'; - STC_LOGD("Arrival time[%s] Timeval[%.06f] " - "Frame len[%u] Capture len[%u]", curr, - (float)((tv_sec - g_pcap_tv.tv_sec) * 1000000 + - (tv_usec - g_pcap_tv.tv_usec)) / 1000000, - pkthdr->len, pkthdr->caplen); + if (STC_DEBUG_LOG && STC_PCAP_LOG) + STC_LOGD("Arrival time[%s] Timeval[%.06f] " + "Frame len[%u] Capture len[%u]", curr, + (float)((tv_sec - g_pcap_tv.tv_sec) * 1000000 + + (tv_usec - g_pcap_tv.tv_usec)) / 1000000, + pkthdr->len, pkthdr->caplen); } static void __pcap_handler(u_char *param, diff --git a/plugin/procfs/stc-plugin-procfs.c b/plugin/procfs/stc-plugin-procfs.c index 4aa36c6..5a323a4 100755 --- a/plugin/procfs/stc-plugin-procfs.c +++ b/plugin/procfs/stc-plugin-procfs.c @@ -135,7 +135,7 @@ static proc_value_s * __proc_tree_find_parent(proc_value_s *value) parent = lookup; } while (lookup); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { if (parent != NULL) STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] " "pid[%s] ppid[%s] cmdline[\033[0;34m%s\033[0;m] name[%s]", @@ -158,7 +158,7 @@ static void __proc_tree_add(proc_key_s *key, proc_value_s *value) } if (key == NULL || value == NULL) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGE("invalid parameters"); return; } @@ -318,7 +318,7 @@ static void __process_event_fork(int tgid, int pid) g_strlcpy(value.status[i], status[i], sizeof(value.status[i])); g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline)); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("\033[1;32mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] " "ppid=[%s] cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid); @@ -357,7 +357,7 @@ static void __process_event_exec(int tgid, int pid) sizeof(value.status[i])); g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline)); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] " "ppid[%s] cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid); @@ -379,7 +379,7 @@ static void __process_event_exit(int tgid, int pid, int exit_code) if (lookup == NULL) /* unmonitored process */ return; - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] " "cmdline[\033[0;34m%s\033[0;m] pid[%d] exitcode[%d]", tgid, lookup->cmdline, pid, exit_code); @@ -591,7 +591,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd, { stc_error_e ret = STC_ERROR_NONE; - if ((pkg_id && app_id) && STC_DEBUG_LOG) + if ((pkg_id && app_id) && STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("cmd[%d] pkgid[%s] appid[%s] pid[%d] type[%d]", cmd, pkg_id, app_id, pid, app_type); diff --git a/src/database/tables/table-statistics.c b/src/database/tables/table-statistics.c old mode 100644 new mode 100755 index 5983ad7..f8db77b --- a/src/database/tables/table-statistics.c +++ b/src/database/tables/table-statistics.c @@ -621,7 +621,7 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key, goto handle_error; //LCOV_EXCL_LINE } - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("App stat recorded [\033[0;34m%s\033[0;m] " "rcv[%lld] snd[%lld]", stat->app_id, rcv, snd); diff --git a/src/helper/helper-cgroup.c b/src/helper/helper-cgroup.c old mode 100644 new mode 100755 index ee7c282..fbb0024 --- a/src/helper/helper-cgroup.c +++ b/src/helper/helper-cgroup.c @@ -119,7 +119,7 @@ int cgroup_write_node_uint32(const char *cgroup_name, char buf[MAX_PATH_LENGTH]; snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("cgroup_buf %s, value %d\n", buf, value); //LCOV_EXCL_LINE return fwrite_uint(buf, value); @@ -131,7 +131,7 @@ int cgroup_write_node_str(const char *cgroup_name, char buf[MAX_PATH_LENGTH]; snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("cgroup_buf %s, string %s\n", buf, string); //LCOV_EXCL_LINE return fwrite_str(buf, string); @@ -145,7 +145,7 @@ int cgroup_read_node_uint32(const char *cgroup_name, snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name); ret = fread_uint(buf, value); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); //LCOV_EXCL_LINE return ret; diff --git a/src/monitor/stc-monitor-app.c b/src/monitor/stc-monitor-app.c old mode 100644 new mode 100755 index 96d602a..ceeb0b4 --- a/src/monitor/stc-monitor-app.c +++ b/src/monitor/stc-monitor-app.c @@ -363,7 +363,7 @@ API stc_error_e stc_monitor_app_add(uint32_t classid, lookup_value = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (lookup_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGE("Already exists [\033[1;36m%d\033[0;m:" "\033[0;32m%s\033[0;m]", classid, app_id); return STC_ERROR_NONE; @@ -371,7 +371,7 @@ API stc_error_e stc_monitor_app_add(uint32_t classid, app_value = MALLOC0(stc_app_value_s, 1); if (!app_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGE("Value allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -411,7 +411,7 @@ API stc_error_e stc_monitor_app_add(uint32_t classid, stc_monitor_rstn_add_for_app(classid); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { __print_app(GUINT_TO_POINTER(classid), app_value, NULL); STC_LOGD("\033[1;32mApplication added\033[0;m " "[\033[1;36m%d\033[0;m]", classid); @@ -570,7 +570,7 @@ API stc_error_e stc_monitor_app_remove(uint32_t classid, const char *app_id) app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (!app_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid); return STC_ERROR_FAIL; } @@ -589,7 +589,7 @@ API stc_error_e stc_monitor_app_remove(uint32_t classid, const char *app_id) /* remove ristrictions if any */ stc_monitor_rstn_remove_for_app(classid); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) __print_app(GUINT_TO_POINTER(classid), app_lookup, NULL); /* remove app_key from the stc-manager */ diff --git a/src/monitor/stc-monitor-proc.c b/src/monitor/stc-monitor-proc.c old mode 100644 new mode 100755 index e472421..be12dd1 --- a/src/monitor/stc-monitor-proc.c +++ b/src/monitor/stc-monitor-proc.c @@ -42,7 +42,7 @@ static void __proc_remove_pid(gpointer key, gpointer value, if (!g_hash_table_remove(app_value->processes, GUINT_TO_POINTER(context->pid))) return; - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { __print_proc_all(app_value->processes); STC_LOGD("\033[1;31mProcess removed\033[0;m " "[\033[1;33m%d\033[0;m]", context->pid); @@ -91,7 +91,7 @@ API stc_error_e stc_monitor_proc_update_ground(uint32_t classid, app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (!app_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid); return STC_ERROR_NO_DATA; } @@ -99,7 +99,7 @@ API stc_error_e stc_monitor_proc_update_ground(uint32_t classid, proc_lookup = g_hash_table_lookup(app_lookup->processes, GUINT_TO_POINTER(value.pid)); if (!proc_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", value.pid); return STC_ERROR_NO_DATA; } @@ -130,7 +130,7 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (!app_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid); return STC_ERROR_NO_DATA; } @@ -138,14 +138,14 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, proc_lookup = g_hash_table_lookup(app_lookup->processes, GUINT_TO_POINTER(value.pid)); if (proc_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGE("Already exists [\033[1;36m%d\033[0;m]", value.pid); return STC_ERROR_NONE; } proc_value = MALLOC0(stc_proc_value_s, 1); if (!proc_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGE("Value allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -160,7 +160,7 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, /* add pid to application cgroup */ place_pids_to_net_cgroup(proc_value->pid, app_id); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { __print_proc_all(app_lookup->processes); STC_LOGD("\033[1;32mProcess added\033[0;m " "[\033[1;33m%d\033[0;m]", proc_value->pid); @@ -193,21 +193,21 @@ API stc_error_e stc_monitor_proc_remove(uint32_t classid, app_lookup = context.app_value; if (!app_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", pid); return STC_ERROR_NO_DATA; } } else { app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (!app_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid); return STC_ERROR_NO_DATA; } if (g_hash_table_remove(app_lookup->processes, GUINT_TO_POINTER(pid))) { - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { __print_proc_all(app_lookup->processes); STC_LOGD("\033[1;31mProcess removed\033[0;m " "[\033[1;33m%d\033[0;m]", pid); @@ -235,7 +235,7 @@ API stc_error_e stc_monitor_proc_remove(uint32_t classid, g_hash_table_remove(apps, GUINT_TO_POINTER(classid)); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("\033[1;31mApplication removed\033[0;m " "[\033[1;36m%d\033[0;m]", classid); } @@ -259,14 +259,14 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, to != STC_UNKNOWN_CLASSID) { from_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(from)); if (!from_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", from); return STC_ERROR_NO_DATA; } to_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(to)); if (!to_lookup) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", to); return STC_ERROR_NO_DATA; } @@ -274,7 +274,7 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, g_hash_table_foreach(from_lookup->processes, __proc_move_pid, to_lookup); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { __print_proc_all(to_lookup->processes); STC_LOGD("\033[1;34mProcesses moved\033[0;m " "[\033[1;36m%d\033[0;m] -> [\033[1;36m%d\033[0;m]", @@ -283,7 +283,7 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, g_hash_table_remove_all(from_lookup->processes); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_STAT_LOG) { __print_proc_all(from_lookup->processes); STC_LOGD("\033[1;31mProcesses removed\033[0;m " "[\033[1;36m%d\033[0;m]", from); @@ -303,7 +303,7 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, g_hash_table_remove(apps, GUINT_TO_POINTER(from)); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_STAT_LOG) STC_LOGD("\033[1;31mApplication removed\033[0;m " "[\033[1;36m%d\033[0;m]", from); } diff --git a/src/monitor/stc-monitor-rstn.c b/src/monitor/stc-monitor-rstn.c old mode 100644 new mode 100755 index f28de3c..31a05ab --- a/src/monitor/stc-monitor-rstn.c +++ b/src/monitor/stc-monitor-rstn.c @@ -557,7 +557,7 @@ static void __rstn_process(enum traffic_restriction_type rstn_type, rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter + stat.weekly_stat; rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter + stat.daily_stat; - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGD("Rstn counter data[%lld] warn[%lld] " "monthly[%lld] weekly[%lld] daily[%lld]", rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA], @@ -591,7 +591,7 @@ static void __rstn_process(enum traffic_restriction_type rstn_type, rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED; - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_RSTN_LOG) { STC_LOGD("Restriction activated " "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]", rstn_data->classid, rstn_data->restriction_id); @@ -606,7 +606,7 @@ static void __rstn_process(enum traffic_restriction_type rstn_type, rstn_data->limit_exceeded = 0; rstn_data->limit_notified = 0; - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_RSTN_LOG) { STC_LOGD("Restriction activated " "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]", rstn_data->classid, rstn_data->restriction_id); @@ -633,7 +633,7 @@ static void __rstn_process(enum traffic_restriction_type rstn_type, __rstn_set_noti_state(STC_RSTN_STATE_UNSET); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_RSTN_LOG) { STC_LOGD("Restriction deactivated " "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]", rstn_data->classid, rstn_data->restriction_id); @@ -651,7 +651,7 @@ static void __rstn_add(gpointer data, gpointer user_data) /* rstn rule is activated */ if (rstn_data->rstn_state == STC_RSTN_STATE_ACTIVATED) { - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_RSTN_LOG) { STC_LOGD("Restriction already activated " "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]", rstn_data->classid, rstn_data->restriction_id); @@ -671,7 +671,7 @@ static void __rstn_add(gpointer data, gpointer user_data) rstn_data->app_id, rstn_data, user_data); } - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_RSTN_LOG) { __print_rstn(rstn_data); STC_LOGD("\033[1;32mRestriction added\033[0;m " "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]", @@ -703,7 +703,7 @@ static void __rstn_remove(gpointer data, gpointer user_data) __rstn_tethering_process(RST_UNSET, rstn_data->app_id, rstn_data, user_data); - if (STC_DEBUG_LOG) { + if (STC_DEBUG_LOG && STC_RSTN_LOG) { __print_rstn(rstn_data); STC_LOGD("\033[1;31mRestriction removed\033[0;m " "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]", @@ -782,7 +782,7 @@ static stc_error_e __rstn_data_remove(stc_rstn_data_s *data) lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(data->classid)); if (!lookup_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGE("Restriction not found [\033[1;36m%d\033[0;m]", data->classid); return STC_ERROR_NO_DATA; @@ -791,7 +791,7 @@ static stc_error_e __rstn_data_remove(stc_rstn_data_s *data) lookup_list = g_slist_find_custom(lookup_value->rules, data, __rstn_data_comp); if (!lookup_list) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGE("Restriction not found [%d:%s:%s:%d]", data->iftype, data->ifname, data->subscriber_id, data->roaming); @@ -827,7 +827,7 @@ static stc_error_e __rstn_data_add(stc_rstn_data_s *data) rstn_data = MALLOC0(stc_rstn_data_s, 1); if (!rstn_data) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGE("Rstn_data allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -836,7 +836,7 @@ static stc_error_e __rstn_data_add(stc_rstn_data_s *data) if (!lookup_value) { rstn_value = MALLOC0(stc_rstn_value_s, 1); if (!rstn_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGE("Rstn_value allocation failed"); FREE(rstn_data); return STC_ERROR_OUT_OF_MEMORY; @@ -1303,7 +1303,7 @@ void stc_monitor_rstn_action_when_limit_exceeded(stc_rstn_limit_type_e limit_typ stc_plugin_appstatus_send_message(net_popup_content, net_popup_type, rstn_data->app_id, iftype, byte); - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGD("Limit exceeded [\033[0;31m%s\033[0;m:%d]", net_popup_content, limit_type); } @@ -1381,7 +1381,7 @@ void stc_monitor_rstn_add_for_app(uint32_t classid) lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid)); if (!lookup_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGD("Restriction not found [\033[1;36m%d\033[0;m]", classid); return; @@ -1432,7 +1432,7 @@ void stc_monitor_rstn_remove_for_app(uint32_t classid) lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid)); if (!lookup_value) { - if (STC_DEBUG_LOG) + if (STC_DEBUG_LOG && STC_RSTN_LOG) STC_LOGD("Restriction not found [\033[1;36m%d\033[0;m]", classid); return; diff --git a/src/stc-firewall.c b/src/stc-firewall.c old mode 100644 new mode 100755 index 2a1799c..f1adadb --- a/src/stc-firewall.c +++ b/src/stc-firewall.c @@ -207,8 +207,10 @@ static void __fw_rule_make_key(firewall_rule_s *rule, info->identifier = g_strdup(rule->identifier); info->key = rule->key; - STC_LOGD("Identifier [%s]", rule->identifier); - STC_LOGD("Key [%u]", rule->key); + if (STC_DEBUG_LOG && STC_FW_LOG) { + STC_LOGD("Identifier [%s]", rule->identifier); + STC_LOGD("Key [%u]", rule->key); + } } static void __fw_rule_free(void *data) @@ -257,13 +259,15 @@ static stc_error_e __fw_chain_add(const char *chain) lookup = g_hash_table_lookup(g_firewalls, chain); if (lookup) { - STC_LOGD("chain already present"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGD("chain already present"); return STC_ERROR_ALREADY_DATA; } data = MALLOC0(stc_fw_data_s, 1); if (!data) { - STC_LOGE("data allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("data allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -286,12 +290,14 @@ static stc_error_e __fw_chain_remove(const char *chain) lookup = g_hash_table_lookup(g_firewalls, chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } if (lookup->target != STC_FW_CHAIN_TARGET_NONE) { - STC_LOGE("can't be applied bcz chain is set"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("can't be applied bcz chain is set"); return STC_ERROR_INVALID_PARAMETER; } @@ -313,12 +319,14 @@ static stc_error_e __fw_chain_flush(const char *chain) lookup = g_hash_table_lookup(g_firewalls, chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } if (lookup->target != STC_FW_CHAIN_TARGET_NONE) { - STC_LOGE("can't be applied bcz chain is set"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("can't be applied bcz chain is set"); return STC_ERROR_INVALID_PARAMETER; } @@ -338,7 +346,8 @@ static stc_error_e __fw_chain_set(const char *chain, stc_fw_data_s value) lookup = g_hash_table_lookup(g_firewalls, chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } @@ -357,7 +366,8 @@ static stc_fw_data_s *__fw_chain_get(const char *chain) lookup = g_hash_table_lookup(g_firewalls, chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return NULL; } @@ -375,7 +385,8 @@ static stc_error_e __fw_chain_unset(const char *chain) lookup = g_hash_table_lookup(g_firewalls, chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } @@ -747,7 +758,8 @@ stc_cb_ret_e __fw_table_chain_info_cb(const firewall_chain_s *info, data = MALLOC0(stc_fw_data_s, 1); if (!data) { - STC_LOGE("data allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("data allocation failed"); return STC_CONTINUE; } @@ -768,13 +780,15 @@ stc_cb_ret_e __fw_table_rule_info_cb(const firewall_rule_s *info, lookup = g_hash_table_lookup(g_firewalls, info->chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_CONTINUE; } rule = MALLOC0(firewall_rule_s, 1); if (!rule) { - STC_LOGE("rule allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("rule allocation failed"); return STC_CONTINUE; } @@ -798,18 +812,21 @@ static stc_error_e __fw_rule_add(firewall_rule_s *info) lookup = g_hash_table_lookup(g_firewalls, info->chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } if (lookup->target != STC_FW_CHAIN_TARGET_NONE) { - STC_LOGE("can't be applied bcz chain is set"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("can't be applied bcz chain is set"); return STC_ERROR_INVALID_PARAMETER; } rule = MALLOC0(firewall_rule_s, 1); if (!rule) { - STC_LOGE("rule allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("rule allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -819,7 +836,8 @@ static stc_error_e __fw_rule_add(firewall_rule_s *info) comp = g_slist_find_custom(lookup->rules, rule, __fw_rule_comp); if (comp) { - STC_LOGD("rule already present"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGD("rule already present"); __fw_rule_free(rule); return STC_ERROR_ALREADY_DATA; } @@ -842,19 +860,22 @@ static stc_error_e __fw_rule_remove(const firewall_rule_s *info) lookup = g_hash_table_lookup(g_firewalls, info->chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } if (lookup->target != STC_FW_CHAIN_TARGET_NONE) { - STC_LOGE("can't be applied bcz chain is set"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("can't be applied bcz chain is set"); return STC_ERROR_INVALID_PARAMETER; } rule_list = lookup->rules; comp = g_slist_find_custom(rule_list, info, __fw_rule_comp); if (!comp) { - STC_LOGD("rule not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGD("rule not found"); return STC_ERROR_NO_DATA; } @@ -879,19 +900,22 @@ static stc_error_e __fw_rule_update(firewall_rule_s *info) lookup = g_hash_table_lookup(g_firewalls, info->chain); if (!lookup) { - STC_LOGE("chain not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain not found"); return STC_ERROR_NO_DATA; } if (lookup->target != STC_FW_CHAIN_TARGET_NONE) { - STC_LOGE("can't be applied bcz chain is set"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("can't be applied bcz chain is set"); return STC_ERROR_INVALID_PARAMETER; } rule_list = lookup->rules; comp = g_slist_find_custom(rule_list, info, __fw_rule_comp); if (!comp) { - STC_LOGD("rule not found"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGD("rule not found"); return STC_ERROR_NO_DATA; } @@ -899,7 +923,8 @@ static stc_error_e __fw_rule_update(firewall_rule_s *info) update_rule = MALLOC0(firewall_rule_s, 1); if (!update_rule) { - STC_LOGE("rule allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("rule allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -909,7 +934,8 @@ static stc_error_e __fw_rule_update(firewall_rule_s *info) comp = g_slist_find_custom(lookup->rules, update_rule, __fw_rule_comp); if (comp) { - STC_LOGD("rule already present"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGD("rule already present"); __fw_rule_free(update_rule); return STC_ERROR_ALREADY_DATA; } @@ -1518,7 +1544,8 @@ gboolean handle_firewall_unset_chain(StcFirewall *object, } if (lookup->target == STC_FW_CHAIN_TARGET_NONE) { - STC_LOGE("chain is not set"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("chain is not set"); STC_FIREWALL_DBUS_REPLY_ERROR(invocation, STC_ERROR_INVALID_PARAMETER); __STC_LOG_FUNC_EXIT__; @@ -1575,7 +1602,8 @@ gboolean handle_firewall_add_rule(StcFirewall *object, rule = MALLOC0(firewall_rule_s, 1); if (!rule) { - STC_LOGE("rule allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("rule allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -1627,7 +1655,8 @@ gboolean handle_firewall_remove_rule(StcFirewall *object, rule = MALLOC0(firewall_rule_s, 1); if (!rule) { - STC_LOGE("rule allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("rule allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -1680,7 +1709,8 @@ gboolean handle_firewall_update_rule(StcFirewall *object, rule = MALLOC0(firewall_rule_s, 1); if (!rule) { - STC_LOGE("rule allocation failed"); + if (STC_DEBUG_LOG && STC_FW_LOG) + STC_LOGE("rule allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } diff --git a/src/stc-manager-util.c b/src/stc-manager-util.c old mode 100644 new mode 100755 index 51dbd4f..1f25927 --- a/src/stc-manager-util.c +++ b/src/stc-manager-util.c @@ -16,7 +16,18 @@ #include "stc-manager-util.h" -static int g_debuglog = -1; +typedef struct { + int state; + char *key; +} log_info_s; + +log_info_s g_log_info[] = { + {-1, INFO_DEBUG_LOG}, + {-1, INFO_STAT_LOG}, + {-1, INFO_RSTN_LOG}, + {-1, INFO_FW_LOG}, + {-1, INFO_PCAP_LOG}, +}; static void __sync_file_to_disk(const char *path) { @@ -128,31 +139,46 @@ int stc_util_get_config_int(char *key) } //LCOV_EXCL_START -API void stc_util_set_debuglog(int debuglog) +API void stc_util_update_log_state(void) { - g_debuglog = debuglog; + int i; + + for (i = DEBUG_LOG_INFO; i < MAX_LOG_INFO; ++i) + g_log_info[i].state = stc_util_get_config_int(g_log_info[i].key); + + STC_LOGD("log info [%d:%d:%d:%d:%d]", + g_log_info[DEBUG_LOG_INFO].state, g_log_info[STAT_LOG_INFO].state, + g_log_info[RSTN_LOG_INFO].state, g_log_info[FW_LOG_INFO].state, + g_log_info[PCAP_LOG_INFO].state); +} + +API void stc_util_set_log_state(log_info_e info, int state) +{ + g_log_info[info].state = state; } //LCOV_EXCL_STOP -API int stc_util_get_debuglog(void) +API int stc_util_get_log_state(log_info_e info) { - if (g_debuglog == -1) - g_debuglog = stc_util_get_config_int(INFO_DEBUGLOG); + if (g_log_info[info].state == -1) + g_log_info[info].state = stc_util_get_config_int(g_log_info[info].key); - return g_debuglog; + return g_log_info[info].state; } void stc_util_initialize_config(void) { char path[MAX_PATH_LENGTH]; GKeyFile *keyfile; + int i; snprintf(path, sizeof(path), "%s/%s", INFO_STORAGE_DIR, INFO_CONFIG); keyfile = __load_key_file(path); if (!keyfile) { keyfile = g_key_file_new(); //LCOV_EXCL_LINE - g_key_file_set_integer(keyfile, path, INFO_DEBUGLOG, 0); + for (i = DEBUG_LOG_INFO; i < MAX_LOG_INFO; ++i) + g_key_file_set_integer(keyfile, path, g_log_info[i].key, 0); } __save_key_file(keyfile, path); diff --git a/src/stc-manager.c b/src/stc-manager.c index 46401fb..ba9356d 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -62,10 +62,8 @@ static void __stc_inotify_handler(struct inotify_event *event, const char *ident return; } - if (!g_strcmp0(ident, INFO_CONFIG)) { - int debug = stc_util_get_config_int(INFO_DEBUGLOG); - stc_util_set_debuglog(debug); - } + if (!g_strcmp0(ident, INFO_CONFIG)) + stc_util_update_log_state(); } static void __stc_manager_deinit(void)