const int pid)
{
int ret;
- char buf[256];
+ char buf[ERR_BUF_SIZE];
if (pid <=0) {
_E("try to write empty pid to %s", cgroup_full_path);
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, sizeof(buf)));
+ cgroup_full_path, strerror_r(errno, buf, ERR_BUF_SIZE));
return RESOURCED_ERROR_NONE;
}
#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
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) {
if (ret < 0) {
_E("Failed to get %s: %s",
meminfo_id_to_string(MEMINFO_ID_SWAP_TOTAL),
- strerror(-ret));
+ strerror_r(-ret, buf, ERR_BUF_SIZE));
return RESOURCED_ERROR_FAIL;
}
swap_total = mi.value[MEMINFO_ID_SWAP_TOTAL];
{
struct meminfo mi;
int ret;
- char buf[256];
+ 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, sizeof(buf)));
+ strerror_r(-ret, buf, ERR_BUF_SIZE));
return 0;
}
{
struct meminfo mi;
int ret;
- char error_buf[256];
+ 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, error_buf, sizeof(error_buf)));
+ strerror_r(-ret, buf, ERR_BUF_SIZE));
return 0;
}
int proc_sys_node_trigger(enum sys_node_id sys_node_id)
{
FILE *fp = NULL;
- char error_buf[256];
+ 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);
if (fp == NULL) {
_E("Failed to open: %s: %s\n",
sys_node_tables[sys_node_id].path,
- strerror_r(errno, error_buf, sizeof(error_buf)));
+ strerror_r(errno, buf, ERR_BUF_SIZE));
sys_node_tables[sys_node_id].valid = 0;
return RESOURCED_ERROR_FAIL;
}
#define _SYSTEM_RESOURCE_TRACE_H_
#include "config.h"
+#include "const.h"
#include <dlog.h>
#include <errno.h>
#include <signal.h>
}
#define TRACE_RET_ERRCODE(type, error_code) do { \
- char buf[256]; \
- _##type("errno %d, errmsg %s", error_code, strerror_r(-error_code, buf, sizeof(buf))); \
+ char buf[ERR_BUF_SIZE]; \
+ _##type("errno %d, errmsg %s", error_code, strerror_r(-error_code, buf, ERR_BUF_SIZE)); \
} 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[256]; \
+ char buf[ERR_BUF_SIZE]; \
_##type(fmt, ##arg); \
- _##type("errno %d, errmsg %s", error_code, strerror_r(-error_code, buf, sizeof(buf))); \
+ _##type("errno %d, errmsg %s", error_code, strerror_r(-error_code, buf, ERR_BUF_SIZE)); \
} while (0)
#define DTRACE_RET_ERRCODE_MSG(error_code, fmt, arg...) \
_cleanup_free_ char *info = NULL;
unsigned int pss = 0, uss = 0;
int ret;
- char error_buf[256];
+ char error_buf[ERR_BUF_SIZE];
/* For write to data crud during period */
/* write memory usage in proc_list */
if (ret < 0) {
_E("Failed to get PID(%d) smaps: %s",
p_data->pid,
- strerror_r(-ret, error_buf, sizeof(error_buf)));
+ strerror_r(-ret, error_buf, ERR_BUF_SIZE));
return ret;
}
{
void *mem = NULL;
int r;
- char buf[256];
+ char buf[ERR_BUF_SIZE];
fprintf(stdout, "Memory stress size is: %zu", arg_size);
r = mem_stress_allocate_memory(&mem, arg_size);
if (r < 0) {
- fprintf(stderr, "Failed to allocate memory: %s", strerror_r(-r, buf, sizeof(buf)));
+ fprintf(stderr, "Failed to allocate memory: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
return r;
}
r = mem_stress_free_memory(mem, arg_size);
if (r < 0) {
- fprintf(stderr, "Failed to free memory: %s", strerror_r(-r, buf, sizeof(buf)));
+ fprintf(stderr, "Failed to free memory: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
return r;
}
void proc_app_list_close(void)
{
int err;
+ char buf[ERR_BUF_SIZE];
app_list.ref--;
err = pthread_mutex_unlock(&app_list.lock);
if (err)
_E("Failed to unlock app list mutex: %s",
- strerror(err));
+ strerror_r(err, buf, ERR_BUF_SIZE));
}
static bool is_ui_app(enum application_type type)
{
_cleanup_free_ char *runtime_app_info_path = NULL;
int ret;
+ char buf[ERR_BUF_SIZE];
assert(pai);
assert(pid > 0);
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(ENOMEM));
+ _E("Failed to get runtime appinfo path: %s",
+ strerror_r(ENOMEM, buf, ERR_BUF_SIZE));
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(-ret));
+ runtime_app_info_path, strerror_r(-ret, buf, ERR_BUF_SIZE));
}
void proc_set_process_memory_state(struct proc_app_info *pai,
{
_cleanup_app_list_close_ GSList *proc_app_list = NULL;
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(ret));
+ _E("Failed to add runtime app info: %s", strerror_r(-ret, buf, ERR_BUF_SIZE));
proc_app_list = proc_app_list_open();
app_list.list = g_slist_prepend(proc_app_list, pai);
{
_cleanup_app_list_close_ GSList *proc_app_list = NULL;
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(-ret));
+ pai->appid, strerror_r(-ret, buf, ERR_BUF_SIZE));
proc_app_list = proc_app_list_open();
app_list.list = g_slist_remove(proc_app_list, pai);
{
_cleanup_free_ char *runtime_app_info_path = NULL;
int ret;
+ char buf[ERR_BUF_SIZE];
assert(pai);
assert(pid >= 0);
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(ENOMEM));
+ _E("Failed to get runtime appinfo path: %s",
+ strerror_r(ENOMEM, buf, ERR_BUF_SIZE));
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(-ret));
+ runtime_app_info_path, strerror_r(-ret, buf, ERR_BUF_SIZE));
return;
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(-ret));
+ runtime_app_info_path, strerror_r(-ret, buf, ERR_BUF_SIZE));
return;
}
_cleanup_closedir_ DIR *dp = NULL;
struct dirent dentry;
struct dirent *dir;
+ char buf[ERR_BUF_SIZE];
dp = opendir(RUNTIME_APP_INFO_DIR);
if (!dp)
ret = proc_restore_runtime_app_info(path);
if (ret < 0)
_E("Failed to restore runtime appinfo '%s': %s",
- dir->d_name, strerror(-ret));
+ dir->d_name, strerror_r(-ret, buf, ERR_BUF_SIZE));
}
}
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(-ret));
+ _E("Failed to create directory %s: %s", RUNTIME_APP_INFO_DIR,
+ strerror_r(-ret, buf, ERR_BUF_SIZE));
return RESOURCED_ERROR_FAIL;
}
DBusMessage *reply;
struct meminfo mi;
int r;
- char error_buf[256];
+ char error_buf[ERR_BUF_SIZE];
reply = dbus_message_new_method_return(msg);
MEMINFO_MASK_SWAP_FREE);
if (r < 0) {
_E("Failed to get meminfo: %s",
- strerror_r(-r, error_buf, sizeof(error_buf)));
+ strerror_r(-r, error_buf, ERR_BUF_SIZE));
return reply;
}
{
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(-ret));
+ RUNTIME_RESOURCED_DIR, strerror_r(-ret, buf, ERR_BUF_SIZE));
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(-ret));
+ _E("Failed to read old resourced pid: %s", strerror_r(-ret, buf, ERR_BUF_SIZE));
return ret;
}
int status;
pid_t child_pid;
pid_t pid = fork();
- char error_buf[256];
+ char error_buf[ERR_BUF_SIZE];
if (pid < 0) {
_E("failed to fork");
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, sizeof(error_buf)));
+ strerror_r(errno, error_buf, ERR_BUF_SIZE));
return child_pid;
}
_cleanup_free_ char *cgroup_name = NULL;
bool already;
int r;
- char buf[256];
+ char buf[ERR_BUF_SIZE];
assert(name);
assert(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, sizeof(buf)));
+ pid, cgroup_name, strerror_r(-r, buf, ERR_BUF_SIZE));
return r;
}
{
_cleanup_close_ int checkfd = -1;
int r;
- char buf[256];
+ char buf[ERR_BUF_SIZE];
r = access(CHECK_RELEASE_PROGRESS, F_OK);
if (r == 0) {
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, sizeof(buf)));
+ _E("failed to parse vip config file: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
return RESOURCED_ERROR_FAIL;
}
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, sizeof(buf)));
+ _E("failed to set vip release agent: %s", strerror_r(-r, buf, ERR_BUF_SIZE));
return RESOURCED_ERROR_FAIL;
}
}
{
int status = 0, times = 0, wpid;
pid_t pid = 0;
- char buf[256];
+ char buf[ERR_BUF_SIZE];
if (argv == NULL)
return -3;
if (pid == 0) {
setpgid(0, 0);
if (execv(argv[0], argv) == -1) {
- _E("Error execv: %s.\n", strerror_r(errno, buf, sizeof(buf)));
+ _E("Error execv: %s.\n", strerror_r(errno, buf, ERR_BUF_SIZE));
_exit(-1);
}
_exit(1);