Source
/* make attempts to read until there is a printable character, which would indicate a result of the command */
/*
** 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/>.
**/
static int write_gsm(int fd, const char *str, char *error, int max_error_len)
{
int i, wlen, len, ret = SUCCEED;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() str:'%s'", __func__, str);
len = strlen(str);
for (wlen = 0; wlen < len; wlen += i)
{
if (-1 == (i = write(fd, str + wlen, len - wlen)))
{
i = 0;
if (EAGAIN == errno)
continue;
zabbix_log(LOG_LEVEL_DEBUG, "error writing to GSM modem: %s", zbx_strerror(errno));
if (NULL != error)
zbx_snprintf(error, max_error_len, "error writing to GSM modem: %s", zbx_strerror(errno));
ret = FAIL;
break;
}
}
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
return ret;
}
static int check_modem_result(char *buffer, char **ebuf, char **sbuf, const char *expect, char *error,
int max_error_len)
{
char rcv[0xff];
int i, len, ret = SUCCEED;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
zbx_strlcpy(rcv, *sbuf, sizeof(rcv));