From 4439f2f4e19d7dec3d12a9feb893a4900f4acc32 Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Mon, 20 Mar 2017 13:13:45 +0900 Subject: [PATCH] replace strerror() to strerror_r() for thread safety It adds a macro to print error information of errno. Change-Id: Ic68c0b40bea361788917618e7263f6ed30e04e03 --- pkgmgr_font/src/font_service_register.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pkgmgr_font/src/font_service_register.c b/pkgmgr_font/src/font_service_register.c index 78529a3..e78d85d 100755 --- a/pkgmgr_font/src/font_service_register.c +++ b/pkgmgr_font/src/font_service_register.c @@ -41,6 +41,12 @@ #define DEBUG_ERROR(frmt, args...) \ do { SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt"\n",\ __func__, ##args);} while (0) +#define DEBUG_ERROR_ERRNO(frmt, args...) \ + do { \ + char error_string[255] = { 0 }; \ + strerror_r(errno, error_string, sizeof(error_string)); \ + SLOG(LOG_ERROR,FONT_SERVICE_TAG, "[font_service] %s: "frmt": %s\n",\ + __func__, ##args, error_string);} while (0) static const char *PARENT_PATH = "/opt/share/fonts"; static const char *DOWNLOAD_PATH = "/opt/share/fonts/download"; @@ -203,19 +209,19 @@ static int copy_file(const char *srcpath, const char *destpath) { if ((in = fopen(srcpath, "rb")) == NULL) { - DEBUG_ERROR("copyfile is failed. The srcpath[%s] is not opened with read permission. fopen(): %s\n", srcpath, strerror(errno)); + DEBUG_ERROR_ERRNO("copyfile is failed. The srcpath[%s] is not opened with read permission. fopen()", srcpath); goto FAIL; } if ((out = fopen(destpath, "wb")) == NULL) { - DEBUG_ERROR("copyfile is failed. The destpath[%s] is not opened with write permission. fopen(): %s\n", destpath, strerror(errno)); + DEBUG_ERROR_ERRNO("copyfile is failed. The destpath[%s] is not opened with write permission. fopen()", destpath); goto FAIL; } if ((buf = (char *) malloc(COPY_BUF_SIZE)) == NULL) { - DEBUG_ERROR("copyfile is failed. Memory allocation for copy buffer is failed. Request size [%d]. malloc(): %s\n", COPY_BUF_SIZE, strerror(errno)); + DEBUG_ERROR_ERRNO("copyfile is failed. Memory allocation for copy buffer is failed. Request size [%d]. malloc()", COPY_BUF_SIZE); goto FAIL; } @@ -225,13 +231,13 @@ static int copy_file(const char *srcpath, const char *destpath) { { /* Reads "len" string. But, it fails to write file. We need to remove wrong result. */ - DEBUG_ERROR("copyfile is failed. fwrite fails to write. fwrite(): %s\n", strerror(errno)); + DEBUG_ERROR_ERRNO("copyfile is failed. fwrite fails to write. fwrite()"); fclose(out); out = NULL; if (remove(destpath) == -1) - DEBUG_ERROR("removing copied file with error is failed. remove(): %s\n", strerror(errno)); + DEBUG_ERROR_ERRNO("removing copied file with error is failed. remove()"); goto FAIL; } @@ -310,7 +316,7 @@ static int move_path(const char *srcpath, const char *destpath) } if (remove(srcdir) == -1) - DEBUG_ERROR("removing src file[%s] is failed. remove(): %s\n", srcdir, strerror(errno)); + DEBUG_ERROR_ERRNO("removing src file[%s] is failed. remove()", srcdir); } } @@ -657,7 +663,7 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li if (access(deletedir, F_OK) == -1) { - DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno)); + DEBUG_ERROR_ERRNO("dest directory(%s) is not exist", deletedir); goto FAIL; } @@ -671,14 +677,14 @@ int COMMON_PKGMGR_PLUGIN_UPGRADE(const char *pkgid, const char *appid, GList *li ret = make_dir(PARENT_PATH); if (ret < 0) { - DEBUG_ERROR("make current directory(%s) is failed: %s\n", PARENT_PATH, strerror(errno)); + DEBUG_ERROR_ERRNO("make current directory(%s) is failed", PARENT_PATH); goto FAIL; } ret = make_dir(dest_path); if (ret < 0) { - DEBUG_ERROR("make current directory(%s) is failed: %s\n", dest_path, strerror(errno)); + DEBUG_ERROR_ERRNO("make current directory(%s) is failed", dest_path); goto FAIL; } @@ -818,7 +824,7 @@ int COMMON_PKGMGR_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList * if (access(deletedir, F_OK) == -1) { - DEBUG_ERROR("dest directory(%s) is not exist: %s\n", deletedir, strerror(errno)); + DEBUG_ERROR_ERRNO("dest directory(%s) is not exist", deletedir); goto FAIL; } -- 2.7.4