Modify strerror to strerror_r 44/63144/1 accepted/tizen/common/20160325.133758 accepted/tizen/ivi/20160323.013556 accepted/tizen/mobile/20160323.013505 accepted/tizen/tv/20160323.013519 accepted/tizen/wearable/20160323.013539 submit/tizen/20160322.121104
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 22 Mar 2016 08:08:42 +0000 (17:08 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 22 Mar 2016 08:10:22 +0000 (17:10 +0900)
- strerror makes no guarantee of thread safety

Change-Id: If19e318bcc414977937ca9eff1b38b179693cfab
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/data-control-internal.c
src/data-control-sql-cursor.c

index e682a45..51b4423 100755 (executable)
@@ -28,6 +28,7 @@
 #define RESULT_PAGE_NUMBER             "RESULT_PAGE_NUMBER"
 #define MAX_RETRY                      5
 
+#define ERR_BUFFER_SIZE         1024
 #define BUFSIZE 512
 
 int _consumer_request_compare_cb(gconstpointer a, gconstpointer b)
@@ -168,7 +169,7 @@ void _socket_info_free(gpointer socket)
 datacontrol_socket_info *_get_socket_info(const char *caller_id, const char *callee_id, const char *type,
                GIOFunc cb, void *data)
 {
-
+       char err_buf[ERR_BUFFER_SIZE];
        int socketpair = 0;
        datacontrol_socket_info *socket_info = NULL;
        bundle *sock_bundle = bundle_create();
@@ -185,7 +186,7 @@ datacontrol_socket_info *_get_socket_info(const char *caller_id, const char *cal
                GIOChannel *gio_read = NULL;
                gio_read = g_io_channel_unix_new(socketpair);
                if (!gio_read) {
-                       LOGE("Error is %s\n", strerror(errno));
+                       LOGE("Error is %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return NULL;
                }
 
index 460e571..82f4b75 100755 (executable)
@@ -14,6 +14,7 @@
 #define LOG_TAG "DATA_CONTROL"
 #endif
 
+#define ERR_BUFFER_SIZE                1024
 #define MAX_ROW_COUNT          1024
 
 resultset_cursor *datacontrol_sql_get_cursor()
@@ -118,11 +119,12 @@ int datacontrol_sql_get_column_name(resultset_cursor *cursor, int column_index,
        int ret = 0;
        int column_len = 0;
        int fd = cursor->resultset_fd;
+       char err_buf[ERR_BUFFER_SIZE];
 
        ret = lseek(fd, cursor->resultset_col_name_offset, SEEK_SET);
        if (ret < 0) {
                LOGE("unable to seek in the resultset file: %d %s", cursor->resultset_current_offset,
-                               strerror(errno));
+                               strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -137,14 +139,14 @@ int datacontrol_sql_get_column_name(resultset_cursor *cursor, int column_index,
                        col_name = (char *)calloc(column_len, sizeof(char));
                        ret = read(fd, col_name, column_len);
                        if (ret == 0) {
-                               LOGE("unable to read col_name : %s", strerror(errno));
+                               LOGE("unable to read col_name : %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                                free(col_name);
                                return DATACONTROL_ERROR_IO_ERROR;
                        }
                } else {
                        ret = lseek(fd, column_len, SEEK_CUR);
                        if (ret < 0) {
-                               LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                               LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                                return DATACONTROL_ERROR_IO_ERROR;
                        }
                }
@@ -164,13 +166,13 @@ int datacontrol_sql_get_column_item_size(resultset_cursor *cursor, int column_in
        int size = 0;
        int i = 0;
        int ret = 0;
-
+       char err_buf[ERR_BUFFER_SIZE];
        int fd = cursor->resultset_fd;
 
        ret = lseek(fd, cursor->resultset_current_offset, SEEK_SET);
        if (ret < 0) {
                LOGE("unable to seek in the resultset file: %d %s", cursor->resultset_current_offset,
-                               strerror(errno));
+                               strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -178,32 +180,32 @@ int datacontrol_sql_get_column_item_size(resultset_cursor *cursor, int column_in
        for (i = 0; i < column_index; i++) {
                ret = read(fd, &type, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = read(fd, &size, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = lseek(fd, size, SEEK_CUR);
                if (ret < 0) {
-                       LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                       LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
        }
 
        ret = read(fd, &type, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
        ret = read(fd, &size, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -218,12 +220,12 @@ int datacontrol_sql_get_column_item_type(resultset_cursor *cursor, int column_in
        int i = 0;
        int size = 0;
        int ret = 0;
-
+       char err_buf[ERR_BUFFER_SIZE];
        int fd = cursor->resultset_fd;
 
        ret = lseek(fd, cursor->resultset_current_offset, SEEK_SET);
        if (ret < 0) {
-               LOGE("unable to seek in the resultset file: %s", strerror(errno));
+               LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -231,26 +233,26 @@ int datacontrol_sql_get_column_item_type(resultset_cursor *cursor, int column_in
        for (i = 0; i < column_index; i++) {
                ret = read(fd, &type, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = read(fd, &size, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = lseek(fd, size, SEEK_CUR);
                if (ret < 0) {
-                       LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                       LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
        }
 
        ret = read(fd, &type, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -290,12 +292,12 @@ int datacontrol_sql_get_blob_data(resultset_cursor *cursor, int column_index, vo
        int size = 0;
        int i = 0;
        int ret = 0;
-
+       char err_buf[ERR_BUFFER_SIZE];
        int fd = cursor->resultset_fd;
 
        ret = lseek(fd, cursor->resultset_current_offset, SEEK_SET);
        if (ret < 0) {
-               LOGE("unable to seek in the resultset file: %s", strerror(errno));
+               LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -303,26 +305,26 @@ int datacontrol_sql_get_blob_data(resultset_cursor *cursor, int column_index, vo
        for (i = 0; i < column_index; i++) {
                ret = read(fd, &type, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = read(fd, &size, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = lseek(fd, size, SEEK_CUR);
                if (ret < 0) {
-                       LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                       LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
        }
 
        ret = read(fd, &type, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -333,7 +335,7 @@ int datacontrol_sql_get_blob_data(resultset_cursor *cursor, int column_index, vo
 
        ret = read(fd, &size, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read size in the resultset file: %s", strerror(errno));
+               LOGE("unable to read size in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -348,7 +350,7 @@ int datacontrol_sql_get_blob_data(resultset_cursor *cursor, int column_index, vo
 
                ret = read(fd, data, size);
                if (ret < size) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        free(data);
                        return DATACONTROL_ERROR_IO_ERROR;
                }
@@ -379,12 +381,12 @@ int datacontrol_sql_get_int64_data(resultset_cursor *cursor, int column_index, l
        int size = 0;
        int i = 0;
        int ret = 0;
-
+       char err_buf[ERR_BUFFER_SIZE];
        int fd = cursor->resultset_fd;
 
        ret = lseek(fd, cursor->resultset_current_offset, SEEK_SET);
        if (ret < 0) {
-               LOGE("unable to seek in the resultset file: %s", strerror(errno));
+               LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -392,26 +394,26 @@ int datacontrol_sql_get_int64_data(resultset_cursor *cursor, int column_index, l
        for (i = 0; i < column_index; i++) {
                ret = read(fd, &type, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = read(fd, &size, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = lseek(fd, size, SEEK_CUR);
                if (ret < 0) {
-                       LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                       LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
        }
 
        ret = read(fd, &type, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -422,13 +424,13 @@ int datacontrol_sql_get_int64_data(resultset_cursor *cursor, int column_index, l
 
        ret = read(fd, &size, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
        ret = read(fd, data, size);
        if (ret < size) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -441,12 +443,12 @@ int datacontrol_sql_get_double_data(resultset_cursor *cursor, int column_index,
        int size = 0;
        int i = 0;
        int ret = 0;
-
+       char err_buf[ERR_BUFFER_SIZE];
        int fd = cursor->resultset_fd;
 
        ret = lseek(fd, cursor->resultset_current_offset, SEEK_SET);
        if (ret < 0) {
-               LOGE("unable to seek in the resultset file: %s", strerror(errno));
+               LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -454,26 +456,26 @@ int datacontrol_sql_get_double_data(resultset_cursor *cursor, int column_index,
        for (i = 0; i < column_index; i++) {
                ret = read(fd, &type, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = read(fd, &size, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = lseek(fd, size, SEEK_CUR);
                if (ret < 0) {
-                       LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                       LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
        }
 
        ret = read(fd, &type, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -484,13 +486,13 @@ int datacontrol_sql_get_double_data(resultset_cursor *cursor, int column_index,
 
        ret = read(fd, &size, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
        ret = read(fd, data, size);
        if (ret < size) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -504,12 +506,12 @@ int datacontrol_sql_get_text_data(resultset_cursor *cursor, int column_index, ch
        int size = 0;
        int i = 0;
        int ret = 0;
-
+       char err_buf[ERR_BUFFER_SIZE];
        int fd = cursor->resultset_fd;
 
        ret = lseek(fd, cursor->resultset_current_offset, SEEK_SET);
        if (ret < 0) {
-               LOGE("unable to seek in the resultset file: %s", strerror(errno));
+               LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -517,26 +519,26 @@ int datacontrol_sql_get_text_data(resultset_cursor *cursor, int column_index, ch
        for (i = 0; i < column_index; i++) {
                ret = read(fd, &type, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = read(fd, &size, sizeof(int));
                if (ret == 0) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
 
                ret = lseek(fd, size, SEEK_CUR);
                if (ret < 0) {
-                       LOGE("unable to seek in the resultset file: %s", strerror(errno));
+                       LOGE("unable to seek in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        return DATACONTROL_ERROR_IO_ERROR;
                }
        }
 
        ret = read(fd, &type, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -548,7 +550,7 @@ int datacontrol_sql_get_text_data(resultset_cursor *cursor, int column_index, ch
 
        ret = read(fd, &size, sizeof(int));
        if (ret == 0) {
-               LOGE("unable to read in the resultset file: %s", strerror(errno));
+               LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                return DATACONTROL_ERROR_IO_ERROR;
        }
 
@@ -562,7 +564,7 @@ int datacontrol_sql_get_text_data(resultset_cursor *cursor, int column_index, ch
                memset(data, 0, size + 1);
                ret = read(fd, data, size);
                if (ret < size) {
-                       LOGE("unable to read in the resultset file: %s", strerror(errno));
+                       LOGE("unable to read in the resultset file: %s", strerror_r(errno, err_buf, sizeof(err_buf)));
                        free(data);
                        return DATACONTROL_ERROR_IO_ERROR;
                }