Fix system issues
[platform/framework/native/appfw.git] / src / system / FSys_RuntimeInfoImpl.cpp
index 73e8c23..2137e7c 100644 (file)
@@ -35,6 +35,7 @@
 #include <runtime_info.h>
 #include <vconf.h>
 
+#include <FAppApp.h>
 #include <FBaseRtEvent.h>
 #include <FBaseRtIEventArg.h>
 #include <FBaseRtIEventListener.h>
@@ -351,22 +352,62 @@ _RuntimeInfoImpl::GetDirectorySize(const char* path)
        }
 
        char command[512] = {0,};
+       char fileName[512] = {0,};
        long long size = 0;
        int ret = 0;
 
-       sprintf(command, "du -sk -P %s >> /tmp/size_of_directory.tmp", path);
+       Tizen::App::App* pApp = Tizen::App::App::GetInstance();
+       if(pApp == null)
+       {
+               return 0;
+       }
+
+       String appId(pApp->GetAppId());
+       unique_ptr <char> appIdPath(_StringConverter::CopyToCharArrayN(appId));
+
+       ret = sprintf(fileName, "/tmp/size_of_directory_%s.tmp", appIdPath.get());
+       if(ret < 1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write file path.");
+               return 0;
+       }
+
+       ret = sprintf(command, "rm -rf %s", fileName);
+       if(ret < 1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write remove command.");
+               return 0;
+       }
+
+       ret = system(command);
 
-       system("rm -rf /tmp/size_of_directory.tmp");
-       system(command);
+       if(ret == -1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+       }
+
+       ret = sprintf(command, "du -skb -P %s >> %s", path, fileName);
+       if(ret < 1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write du command.");
+               return 0;
+       }
+
+       ret = system(command);
+       if(ret == -1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+               return 0;
+       }
 
        FILE* pFile = null;
-       pFile = fopen("/tmp/size_of_directory.tmp", "r");
+       pFile = fopen(fileName, "r");
        if(pFile == null)
        {
                return 0;
        }
-       ret = fscanf(pFile, "%lld", &size);
 
+       ret = fscanf(pFile, "%lld", &size);
        if(ret < 1)
        {
                if(pFile != null)
@@ -381,7 +422,21 @@ _RuntimeInfoImpl::GetDirectorySize(const char* path)
        {
                fclose(pFile);
        }
-       system("rm -rf /tmp/size_of_directory.tmp");
+
+       ret = sprintf(command, "rm -rf %s", fileName);
+       if(ret < 1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to write remove command.");
+               return 0;
+       }
+
+       ret = system(command);
+       if(ret == -1)
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "It is failed to execute command[%s].", command);
+       }
+
+
        return size;
 }
 
@@ -632,8 +687,7 @@ _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetIntAsyncResult
        {
                if(listener != null)
                {
-                       SysLog(NID_SYS, "%x", listener);
-                       runtimeInfoEvent.AddListener(*listener, false);
+                       runtimeInfoEvent.AddListener(*listener);
                }
 
                int thr_id = 0;
@@ -714,7 +768,7 @@ _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetLonglongAsyncR
        {
                if(listener != null)
                {
-                       SysLog(NID_SYS, "test %x", listener);
+                       SysLog(NID_SYS, "listener instance is %x.", listener);
                        runtimeInfoEvent.AddListener(*listener);
                }
 
@@ -723,7 +777,7 @@ _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetLonglongAsyncR
                pEventArg->DirectoryPath = directoryPath;
 
                thr_id = pthread_create(&p_thread, null, GetDirectorySizeAsync, pEventArg);
-               SysLog(NID_SYS, "%d", thr_id);
+               SysLog(NID_SYS, "Thread id is %d.", thr_id);
                pthread_detach(p_thread);
        }