6 #include <netinet/in.h>
8 #include <sys/socket.h>
10 #include <arpa/inet.h>
12 #include "rdk_dynamic_logger.h"
14 #define COMP_SIGNATURE "LOG.RDK."
15 #define COMP_SIGNATURE_LEN 8
17 #define DL_SIGNATURE "COMC"
18 #define DL_SIGNATURE_LEN 4
20 static void usage(
const char* app_name)
22 printf(
"usage: %s <app_name> <module_name> <loglevel> \n",app_name);
23 printf(
"Parameters:\n");
24 printf(
"app_name -> Application name, as per listed by 'ps' command\n");
25 printf(
"module_name -> Module name.\n");
26 printf(
" For RDK component, the 'Module name' is expected to start with 'LOG.RDK.' string\n");
27 printf(
" For CPC component like 'Reciever', the module name can be either 'LOG.RDK.' or 'XREConnection', 'RmfMediaPlayer', etc.\n");
28 printf(
"loglevel -> Log Level of the Component to be modified\n");
29 printf(
" Possible values - FATAL,ERROR,WARN,NOTICE,INFO,DEBUG,TRACE1-TRACE9\n");
30 printf(
" Turn off any loglevel using '~' symbol.\n");
31 printf(
" (i.e) '~ERROR' would turn off error logs alone for that component\n");
34 static char validate_loglevel(
const char* level)
36 char *loglevel = (
char *)level;
39 if(loglevel[0] ==
'~') {
44 if(0 == strncmp(loglevel,
"FATAL",5))
45 return negate|RDK_LOG_FATAL;
46 else if(0 == strncmp(loglevel,
"ERROR",5))
47 return negate|RDK_LOG_ERROR;
48 else if(0 == strncmp(loglevel,
"WARN",4))
49 return negate|RDK_LOG_WARN;
50 else if(0 == strncmp(loglevel,
"NOTICE",6))
51 return negate|RDK_LOG_NOTICE;
52 else if(0 == strncmp(loglevel,
"INFO",4))
53 return negate|RDK_LOG_INFO;
54 else if(0 == strncmp(loglevel,
"DEBUG",5))
55 return negate|RDK_LOG_DEBUG;
56 else if(0 == strncmp(loglevel,
"TRACE1",6))
57 return negate|RDK_LOG_TRACE1;
58 else if(0 == strncmp(loglevel,
"TRACE2",6))
59 return negate|RDK_LOG_TRACE2;
60 else if(0 == strncmp(loglevel,
"TRACE3",6))
61 return negate|RDK_LOG_TRACE3;
62 else if(0 == strncmp(loglevel,
"TRACE4",6))
63 return negate|RDK_LOG_TRACE4;
64 else if(0 == strncmp(loglevel,
"TRACE5",6))
65 return negate|RDK_LOG_TRACE5;
66 else if(0 == strncmp(loglevel,
"TRACE6",6))
67 return negate|RDK_LOG_TRACE6;
68 else if(0 == strncmp(loglevel,
"TRACE7",6))
69 return negate|RDK_LOG_TRACE7;
70 else if(0 == strncmp(loglevel,
"TRACE8",6))
71 return negate|RDK_LOG_TRACE8;
72 else if(0 == strncmp(loglevel,
"TRACE9",6))
73 return negate|RDK_LOG_TRACE9;
75 return ENUM_RDK_LOG_COUNT;
78 static int validate_module_name(
const char *name)
82 char comp_name[128] = {0};
85 fp = fopen(
"/etc/debug.ini",
"r");
90 ch = fscanf(fp,
"%s", comp_name);
91 if(strstr(comp_name,name)) {
101 int main(
int argc,
char *argv[])
103 struct sockaddr_in dest_addr;
104 int i, sockfd, numbytes, addr_len, app_len, comp_len, optval = 1;
106 unsigned char buf[128] = {0};
113 if(0 != strcmp(
"Receiver",argv[1])) {
114 if( (0 != strncmp(argv[2],COMP_SIGNATURE,COMP_SIGNATURE_LEN)) ||
115 (0 != validate_module_name(argv[2])) ) {
116 printf(
"Invalid module name\n");
122 level = validate_loglevel(argv[3]);
123 if(ENUM_RDK_LOG_COUNT == level) {
124 printf(
"Invalid log level\n");
129 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
130 printf(
"socket: %s\n",strerror(errno));
134 if(setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,(
char *) &optval,
sizeof(optval))){
135 printf(
"Error setting socket to BROADCAST mode %s\n",strerror(errno));
139 memset(&dest_addr,0,
sizeof(dest_addr));
140 dest_addr.sin_family = AF_INET;
141 dest_addr.sin_port=htons((
unsigned short) DL_PORT);
142 dest_addr.sin_addr.s_addr=inet_addr(
"127.255.255.255");
145 i = DL_SIGNATURE_LEN;
146 memcpy(buf,DL_SIGNATURE,i);
149 buf[++i] = (
unsigned char)level;
152 app_len = strlen(argv[1]);
156 memcpy(buf+(++i),argv[1],app_len);
159 comp_len = strlen(argv[2]);
164 memcpy(buf+(++i),argv[2],comp_len);
171 buf[4] = app_len + comp_len + 3;
177 #define DL_PACKET_LEN buf[4]+DL_SIGNATURE_LEN+1
179 if ((numbytes=sendto(sockfd, buf, DL_PACKET_LEN, 0, (
struct sockaddr *)&dest_addr,
sizeof(
struct sockaddr))) == -1) {
180 printf(
"sendto: %s\n",strerror(errno));
184 printf(
"Sent message to update log level of %s for %s process\n", argv[2], argv[1]);