int clear_old_files( void )
{
int i,index,len,current_start,cnt;
char buffer [RESULT_MAX_BUFF_SIZE];
char cmd_str[RESULT_MAX_BUFF_SIZE];
char name[128];
//strcpy( cmd_str, "busybox ls -t /data/system_log/ | sed -n \'6,$p\' |xargs rm -rf" );
strcpy( cmd_str, "busybox ls -t /data/system_log/ | sed -n '4,$p'" );
debug_msg( "cmd_str = %s\n", cmd_str );
exec_cmd_and_get_result(cmd_str, buffer);
macdbg_dmphex(buffer, 100);
debug_msg( "buffer len = %d\n", strlen(buffer) );
len = strlen(buffer);
index = 0x00;
while(1){
current_start = index;
cnt = 0x00;
memset( name, 0x00, sizeof(name) );
while(1){
if( buffer[index] != '\n' && buffer[index] != '\0' ){
index++;
cnt++;
}else{
break;
}
}
if( cnt ){
memcpy( name, &buffer[current_start], cnt );
debug_msg( "name = %s\n", name );
index++;
memset( cmd_str, 0x00, sizeof(cmd_str) );
strcpy( cmd_str, "rm -f /data/system_log/" );
strcat( cmd_str, name );
system( cmd_str );
}else{
break;
}
}
return 0;
}
#define RESULT_MAX_BUFF_SIZE 4096
int exec_cmd_and_get_result( const char *cmd_str, char *buffer )
{
int cnt;
FILE *pf;
pf = popen(cmd_str, "r");
cnt=fread(buffer, 1,RESULT_MAX_BUFF_SIZE, pf);
buffer[cnt-1] = '\0';
//debug_msg( "fread cnt = %d\n", cnt );
//printf( "strlen(buffer) = %d\n", strlen(buffer) );
//debug_msg( "buffer = %s\n", buffer );
//macdbg_dmphex(buffer, cnt);
pclose(pf);
return 0;
}
int debug_msg(const char *format, ...)
{
//char tmpbuf[4096];
unsigned int send_len;
char * tmpbuf = malloc(8192);
if( tmpbuf == NULL ){
return -1;
}
va_list vArgs;
va_start(vArgs, format);
vsnprintf( (char *)&tmpbuf[0], 8192, (char const *)format, vArgs );
va_end(vArgs);
send_len = strlen(&tmpbuf[0]);
__android_log_write( ANDROID_LOG_DEBUG, TAG, tmpbuf );
if( tmpbuf != NULL ){
free(tmpbuf);
}
return 0;
}
u8 g_debug_buff[256];
int g_debug_buff_index;
#define macdbg_prser Ser_Printf
//#define Ser_WrStr do{ LOGI("%s", buffer); }while(0)
int g_printf_switch = 0x01;
int Ser_Printf (const char *format, ...)
{
unsigned char buffer[80 + 1];
va_list vArgs;
if( g_printf_switch == 0x00 ){
return 1;
}
va_start(vArgs, format);
vsnprintf((char *)buffer, sizeof(buffer), (char const *)format, vArgs);
va_end(vArgs);
//Ser_WrStr;
strcpy( &g_debug_buff[g_debug_buff_index], buffer );
g_debug_buff_index = g_debug_buff_index + strlen(buffer);
return 0;
}
int macdbg_dmphex(const char* buff, int len)
{
int retval = 0;
int x, y, tot, lineoff;
const char* curr;
lineoff = 0;
curr = buff;
tot = 0;
for( x = 0; len > x+16; ){
macdbg_prser("0x%08x: ", lineoff);
for( y = 0; y < 16; y++ ){
macdbg_prser("%02x ", (unsigned char)*(curr + y));
}
macdbg_prser(" ");
for( y = 0; y < 16; y++ ){
char c;
c = *(curr + y);
if( c > 31 && c < 127 ){
macdbg_prser("%c", c);
}else{
macdbg_prser("%c", '.');
}
tot++;
}
curr += 16;
x += 16;
lineoff+=16;
//syslog( LOG_INFO, "%s", g_debug_buff );
debug_msg( "%s\n", g_debug_buff );
memset( &g_debug_buff[0x00], 0x00, sizeof(g_debug_buff) );
g_debug_buff_index = 0x00;
}
//do last line
//Ser_Printf("tot %d.\r\n", tot );
//Ser_Printf("len %d.\r\n", len );
if( tot < len ){
curr = (buff + tot);
macdbg_prser("0x%08x: ", lineoff);
for( y = 0; y < (len - tot); y++ ){
macdbg_prser("%02x ", (unsigned char)*(curr + y));
}
//padding with spaces
//Ser_Printf("(len - tot) %d.\r\n", (len - tot) );
if( (len - tot) < 16 ){
for( y = 0; y < (32 - ((len - tot)*2)); y++ ){
macdbg_prser(" ");
}
}
for( y = 0; y < 16-(len - tot); y++ ){
macdbg_prser(" ");
}
macdbg_prser(" ");
//Ser_Printf("(len - tot) %d.\r\n", (len - tot) );
for( y = 0; y < (len - tot); y++ ){
char c;
c = *(curr + y);
if( c >31 && c < 127 ){
macdbg_prser("%c", c);
}else{
macdbg_prser("%c", '.');
}
}
}
// syslog( LOG_INFO, "%s", g_debug_buff );
debug_msg( "%s\n", g_debug_buff );
memset( &g_debug_buff[0x00], 0x00, sizeof(g_debug_buff) );
g_debug_buff_index = 0x00;
return retval;
}