40 #include<proc/readproc.h>
47 #include "safec_lib.h"
49 GHashTable* hostIf_DeviceProcess::ifHash = NULL;
51 GMutex* hostIf_DeviceProcess::m_mutex = NULL;
53 GMutex* hostIf_DeviceProcess::m_libproc_lock = NULL;
65 bCalledProcessPid =
false;
66 bCalledProcessCommand =
false;
67 bCalledProcessSize =
false;
68 bCalledProcessPriority =
false;
69 bCalledProcessCpuTime =
false;
70 bCalledProcessState =
false;
73 memset(backupProcessCommand,0,_COMMAND_LENGTH);
74 backupProcessSize = 0;
75 backupProcessPriority = 0;
76 backupProcessCpuTime = 0;
77 memset(backupProcessState,0,_STATE_LENGTH);
78 hostIf_DeviceProcess::initProcpsLock();
82 GMutex* hostIf_DeviceProcess::initProcpsLock()
84 #if GLIB_VERSION_CUR_STABLE <= GLIB_VERSION_2_32
85 if(!g_thread_supported())
90 if( NULL == m_libproc_lock )
91 m_libproc_lock = g_mutex_new();
92 return m_libproc_lock;
102 if( NULL == m_libproc_lock )
103 g_mutex_free(m_libproc_lock);
116 ifHash = g_hash_table_new(NULL,NULL);
125 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create MoCA Interface instance..\n");
127 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
132 GList* hostIf_DeviceProcess::getAllInstances()
135 return g_hash_table_get_keys(ifHash);
143 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
148 void hostIf_DeviceProcess::closeAllInstances()
152 GList* tmp_list = g_hash_table_get_values (ifHash);
157 tmp_list = tmp_list->next;
163 void hostIf_DeviceProcess::getLock()
167 m_mutex = g_mutex_new();
169 g_mutex_lock(m_mutex);
172 void hostIf_DeviceProcess::releaseLock()
174 g_mutex_unlock(m_mutex);
187 hostIf_DeviceProcess::initProcpsLock();
188 g_mutex_lock(m_libproc_lock);
189 int iTotalNumOfProcess = 0;
191 PROCTAB *pProcTab = NULL;
197 pProcTab = openproc(PROC_FILLMEM);
200 if (pProcTab == NULL)
202 g_mutex_unlock(m_libproc_lock);
206 while ((task = readproc(pProcTab, NULL)) != NULL)
208 iTotalNumOfProcess++;
213 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"%s: Current Process Count: [%u]\n", __FUNCTION__, iTotalNumOfProcess);
216 stMsgData->
paramtype = hostIf_UnsignedIntType;
217 g_mutex_unlock(m_libproc_lock);
234 PROCTAB *pProcTab = NULL;
237 errno_t safec_rc = -1;
239 if(NULL == (pProcTab = openproc(PROC_FILLSTAT | PROC_FILLMEM)))
241 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Failed in openproc(), returned NULL. \n",__FILE__,__FUNCTION__,__LINE__);
246 for (iProcEntry = 0; iProcEntry < iProcInstanceNum; iProcEntry++)
248 memset(&procTask, 0,
sizeof(procTask));
250 if(!pProcTab->finder(pProcTab,&procTask))
252 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d : No Entry Found In Process Profile Table\n",iProcInstanceNum);
253 memset(&processStatus, 0,
sizeof(processStatus));
260 pProcTab->reader(pProcTab,&procTask);
265 processStatus.uiPid = (
unsigned int)procTask.tid;
266 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d Pid: %d\n",iProcInstanceNum, procTask.tid);
268 case eProcessCommand:
269 memset(processStatus.cCommand,
'\0',_COMMAND_LENGTH);
270 safec_rc=strcpy_s(processStatus.cCommand,
sizeof(processStatus.cCommand) ,procTask.cmd);
275 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d Command: %s\n",iProcInstanceNum, procTask.cmd);
278 memset(processStatus.cState,
'\0',_STATE_LENGTH);
279 switch(procTask.state)
282 safec_rc=strcpy_s(processStatus.cState,
sizeof(processStatus.cState) ,PROCESS_STATE_RUNNING);
289 safec_rc=strcpy_s(processStatus.cState,
sizeof(processStatus.cState) ,PROCESS_STATE_SLEEPING);
296 safec_rc=strcpy_s(processStatus.cState,
sizeof(processStatus.cState) ,PROCESS_STATE_STOPPED);
303 safec_rc=strcpy_s(processStatus.cState,
sizeof(processStatus.cState) ,PROCESS_STATE_ZOMBIE);
312 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d State: %c\n",iProcInstanceNum, procTask.state);
314 case eProcessPriority:
315 processStatus.uiPriority = (
unsigned int)procTask.priority;
316 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d Priority: %5ld\n",iProcInstanceNum, procTask.priority);
319 processStatus.uiSize = (
unsigned int)(procTask.size*4);
320 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d Size: %5ld\n",iProcInstanceNum, procTask.size*4);
322 case eProcessCpuTime:
323 processStatus.uiCpuTime = (
unsigned int)(procTask.utime+procTask.stime);
324 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"ProcessInstance: %d CPU Time: %5lld\n",iProcInstanceNum, procTask.utime+procTask.stime);
344 int iProcessInstance = 0;
345 const char *pSetting;
346 if(!matchComponent(name,
"Device.DeviceInfo.ProcessStatus.Process",&pSetting,iProcessInstance))
377 g_mutex_lock(m_libproc_lock);
380 g_mutex_unlock(m_libproc_lock);
383 if(bCalledProcessPid && pChanged && (backupProcessPid != processStatus.uiPid))
387 bCalledProcessPid =
true;
388 backupProcessPid = processStatus.uiPid;
391 stMsgData->
paramtype = hostIf_UnsignedIntType;
392 g_mutex_unlock(m_libproc_lock);
411 g_mutex_lock(m_libproc_lock);
414 g_mutex_unlock(m_libproc_lock);
417 rc=strcpy_s(backupProcessCommand,
sizeof(backupProcessCommand),processStatus.cCommand);
423 if(bCalledProcessCommand && pChanged && (!rc))
427 bCalledProcessCommand =
true;
428 rc=strcpy_s(backupProcessCommand,
sizeof(backupProcessCommand),processStatus.cCommand);
440 g_mutex_unlock(m_libproc_lock);
458 g_mutex_lock(m_libproc_lock);
461 g_mutex_unlock(m_libproc_lock);
464 if(bCalledProcessSize && pChanged && (backupProcessSize != processStatus.uiSize))
468 bCalledProcessSize =
true;
469 backupProcessSize = processStatus.uiSize;
472 stMsgData->
paramtype = hostIf_UnsignedIntType;
473 g_mutex_unlock(m_libproc_lock);
491 g_mutex_lock(m_libproc_lock);
494 g_mutex_unlock(m_libproc_lock);
497 if(bCalledProcessPriority && pChanged && (backupProcessPriority != processStatus.uiPriority))
501 bCalledProcessPriority =
true;
502 backupProcessPriority = processStatus.uiPriority;
505 stMsgData->
paramtype = hostIf_UnsignedIntType;
506 g_mutex_unlock(m_libproc_lock);
524 g_mutex_lock(m_libproc_lock);
527 g_mutex_unlock(m_libproc_lock);
530 if(bCalledProcessCpuTime && pChanged && (backupProcessCpuTime != processStatus.uiCpuTime))
534 bCalledProcessCpuTime =
true;
535 backupProcessCpuTime = processStatus.uiCpuTime;
538 stMsgData->
paramtype = hostIf_UnsignedIntType;
539 g_mutex_unlock(m_libproc_lock);
557 g_mutex_lock(m_libproc_lock);
561 g_mutex_unlock(m_libproc_lock);
564 rc=strcpy_s(backupProcessState,
sizeof(backupProcessState),processStatus.cState);
570 if(bCalledProcessState && pChanged && (!rc))
574 bCalledProcessState =
true;
575 rc=strcpy_s(backupProcessState,
sizeof(backupProcessState),processStatus.cState);
587 g_mutex_unlock(m_libproc_lock);