Skip to content

Commit

Permalink
...G...... [ZBX-21560] fixed default Zabbix agent 1 and 2 config file…
Browse files Browse the repository at this point in the history
… name and path for Windows; fixed logging to stderr in Zabbix agent 2[ZBX-21560] fixed default Zabbix agent 1 and 2 config file name and path for Windows; fixed logging to stderr in Zabbix agent 2

* commit 'f43aea924d5db923078a597a70aaa831811cf4fb':
  ...G...... [ZBX-21560] added info about conf full path to help message
  ...G...... [ZBX-21560] refactored conf path creation
  ...G...... [ZBX-21560] fixed problem with path to Zabbix agent containing directory zabbix_agentd.exe, removed redundant memory buffer
  ...G...... [ZBX-21560] fixed default Zabbix agent 1 and 2 config file name and path for Windows; fixed logging to stderr in Zabbix agent 2
  • Loading branch information
Mihails Prihodko committed Aug 31, 2023
2 parents 67087e9 + f43aea9 commit 195b272
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 10 deletions.
1 change: 1 addition & 0 deletions ChangeLog.d/bugfix/ZBX-21560
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
...G...... [ZBX-21560] fixed default Zabbix agent 1 and 2 config file name and path for Windows; fixed logging to stderr in Zabbix agent 2 (mprihodko)
2 changes: 1 addition & 1 deletion include/zbxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ extern const char *help_message[];

#define ARRSIZE(a) (sizeof(a) / sizeof(*a))

void zbx_help(void);
void zbx_help(const char *param);
void zbx_usage(void);
void zbx_version(void);

Expand Down
3 changes: 2 additions & 1 deletion src/go/cmd/zabbix_agent2/zabbix_agent2.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,11 @@ func fatalExit(message string, err error) {
message = fmt.Sprintf("%s: %s", message, err.Error())
}

fmt.Fprintf(os.Stderr, "zabbix_agent2 [%d]: ERROR: %s\n", os.Getpid(), message)

if agent.Options.LogType == "file" {
log.Critf("%s", message)
}

fmt.Fprintf(os.Stderr, "zabbix_agent2 [%d]: ERROR: %s\n", os.Getpid(), message)
os.Exit(1)
}
2 changes: 1 addition & 1 deletion src/go/cmd/zabbix_agent2/zabbix_agent2_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func loadOSDependentItems() error {
func init() {
if path, err := os.Executable(); err == nil {
dir, name := filepath.Split(path)
confDefault = dir + strings.TrimSuffix(name, filepath.Ext(name)) + ".win.conf"
confDefault = dir + strings.TrimSuffix(name, filepath.Ext(name)) + ".conf"
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/libs/zbxcommon/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**/

#include "zbxcommon.h"
#include "zbxstr.h"

const int INTERFACE_TYPE_PRIORITY[INTERFACE_TYPE_COUNT] =
{
Expand Down Expand Up @@ -296,19 +297,33 @@ static const char help_message_footer[] =
* Purpose: print help of application parameters on stdout by application *
* request with parameter '-h' *
* *
* Parameters: param - pointer to modification parameter *
* *
* Comments: help_message - is global variable which must be initialized *
* in each zabbix application *
* *
******************************************************************************/
void zbx_help(void)
void zbx_help(const char *param)
{
const char **p = help_message;

zbx_usage();
printf("\n");

while (NULL != *p)
{
if (NULL != param && NULL != strstr(*p, "{DEFAULT_CONFIG_FILE}"))
{
char *ptr;

ptr = zbx_string_replace(*p++, "{DEFAULT_CONFIG_FILE}", param);
printf("%s\n", ptr);
zbx_free(ptr);
continue;
}

printf("%s\n", *p++);
}

printf("\n");
puts(help_message_footer);
Expand Down
42 changes: 41 additions & 1 deletion src/zabbix_agent/zabbix_agentd.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ const char *help_message[] = {
"",
"Options:",
" -c --config config-file Path to the configuration file",
#ifdef _WINDOWS
" (default: \"{DEFAULT_CONFIG_FILE}\")",
#else
" (default: \"" DEFAULT_CONFIG_FILE "\")",
#endif
" -f --foreground Run Zabbix agent in foreground",
" -p --print Print known items and exit",
" -t --test item-key Test specified item and exit",
Expand Down Expand Up @@ -379,7 +383,12 @@ static int parse_commandline(int argc, char **argv, ZBX_TASK_EX *t)
#endif
case 'h':
t->task = ZBX_TASK_SHOW_HELP;
#ifdef _WINDOWS
goto cf_out;
#else
goto out;
#endif

case 'V':
t->task = ZBX_TASK_SHOW_VERSION;
goto out;
Expand Down Expand Up @@ -545,6 +554,37 @@ static int parse_commandline(int argc, char **argv, ZBX_TASK_EX *t)
goto out;
}

#ifdef _WINDOWS
#define PATH_BUF_LEN 4096
cf_out:
if (NULL == config_file)
{
char *ptr, *process_path = NULL;
wchar_t szProcessName[PATH_BUF_LEN];

if (0 == GetModuleFileNameEx(GetCurrentProcess(), NULL, szProcessName, ARRSIZE(szProcessName)))
{
zbx_error("failed to get Zabbix agent executable file path while initializing default config"
" path");
goto skip;
}

process_path = zbx_unicode_to_utf8(szProcessName);

if (NULL == (ptr = get_program_name(process_path)))
{
zbx_error("got unexpected Zabbix agent executable file path '%s' while initializing"
" default config path", ptr);
goto skip;
}

*ptr = '\0';
config_file = zbx_dsprintf(config_file, "%s%s", process_path, get_program_name(DEFAULT_CONFIG_FILE));
skip:
zbx_free(process_path);
}
#undef PATH_BUF_LEN
#endif
if (NULL == config_file)
config_file = zbx_strdup(NULL, DEFAULT_CONFIG_FILE);
out:
Expand Down Expand Up @@ -1590,7 +1630,7 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case ZBX_TASK_SHOW_HELP:
zbx_help();
zbx_help(config_file);
exit(EXIT_SUCCESS);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/zabbix_get/zabbix_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ int main(int argc, char **argv)
}
break;
case 'h':
zbx_help();
zbx_help(NULL);
exit(EXIT_SUCCESS);
case 'V':
zbx_version();
Expand Down
2 changes: 1 addition & 1 deletion src/zabbix_js/zabbix_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int main(int argc, char **argv)

break;
case 'h':
zbx_help();
zbx_help(NULL);
ret = SUCCEED;
goto clean;
case 'V':
Expand Down
2 changes: 1 addition & 1 deletion src/zabbix_proxy/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ int main(int argc, char **argv)
t.task = ZBX_TASK_RUNTIME_CONTROL;
break;
case 'h':
zbx_help();
zbx_help(NULL);
exit(EXIT_SUCCESS);
break;
case 'V':
Expand Down
2 changes: 1 addition & 1 deletion src/zabbix_sender/zabbix_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ static void parse_commandline(int argc, char **argv)
config_file = zbx_strdup(config_file, zbx_optarg);
break;
case 'h':
zbx_help();
zbx_help(NULL);
exit(EXIT_SUCCESS);
case 'V':
zbx_version();
Expand Down
2 changes: 1 addition & 1 deletion src/zabbix_server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ int main(int argc, char **argv)
t.task = ZBX_TASK_RUNTIME_CONTROL;
break;
case 'h':
zbx_help();
zbx_help(NULL);
exit(EXIT_SUCCESS);
break;
case 'V':
Expand Down

0 comments on commit 195b272

Please sign in to comment.