Replace strerror_r() to '%m'. 43/107643/7
authorKichan Kwon <k_c.kwon@samsung.com>
Thu, 29 Dec 2016 02:44:59 +0000 (11:44 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 18 Jan 2017 01:31:07 +0000 (10:31 +0900)
- strerror_r() always need additional buffer
- We don't have to declare buffer by using '%m'

Change-Id: I326a306d15b1d74360b4264ff99024b5b7a6fb43
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
12 files changed:
src/common/cgroup.c
src/common/const.h
src/common/procfs.c
src/common/trace.h
src/heart/heart-memory.c
src/mem-stress/mem-stress.c
src/proc-stat/proc-main.c
src/proc-stat/proc-monitor.c
src/resourced/init.c
src/swap/swap.c
src/vip-agent/vip-process.c
src/vip-agent/vip-release-agent.c

index 59a7f6292c6f2b8f7ce1239b7eed803bd86b6af1..890b8f40f61fa5cf4b1a213397887824be86cc23 100644 (file)
@@ -69,9 +69,8 @@ resourced_ret_c cgroup_write_pid_fullpath(const char *cgroup_full_path,
        const int pid)
 {
        int ret;
-       char buf[ERR_BUF_SIZE];
 
-       if (pid <=0) {
+       if (pid <= 0) {
                _E("try to write empty pid to %s", cgroup_full_path);
                return RESOURCED_ERROR_NO_DATA;
        }
@@ -80,8 +79,8 @@ resourced_ret_c cgroup_write_pid_fullpath(const char *cgroup_full_path,
                (u_int32_t)pid);
 
        ret_value_msg_if(ret < 0, RESOURCED_ERROR_FAIL,
-               "Failed place all pid to cgroup %s, error %s",
-                       cgroup_full_path, strerror_r(errno, buf, ERR_BUF_SIZE));
+               "Failed place all pid to cgroup %s : %m",
+                        cgroup_full_path);
        return RESOURCED_ERROR_NONE;
 }
 
index bb5e586d8f371e06459a2b4060405362cd905cdd..d4c935936d5f3d0cc8f55eb3d33c0965dce0d539 100644 (file)
@@ -47,8 +47,6 @@
 
 #define TIME_TO_SAFE_DATA 1 /* one second */
 
-#define ERR_BUF_SIZE 256
-
 /*
  * @desc reserved classid enums
  * internal structure, we don't provide it externally
index eaa6756b7cb1626c99a7b41ece824189089e0954..88870d628ed42dd94a8f7150d357cf421f05d99f 100644 (file)
@@ -299,15 +299,13 @@ int proc_get_zram_usage(pid_t pid, unsigned int *usage)
        struct meminfo mi;
        static unsigned int swap_total = 0;
        unsigned int proc_swap_usage, zram_usage;
-       char buf[ERR_BUF_SIZE];
 
        /* Read total swap size just once and cache it */
        if (!swap_total) {
                ret = proc_get_meminfo(&mi, MEMINFO_MASK_SWAP_TOTAL);
                if (ret < 0) {
-                       _E("Failed to get %s: %s",
-                          meminfo_id_to_string(MEMINFO_ID_SWAP_TOTAL),
-                          strerror_r(-ret, buf, ERR_BUF_SIZE));
+                       _E("Failed to get %s: %m",
+                          meminfo_id_to_string(MEMINFO_ID_SWAP_TOTAL));
                        return RESOURCED_ERROR_FAIL;
                }
                swap_total = mi.value[MEMINFO_ID_SWAP_TOTAL];
@@ -361,13 +359,11 @@ unsigned int proc_get_mem_available(void)
 {
        struct meminfo mi;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        ret = proc_get_meminfo(&mi, MEMINFO_MASK_MEM_AVAILABLE);
        if (ret < 0) {
-               _E("Failed to get %s: %s",
-                               meminfo_id_to_string(MEMINFO_ID_MEM_AVAILABLE),
-                               strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to get %s: %m",
+                               meminfo_id_to_string(MEMINFO_ID_MEM_AVAILABLE));
                return 0;
        }
 
@@ -378,13 +374,11 @@ unsigned int proc_get_swap_free(void)
 {
        struct meminfo mi;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        ret = proc_get_meminfo(&mi, MEMINFO_MASK_SWAP_FREE);
        if (ret < 0) {
-               _E("Failed to get %s: %s",
-                  meminfo_id_to_string(MEMINFO_ID_SWAP_FREE),
-                  strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to get %s: %m",
+                  meminfo_id_to_string(MEMINFO_ID_SWAP_FREE));
                return 0;
        }
 
@@ -498,7 +492,6 @@ int proc_get_status(pid_t pid, char *buf, int len)
 int proc_sys_node_trigger(enum sys_node_id sys_node_id)
 {
        FILE *fp = NULL;
-       char buf[ERR_BUF_SIZE];
 
        if (sys_node_id >= ARRAY_SIZE(sys_node_tables)) {
                _E("sys_node_id[%d] is out of range.\n", sys_node_id);
@@ -512,9 +505,8 @@ int proc_sys_node_trigger(enum sys_node_id sys_node_id)
        /* open and check if the path exists, else return fail */
        fp = fopen(sys_node_tables[sys_node_id].path, "w");
        if (fp == NULL) {
-               _E("Failed to open: %s: %s\n",
-                       sys_node_tables[sys_node_id].path,
-                       strerror_r(errno, buf, ERR_BUF_SIZE));
+               _E("Failed to open %s: %m\n",
+                       sys_node_tables[sys_node_id].path);
                sys_node_tables[sys_node_id].valid = 0;
                return RESOURCED_ERROR_FAIL;
        }
index 6ba5790056bc965627b8a181d4dab575957cdc2d..f09b43da847e1dcb281195b79e32a1b3f53f9ddc 100644 (file)
@@ -89,19 +89,19 @@ extern enum log_type logtype;
        sqlite3_free(a); \
 }
 
-#define TRACE_RET_ERRCODE(type, error_code) do { \
-       char buf[ERR_BUF_SIZE]; \
-       _##type("errno %d, errmsg %s", error_code, strerror_r(-error_code, buf, ERR_BUF_SIZE)); \
+#define TRACE_RET_ERRCODE(type, error_code)                    \
+do {                                                           \
+       _##type("errno %d, errmsg %m", error_code); \
 } while (0)
 
 #define DTRACE_RET_ERRCODE(error_code) TRACE_RET_ERRCODE(D, error_code)
 
 #define ETRACE_RET_ERRCODE(error_code) TRACE_RET_ERRCODE(E, error_code)
 
-#define TRACE_RET_ERRCODE_MSG(type, error_code, fmt, arg...) do { \
-       char buf[ERR_BUF_SIZE]; \
-       _##type(fmt, ##arg); \
-       _##type("errno %d, errmsg %s", error_code, strerror_r(-error_code, buf, ERR_BUF_SIZE)); \
+#define TRACE_RET_ERRCODE_MSG(type, error_code, fmt, arg...)   \
+do {                                                           \
+       _##type(fmt, ##arg);                                    \
+       _##type("errno %d, errmsg %m", error_code); \
 } while (0)
 
 #define DTRACE_RET_ERRCODE_MSG(error_code, fmt, arg...) \
index 8f52a952beb198417fb178be6923614e5c1bccc9..07c1eeae8482f5af710cd4ea6e070ff84c62c64d 100644 (file)
@@ -1099,7 +1099,6 @@ static int heart_memory_write(char *appid, char *pkgid, struct proc_status *p_da
        _cleanup_free_ char *info = NULL;
        unsigned int pss = 0, uss = 0;
        int ret;
-       char error_buf[ERR_BUF_SIZE];
 
        /* For write to data crud during period */
        /* write memory usage in proc_list */
@@ -1110,9 +1109,7 @@ static int heart_memory_write(char *appid, char *pkgid, struct proc_status *p_da
                         SMAPS_MASK_PRIVATE_DIRTY |
                         SMAPS_MASK_SWAP));
        if (ret < 0) {
-               _E("Failed to get PID(%d) smaps: %s",
-                  p_data->pid,
-                  strerror_r(-ret, error_buf, ERR_BUF_SIZE));
+               _E("Failed to get PID(%d) smaps: %m", p_data->pid);
                return ret;
        }
 
index 106364e05c895a1aeaa01482d2c9b2a147889f61..f5d7aca6644ae02a30a23ee9fa3ebc932be73e39 100644 (file)
@@ -105,7 +105,6 @@ static int mem_stress_run_loop(void)
 {
        void *mem = NULL;
        int r;
-       char buf[ERR_BUF_SIZE];
 
        fprintf(stdout, "Memory stress size is: %zu", arg_size);
 
@@ -114,7 +113,7 @@ static int mem_stress_run_loop(void)
 
        r = mem_stress_allocate_memory(&mem, arg_size);
        if (r < 0) {
-               fprintf(stderr, "Failed to allocate memory: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
+               fprintf(stderr, "Failed to allocate memory: %m");
                return r;
        }
 
@@ -123,7 +122,7 @@ static int mem_stress_run_loop(void)
 
        r = mem_stress_free_memory(mem, arg_size);
        if (r < 0) {
-               fprintf(stderr, "Failed to free memory: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
+               fprintf(stderr, "Failed to free memory: %m");
                return r;
        }
 
index 7bce57fe74ae29a96ae20d5ffefcf71313d76292..e3388493f4fde8e97a9cb354ebdaa9b04291b8ec 100644 (file)
@@ -89,7 +89,6 @@ GSList *proc_app_list_open(void)
 void proc_app_list_close(void)
 {
        int err;
-       char buf[ERR_BUF_SIZE];
 
        app_list.ref--;
 
@@ -100,8 +99,7 @@ void proc_app_list_close(void)
 
        err = pthread_mutex_unlock(&app_list.lock);
        if (err)
-               _E("Failed to unlock app list mutex: %s",
-                  strerror_r(err, buf, ERR_BUF_SIZE));
+               _E("Failed to unlock app list mutex: %m");
 }
 
 static bool is_ui_app(enum application_type type)
@@ -330,7 +328,6 @@ static void proc_app_info_add_child_pid(struct proc_app_info *pai, pid_t pid)
 {
        _cleanup_free_ char *runtime_app_info_path = NULL;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        assert(pai);
        assert(pid > 0);
@@ -343,15 +340,13 @@ static void proc_app_info_add_child_pid(struct proc_app_info *pai, pid_t pid)
 
        runtime_app_info_path = proc_get_runtime_app_info_path(pai);
        if (!runtime_app_info_path) {
-               _E("Failed to get runtime appinfo path: %s",
-                               strerror_r(ENOMEM, buf, ERR_BUF_SIZE));
+               _E("Failed to get runtime appinfo path: not enough memory");
                return;
        }
 
        ret = proc_runtime_app_info_write_procs(runtime_app_info_path, pai->childs);
        if (ret < 0)
-               _E("Failed to write appinfo children '%s': %s",
-                  runtime_app_info_path, strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to write appinfo children '%s': %m", runtime_app_info_path);
 }
 
 void proc_set_process_memory_state(struct proc_app_info *pai,
@@ -654,14 +649,13 @@ static void proc_app_list_add_app_info(struct proc_app_info *pai)
 {
        _cleanup_app_list_close_ GSList *proc_app_list = PAL_INIT_VALUE;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        if (pai->main_pid <= 0)
                return;
 
        ret = proc_runtime_write_app_info(pai);
        if (ret < 0)
-               _E("Failed to add runtime app info: %s", strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to add runtime app info: %m");
 
        proc_app_list = proc_app_list_open();
        app_list.list = g_slist_prepend(proc_app_list, pai);
@@ -673,12 +667,10 @@ static GSList *proc_app_list_remove_app_info(struct proc_app_info *pai)
 {
        _cleanup_app_list_close_ GSList *proc_app_list = PAL_INIT_VALUE;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        ret = proc_runtime_remove_app_info(pai);
        if (ret < 0)
-               _E("Failed to remove appinfo '%s': %s",
-                  pai->appid, strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to remove appinfo '%s': %m", pai->appid);
 
        proc_app_list = proc_app_list_open();
        app_list.list = g_slist_remove(proc_app_list, pai);
@@ -791,7 +783,6 @@ static void proc_app_info_remove_child_pid(struct proc_app_info *pai, pid_t pid)
 {
        _cleanup_free_ char *runtime_app_info_path = NULL;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        assert(pai);
        assert(pid >= 0);
@@ -801,8 +792,7 @@ static void proc_app_info_remove_child_pid(struct proc_app_info *pai, pid_t pid)
 
        runtime_app_info_path = proc_get_runtime_app_info_path(pai);
        if (!runtime_app_info_path) {
-               _E("Failed to get runtime appinfo path: %s",
-                               strerror_r(ENOMEM, buf, ERR_BUF_SIZE));
+               _E("Failed to get runtime appinfo path: not enough memory");
                return;
        }
 
@@ -818,8 +808,7 @@ static void proc_app_info_remove_child_pid(struct proc_app_info *pai, pid_t pid)
 
        ret = proc_runtime_app_info_write_procs(runtime_app_info_path, pai->childs);
        if (ret < 0)
-               _E("Failed to write appinfo children '%s': %s",
-                  runtime_app_info_path, strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to write appinfo children '%s': %m", runtime_app_info_path);
 
        return;
 
@@ -829,8 +818,7 @@ remove_all:
 
        ret = proc_runtime_app_info_remove_procs(runtime_app_info_path);
        if (ret < 0)
-               _E("Failed to remove appinfo children '%s': %s",
-                  runtime_app_info_path, strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to remove appinfo children '%s': %m", runtime_app_info_path);
 
        return;
 }
@@ -1248,7 +1236,6 @@ static void proc_restore_runtime_app_list(void)
        _cleanup_closedir_ DIR *dp = NULL;
        struct dirent dentry;
        struct dirent *dir;
-       char buf[ERR_BUF_SIZE];
 
        dp = opendir(RUNTIME_APP_INFO_DIR);
        if (!dp)
@@ -1272,18 +1259,15 @@ static void proc_restore_runtime_app_list(void)
 
                ret = proc_restore_runtime_app_info(path);
                if (ret < 0)
-                       _E("Failed to restore runtime appinfo '%s': %s",
-                          dir->d_name, strerror_r(-ret, buf, ERR_BUF_SIZE));
+                       _E("Failed to restore runtime appinfo '%s': %m", dir->d_name);
        }
 }
 
 static int resourced_proc_init(void* data)
 {
-       char buf[ERR_BUF_SIZE];
        int ret = mkdir(RUNTIME_APP_INFO_DIR, S_IRWXU | S_IRGRP | S_IXGRP);
        if (ret < 0 && errno != EEXIST) {
-               _E("Failed to create directory %s: %s", RUNTIME_APP_INFO_DIR,
-                               strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to create directory %s: %m", RUNTIME_APP_INFO_DIR);
                return RESOURCED_ERROR_FAIL;
        }
 
index d1aae4a65cf51e6e09077e112884e528eb523977..71d2acdd9a20232da425a644794d460869d8480c 100755 (executable)
@@ -93,7 +93,6 @@ static DBusMessage *edbus_get_meminfo(E_DBus_Object *obj, DBusMessage *msg)
        DBusMessage *reply;
        struct meminfo mi;
        int r;
-       char error_buf[ERR_BUF_SIZE];
 
        reply = dbus_message_new_method_return(msg);
 
@@ -105,8 +104,7 @@ static DBusMessage *edbus_get_meminfo(E_DBus_Object *obj, DBusMessage *msg)
                             MEMINFO_MASK_SWAP_TOTAL |
                             MEMINFO_MASK_SWAP_FREE);
        if (r < 0) {
-               _E("Failed to get meminfo: %s",
-                               strerror_r(-r, error_buf, ERR_BUF_SIZE));
+               _E("Failed to get meminfo: %m");
                return reply;
        }
 
index 8572c3df8e21862734d9bee1ab954aaea9a8bbfb..93ffe4614ee1c50913223e36412c29e814b59913 100644 (file)
@@ -66,21 +66,20 @@ static int resourced_write_state(void)
 {
        pid_t pid = getpid(), old_pid = 0;
        int ret;
-       char buf[ERR_BUF_SIZE];
 
        assert(pid >= 0);
 
        ret = mkdir(RUNTIME_RESOURCED_DIR, S_IRWXU | S_IRGRP | S_IXGRP);
        if (ret < 0 && errno != EEXIST)
-               _E("Failed to create directory %s: %s",
-                               RUNTIME_RESOURCED_DIR, strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to create directory %s: %m",
+                               RUNTIME_RESOURCED_DIR);
 
        if (access(RUNTIME_RESOURCED_PID_PATH, F_OK) < 0)
                goto write_pid;
 
        ret = fread_uint(RUNTIME_RESOURCED_PID_PATH, (u_int32_t*)&old_pid);
        if (ret < 0) {
-               _E("Failed to read old resourced pid: %s", strerror_r(-ret, buf, ERR_BUF_SIZE));
+               _E("Failed to read old resourced pid: %m");
                return ret;
        }
 
index 9bb1f7d05c4f98bf4392e1df19e30d44de0ce4d6..8324343f916bf58a336d496c499d60306eb1ea0b 100644 (file)
@@ -164,7 +164,6 @@ static pid_t swap_change_state(enum swap_state state)
        int status;
        pid_t child_pid;
        pid_t pid = fork();
-       char error_buf[ERR_BUF_SIZE];
 
        if (pid < 0) {
                _E("failed to fork");
@@ -185,8 +184,7 @@ static pid_t swap_change_state(enum swap_state state)
        /* parent */
        child_pid = waitpid(pid, &status, 0);
        if (child_pid < 0) {
-               _E("can't wait for a pid %d %d %s", pid, status,
-                               strerror_r(errno, error_buf, ERR_BUF_SIZE));
+               _E("can't wait for a pid %d %d: %m", pid, status);
                return child_pid;
        }
 
index 42b6adc0452f4424b4d8efd76088f11d9aceebdf..3839dafe4b9216375691c9c601c65724ea859ccd 100644 (file)
@@ -93,7 +93,6 @@ static int vip_create_sub_cgroup(const char *name, pid_t pid)
        _cleanup_free_ char *cgroup_name = NULL;
        bool already;
        int r;
-       char buf[ERR_BUF_SIZE];
 
        assert(name);
        assert(pid);
@@ -118,8 +117,8 @@ static int vip_create_sub_cgroup(const char *name, pid_t pid)
 
        r = cgroup_write_node_uint32(cgroup_name, TASK_FILE_NAME, pid);
        if (r < 0) {
-               _E("failed to write pid '%d' to '%s': %s",
-                  pid, cgroup_name, strerror_r(-r, buf, ERR_BUF_SIZE));
+               _E("failed to write pid '%d' to '%s': %m",
+                  pid, cgroup_name);
                return r;
        }
 
@@ -204,7 +203,6 @@ static int resourced_vip_process_init(void *data)
 {
        _cleanup_close_ int checkfd = -1;
        int r;
-       char buf[ERR_BUF_SIZE];
 
        r = access(CHECK_RELEASE_PROGRESS, F_OK);
        if (r == 0) {
@@ -215,7 +213,7 @@ static int resourced_vip_process_init(void *data)
 
        r = config_parse(VIP_CONF_FILE, vip_load_config, NULL);
        if (r < 0) {
-               _E("failed to parse vip config file: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
+               _E("failed to parse vip config file: %m");
                return RESOURCED_ERROR_FAIL;
        }
 
@@ -238,7 +236,7 @@ static int resourced_vip_process_init(void *data)
 
                r = cgroup_set_release_agent("vip", "/usr/bin/vip-release-agent");
                if (r < 0) {
-                       _E("failed to set vip release agent: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
+                       _E("failed to set vip release agent: %m");
                        return RESOURCED_ERROR_FAIL;
                }
        }
index 6ded7607646e93d638861296ba3dcabcdf52da1a..50b642b0af56cd8d2910d9fb742e973fced5ff98 100644 (file)
@@ -30,7 +30,6 @@ static int run_exec(char **argv)
 {
        int status = 0, times = 0, wpid;
        pid_t pid = 0;
-       char buf[ERR_BUF_SIZE];
 
        if (argv == NULL)
                return -3;
@@ -43,7 +42,7 @@ static int run_exec(char **argv)
        if (pid == 0) {
                setpgid(0, 0);
                if (execv(argv[0], argv) == -1) {
-                       _E("Error execv: %s.\n", strerror_r(errno, buf, ERR_BUF_SIZE));
+                       _E("Error execv: %m.\n");
                        _exit(-1);
                }
                _exit(1);