~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to src/libs/zbxdbcache/dbcache.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Haas
  • Date: 2009-10-10 12:21:16 UTC
  • mfrom: (1.1.10 upstream) (8.2.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091010122116-44k2zdq57rb40i6z
Tags: 1:1.6.6-2
* debian/po/ja.po updated (Closes: #548651)
* debian/po/cs.po updated (Closes: #548675)
* debian/po/sv.po updated (Closes: #548796)
* debian/po/de.po updated (Closes: #549248)
* debian/po/it.po updated (Closes: #549579)
* debian/po/pt.po updated (Closes: #550087)
* debian/po/ru.po updated (Closes: #550102)
* debian/po/es.po updated (Closes: #550173)
* debian/po/fr.po updated (Closes: #550315)
* Manpages for zabbix_server and zabbix_agent added (Closes: #496696)
* Added hint about the difference of the zabbix_agent.conf and
  zabbix_agentd.conf in each config file as a comment. (Closes: #548701)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1854
1854
 
1855
1855
        if (NULL != first_text)
1856
1856
        {
1857
 
                offset = first_text - cache->text;
 
1857
                if (0 == (offset = first_text - cache->text))
 
1858
                        return;
 
1859
 
1858
1860
                memmove(cache->text, first_text, ZBX_TEXTBUFFER_SIZE - offset);
1859
1861
                
1860
1862
                for (i = 0; i < cache->history_num; i++)
1894
1896
{
1895
1897
        ZBX_DC_HISTORY  *history;
1896
1898
        int             index;
1897
 
        size_t          free_len;
 
1899
        size_t          free_len, sz;
1898
1900
 
1899
1901
retry:
1900
1902
        if (cache->history_num >= ZBX_HISTORY_SIZE)
1909
1911
                goto retry;
1910
1912
        }
1911
1913
 
1912
 
        if (text_len > sizeof(cache->text))
1913
 
        {
1914
 
                zabbix_log(LOG_LEVEL_ERR, "Insufficient shared memory");
1915
 
                exit(-1);
1916
 
        }
1917
 
 
1918
 
        free_len = sizeof(cache->text) - (cache->last_text - cache->text);
1919
 
 
1920
 
        if (text_len > free_len)
1921
 
        {
1922
 
                DCvacuum_text();
1923
 
 
1924
 
                free_len = sizeof(cache->text) - (cache->last_text - cache->text);
 
1914
        if (0 != text_len)
 
1915
        {
 
1916
                sz = sizeof(cache->text);
 
1917
 
 
1918
                if (text_len > sz)
 
1919
                {
 
1920
                        zabbix_log(LOG_LEVEL_ERR, "Insufficient shared memory");
 
1921
                        exit(-1);
 
1922
                }
 
1923
 
 
1924
                free_len = sz - (cache->last_text - cache->text);
1925
1925
 
1926
1926
                if (text_len > free_len)
1927
1927
                {
1928
 
                        UNLOCK_CACHE;
1929
 
 
1930
 
                        zabbix_log(LOG_LEVEL_DEBUG, "History text buffer is full. Sleeping for 1 second.");
1931
 
                        sleep(1);
1932
 
 
1933
 
                        LOCK_CACHE;
1934
 
 
1935
 
                        goto retry;
 
1928
                        DCvacuum_text();
 
1929
 
 
1930
                        free_len = sz - (cache->last_text - cache->text);
 
1931
 
 
1932
                        if (text_len > free_len)
 
1933
                        {
 
1934
                                UNLOCK_CACHE;
 
1935
 
 
1936
                                zabbix_log(LOG_LEVEL_DEBUG, "History text buffer is full. Sleeping for 1 second.");
 
1937
                                sleep(1);
 
1938
 
 
1939
                                LOCK_CACHE;
 
1940
 
 
1941
                                goto retry;
 
1942
                        }
1936
1943
                }
1937
1944
        }
1938
1945
 
2036
2043
 
2037
2044
        LOCK_CACHE;
2038
2045
 
2039
 
        len = strlen(value_orig) + 1;
 
2046
        if (HISTORY_STR_VALUE_LEN_MAX < (len = strlen(value_orig) + 1))
 
2047
                len = HISTORY_STR_VALUE_LEN_MAX;
2040
2048
        history = DCget_history_ptr(itemid, len);
2041
2049
 
2042
2050
        history->itemid                 = itemid;
2075
2083
 
2076
2084
        LOCK_CACHE;
2077
2085
 
2078
 
        len = strlen(value_orig) + 1;
 
2086
        if (HISTORY_TEXT_VALUE_LEN_MAX < (len = strlen(value_orig) + 1))
 
2087
                len = HISTORY_TEXT_VALUE_LEN_MAX;
2079
2088
        history = DCget_history_ptr(itemid, len);
2080
2089
 
2081
2090
        history->itemid                 = itemid;
2114
2123
 
2115
2124
        LOCK_CACHE;
2116
2125
 
2117
 
        len1 = strlen(value_orig) + 1;
2118
 
        len2 = (NULL != source && *source != '\0') ? strlen(source) + 1 : 0;
 
2126
        if (HISTORY_LOG_VALUE_LEN_MAX < (len1 = strlen(value_orig) + 1))
 
2127
                len1 = HISTORY_LOG_VALUE_LEN_MAX;
 
2128
        if (HISTORY_LOG_SOURCE_LEN_MAX < (len2 = (NULL != source && *source != '\0') ? strlen(source) + 1 : 0))
 
2129
                len2 = HISTORY_LOG_SOURCE_LEN_MAX;
2119
2130
        history = DCget_history_ptr(itemid, len1 + len2);
2120
2131
 
2121
2132
        history->itemid                 = itemid;
2128
2139
        cache->last_text                += len1;
2129
2140
        history->timestamp              = timestamp;
2130
2141
 
2131
 
        if (NULL != source && *source != '\0') {
 
2142
        if (0 != len2) {
2132
2143
                history->source         = cache->last_text;
2133
2144
                zbx_strlcpy(cache->last_text, source, len2);
2134
2145
                cache->last_text        += len2;