summaryrefslogtreecommitdiff
path: root/src/lib/evas/cserve2/evas_cs2_client.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-08-23 14:52:11 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:14 +0900
commita14e69e5733457f2b8e09caadb24271522cbe82b (patch)
treec8a61c9bc277a85a7d82563edbb3bf3cd56de244 /src/lib/evas/cserve2/evas_cs2_client.c
parent743e2047636ee7deb8dca87afd8651aa0c83bffb (diff)
evas/cserve2: Remap string entries when size changed
Lots of files can't be found by the client when the strings table changed, because it was not remapped properly.
Diffstat (limited to 'src/lib/evas/cserve2/evas_cs2_client.c')
-rw-r--r--src/lib/evas/cserve2/evas_cs2_client.c146
1 files changed, 91 insertions, 55 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c
index 9bcf966339..7746e1d1c0 100644
--- a/src/lib/evas/cserve2/evas_cs2_client.c
+++ b/src/lib/evas/cserve2/evas_cs2_client.c
@@ -1661,58 +1661,11 @@ evas_cserve2_font_glyph_bitmap_get(Font_Entry *fe, unsigned int idx, Font_Hint_F
1661 1661
1662static Eina_Bool _shared_index_remap_check(Shared_Index *si, int elemsize); 1662static Eina_Bool _shared_index_remap_check(Shared_Index *si, int elemsize);
1663 1663
1664// Returns the number of correctly opened index arrays 1664static Eina_Bool
1665static int 1665_string_index_refresh(void)
1666_server_index_list_set(Msg_Base *data, int size)
1667{ 1666{
1668 Msg_Index_List *msg = (Msg_Index_List *) data; 1667 size_t sz;
1669 unsigned sz; 1668 Eina_Bool ret = EINA_FALSE;
1670
1671 // TODO #1: Check populate rule.
1672 // TODO #2: Protect memory for read-only access.
1673 // TODO #3: Optimize file reopen/remap (esp. strings table)
1674
1675 if (size != sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
1676 {
1677 CRIT("Invalid message! type: %d, size: %d (expected %d)",
1678 msg->base.type, size, (int) sizeof(*msg));
1679 return -1;
1680 }
1681
1682 if (_index.generation_id == msg->generation_id)
1683 {
1684 ERR("New index generation_id is the same as before: %d",
1685 _index.generation_id);
1686 }
1687
1688 _index.generation_id = msg->generation_id;
1689
1690 // 1. Strings (indexes and entries)
1691
1692 if (_index.strings_entries.data
1693 && strncmp(_index.strings_entries.path, msg->strings_entries_path,
1694 SHARED_BUFFER_PATH_MAX) != 0)
1695 {
1696 DBG("Updating string entries shm to: '%s'", msg->strings_entries_path);
1697 eina_file_map_free(_index.strings_entries.f, _index.strings_entries.data);
1698 eina_file_close(_index.strings_entries.f);
1699 _index.strings_entries.f = NULL;
1700 _index.strings_entries.data = NULL;
1701 }
1702
1703 if (_index.strings_index.data
1704 && strncmp(_index.strings_index.path, msg->strings_index_path,
1705 SHARED_BUFFER_PATH_MAX) != 0)
1706 {
1707 DBG("Updating string indexes shm to: '%s'", msg->strings_index_path);
1708 eina_file_map_free(_index.strings_index.f, _index.strings_index.data);
1709 eina_file_close(_index.strings_index.f);
1710 _index.strings_index.f = NULL;
1711 _index.strings_index.data = NULL;
1712 }
1713
1714 eina_strlcpy(_index.strings_entries.path, msg->strings_entries_path, SHARED_BUFFER_PATH_MAX);
1715 eina_strlcpy(_index.strings_index.path, msg->strings_index_path, SHARED_BUFFER_PATH_MAX);
1716 1669
1717 if (!_index.strings_entries.data 1670 if (!_index.strings_entries.data
1718 && _index.strings_entries.path[0] 1671 && _index.strings_entries.path[0]
@@ -1729,8 +1682,13 @@ _server_index_list_set(Msg_Base *data, int size)
1729 eina_file_close(_index.strings_entries.f); 1682 eina_file_close(_index.strings_entries.f);
1730 _index.strings_entries.f = NULL; 1683 _index.strings_entries.f = NULL;
1731 _index.strings_entries.data = NULL; 1684 _index.strings_entries.data = NULL;
1685 ret = EINA_FALSE;
1686 }
1687 else
1688 {
1689 DBG("Mapped string entries from %s", _index.strings_entries.path);
1690 ret = EINA_TRUE;
1732 } 1691 }
1733 else DBG("Mapped string entries from %s", _index.strings_entries.path);
1734 } 1692 }
1735 1693
1736 if (_index.strings_entries.data && 1694 if (_index.strings_entries.data &&
@@ -1752,6 +1710,7 @@ _server_index_list_set(Msg_Base *data, int size)
1752 _index.strings_index.count, _index.strings_index.header->count); 1710 _index.strings_index.count, _index.strings_index.header->count);
1753 _index.strings_index.count = _index.strings_index.header->count; 1711 _index.strings_index.count = _index.strings_index.header->count;
1754 } 1712 }
1713 ret = EINA_TRUE;
1755 } 1714 }
1756 else 1715 else
1757 { 1716 {
@@ -1762,20 +1721,79 @@ _server_index_list_set(Msg_Base *data, int size)
1762 _index.strings_index.f = NULL; 1721 _index.strings_index.f = NULL;
1763 _index.strings_entries.f = NULL; 1722 _index.strings_entries.f = NULL;
1764 _index.strings_entries.data = NULL; 1723 _index.strings_entries.data = NULL;
1724 ret = EINA_FALSE;
1765 } 1725 }
1766 } 1726 }
1767 1727
1768 _shared_index_remap_check(&_index.strings_index, sizeof(Index_Entry)); 1728 _shared_index_remap_check(&_index.strings_index, sizeof(Index_Entry));
1769 if (_index.strings_entries.data) 1729 if (_index.strings_entries.data)
1770 { 1730 {
1771 if (eina_file_refresh(_index.strings_entries.f)) 1731 if (eina_file_refresh(_index.strings_entries.f)
1732 || (_index.strings_entries.size != (int) eina_file_size_get(_index.strings_entries.f)))
1772 { 1733 {
1773 eina_file_map_free(_index.strings_entries.f, _index.strings_entries.data); 1734 eina_file_map_free(_index.strings_entries.f, _index.strings_entries.data);
1774 _index.strings_entries.data = eina_file_map_all(_index.strings_entries.f, EINA_FILE_RANDOM); 1735 _index.strings_entries.data = eina_file_map_all(_index.strings_entries.f, EINA_FILE_RANDOM);
1775 _index.strings_entries.size = eina_file_size_get(_index.strings_entries.f); 1736 _index.strings_entries.size = eina_file_size_get(_index.strings_entries.f);
1737 return EINA_TRUE;
1776 } 1738 }
1777 } 1739 }
1778 1740
1741 return ret;
1742}
1743
1744// Returns the number of correctly opened index arrays
1745static int
1746_server_index_list_set(Msg_Base *data, int size)
1747{
1748 Msg_Index_List *msg = (Msg_Index_List *) data;
1749
1750 // TODO #1: Check populate rule.
1751 // TODO #2: Protect memory for read-only access.
1752 // TODO #3: Optimize file reopen/remap (esp. strings table)
1753
1754 if (size != sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
1755 {
1756 CRIT("Invalid message! type: %d, size: %d (expected %d)",
1757 msg->base.type, size, (int) sizeof(*msg));
1758 return -1;
1759 }
1760
1761 if (_index.generation_id == msg->generation_id)
1762 {
1763 ERR("New index generation_id is the same as before: %d",
1764 _index.generation_id);
1765 }
1766
1767 _index.generation_id = msg->generation_id;
1768
1769 // 1. Strings (indexes and entries)
1770
1771 if (_index.strings_entries.data
1772 && strncmp(_index.strings_entries.path, msg->strings_entries_path,
1773 SHARED_BUFFER_PATH_MAX) != 0)
1774 {
1775 DBG("Updating string entries shm to: '%s'", msg->strings_entries_path);
1776 eina_file_map_free(_index.strings_entries.f, _index.strings_entries.data);
1777 eina_file_close(_index.strings_entries.f);
1778 _index.strings_entries.f = NULL;
1779 _index.strings_entries.data = NULL;
1780 }
1781
1782 if (_index.strings_index.data
1783 && strncmp(_index.strings_index.path, msg->strings_index_path,
1784 SHARED_BUFFER_PATH_MAX) != 0)
1785 {
1786 DBG("Updating string indexes shm to: '%s'", msg->strings_index_path);
1787 eina_file_map_free(_index.strings_index.f, _index.strings_index.data);
1788 eina_file_close(_index.strings_index.f);
1789 _index.strings_index.f = NULL;
1790 _index.strings_index.data = NULL;
1791 }
1792
1793 eina_strlcpy(_index.strings_entries.path, msg->strings_entries_path, SHARED_BUFFER_PATH_MAX);
1794 eina_strlcpy(_index.strings_index.path, msg->strings_index_path, SHARED_BUFFER_PATH_MAX);
1795 _string_index_refresh();
1796
1779 1797
1780 // 2. File indexes 1798 // 2. File indexes
1781 1799
@@ -1803,12 +1821,29 @@ _shared_string_get(int id)
1803{ 1821{
1804 Index_Entry *ie; 1822 Index_Entry *ie;
1805 1823
1824 if (!_index.strings_entries.data)
1825 {
1826 CRIT("Strings table is not valid: no data");
1827 return NULL;
1828 }
1829
1806 ie = (Index_Entry *) 1830 ie = (Index_Entry *)
1807 _shared_index_item_get_by_id(&_index.strings_index, sizeof(*ie), id); 1831 _shared_index_item_get_by_id(&_index.strings_index, sizeof(*ie), id);
1808 if (!ie) return NULL; 1832 if (!ie) return NULL;
1809 if (ie->offset < 0) return NULL; 1833 if (ie->offset < 0) return NULL;
1810 if (!ie->refcount) return NULL; 1834 if (!ie->refcount) return NULL;
1811 if (ie->offset + ie->length > _index.strings_entries.size) return NULL; 1835 if (ie->offset + ie->length > _index.strings_entries.size)
1836 {
1837 if (eina_file_refresh(_index.strings_entries.f)
1838 || (_index.strings_entries.size != (int) eina_file_size_get(_index.strings_entries.f)))
1839 {
1840 DBG("String entries size has changed from %d to %d",
1841 _index.strings_entries.size, (int) eina_file_size_get(_index.strings_entries.f));
1842 if (_string_index_refresh())
1843 return _shared_string_get(id);
1844 }
1845 return NULL;
1846 }
1812 1847
1813 return _index.strings_entries.data + ie->offset; 1848 return _index.strings_entries.data + ie->offset;
1814} 1849}
@@ -1821,7 +1856,7 @@ static const char *
1821_shared_file_data_hkey_get(char *hkey, const char *file, const char *key, 1856_shared_file_data_hkey_get(char *hkey, const char *file, const char *key,
1822 size_t hkey_size) 1857 size_t hkey_size)
1823{ 1858{
1824 size_t keylen, filelen; 1859 size_t keylen = 0, filelen;
1825 1860
1826 if (key) keylen = strlen(key) + 1; 1861 if (key) keylen = strlen(key) + 1;
1827 filelen = strlen(file); 1862 filelen = strlen(file);
@@ -2071,6 +2106,7 @@ _shared_index_remap_check(Shared_Index *si, int elemsize)
2071 si->f = NULL; 2106 si->f = NULL;
2072 return EINA_FALSE; 2107 return EINA_FALSE;
2073 } 2108 }
2109 si->count = (filesize - sizeof(Shared_Array_Header)) / elemsize;
2074 refresh = EINA_TRUE; 2110 refresh = EINA_TRUE;
2075 } 2111 }
2076 2112