Source
/* log [file, <regexp>,<encoding>,<maxlines>, <mode>,<output>,<maxdelay>, <options>,<persistent_dir>] 9 params */
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/* ssize_t */
/* _WINDOWS */
/* maximum size of the first and the last blocks of the file to calculate MD5 sum for */
/* cannot compare file device and inode numbers */
/* both files have different device or inode numbers */
/* both files have the same device and inode numbers */
typedef enum
{
ZBX_LOG_ROTATION_LOGRT = 0, /* pure rotation model */
ZBX_LOG_ROTATION_LOGCPT, /* copy-truncate rotation model */
ZBX_LOG_ROTATION_REREAD, /* reread if modification time changes but size does not */
ZBX_LOG_ROTATION_NO_REREAD /* don't reread if modification time changes but size does not */
}
zbx_log_rotation_options_t;
/******************************************************************************
* *
* Purpose: separates given string to two parts by given delimiter in string *
* *
* Parameters: *
* str - [IN] not-empty string to split *
* del - [IN] pointer to character in string *
* part1 - [OUT] pointer to buffer for first part with delimiter *
* part2 - [OUT] pointer to buffer for second part *
* *
* Return value: SUCCEED - on splitting without errors *
* FAIL - on splitting with errors *
* *
* Comments: Memory for "part1" and "part2" is allocated only on SUCCEED. *
* *
******************************************************************************/
static int split_string(const char *str, const char *del, char **part1, char **part2)
{
size_t str_length, part1_length, part2_length;
int ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() str:'%s' del:'%s'", __func__, str, del);
str_length = strlen(str);
/* since the purpose of this function is to be used in split_filename(), we allow part1 to be */
/* just *del (e.g., "/" - file system root), but we do not allow part2 (filename) to be empty */
if (del < str || del >= (str + str_length - 1))
{
zabbix_log(LOG_LEVEL_DEBUG, "%s() cannot proceed: delimiter is out of range", __func__);
goto out;
}
part1_length = (size_t)(del - str + 1);
part2_length = str_length - part1_length;
*part1 = (char *)zbx_malloc(*part1, part1_length + 1);