summaryrefslogtreecommitdiffstats
path: root/claim
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2023-07-26 19:55:53 +0300
committerGitHub <noreply@github.com>2023-07-26 19:55:53 +0300
commitcca0d2649c628a9fc4b9ee4502b501c821feac8b (patch)
treebf5b1e26e972666eb372dacc3f7ab54625f9314b /claim
parent85d122f8a6c4709943825c1fcf9bffa784bd5620 (diff)
detect the path the netdata-claim.sh script is in (#15556)
Diffstat (limited to 'claim')
-rw-r--r--claim/claim.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/claim/claim.c b/claim/claim.c
index 942dd6d73c..740d9bd89d 100644
--- a/claim/claim.c
+++ b/claim/claim.c
@@ -57,7 +57,8 @@ CLAIM_AGENT_RESPONSE claim_agent(const char *claiming_arguments, bool force, con
#ifndef DISABLE_CLOUD
int exit_code;
pid_t command_pid;
- char command_buffer[CLAIMING_COMMAND_LENGTH + 1];
+ char command_exec_buffer[CLAIMING_COMMAND_LENGTH + 1];
+ char command_line_buffer[CLAIMING_COMMAND_LENGTH + 1];
FILE *fp_child_output, *fp_child_input;
// This is guaranteed to be set early in main via post_conf_load()
@@ -76,42 +77,55 @@ CLAIM_AGENT_RESPONSE claim_agent(const char *claiming_arguments, bool force, con
if (proxy_type == PROXY_TYPE_SOCKS5 || proxy_type == PROXY_TYPE_HTTP)
snprintf(proxy_flag, CLAIMING_PROXY_LENGTH, "-proxy=\"%s\"", proxy_str);
- snprintfz(command_buffer,
+ snprintfz(command_exec_buffer, CLAIMING_COMMAND_LENGTH,
+ "exec \"%s%snetdata-claim.sh\"",
+ netdata_exe_path[0] ? netdata_exe_path : "",
+ netdata_exe_path[0] ? "/" : ""
+ );
+
+ snprintfz(command_line_buffer,
CLAIMING_COMMAND_LENGTH,
- "exec netdata-claim.sh %s -hostname=%s -id=%s -url=%s -noreload %s",
+ "%s %s -hostname=%s -id=%s -url=%s -noreload %s",
+ command_exec_buffer,
proxy_flag,
netdata_configured_hostname,
rrdb.localhost->machine_guid,
cloud_base_url,
claiming_arguments);
- netdata_log_info("Executing agent claiming command 'netdata-claim.sh'");
- fp_child_output = netdata_popen(command_buffer, &command_pid, &fp_child_input);
+ netdata_log_info("Executing agent claiming command: %s", command_exec_buffer);
+ fp_child_output = netdata_popen(command_line_buffer, &command_pid, &fp_child_input);
if(!fp_child_output) {
- netdata_log_error("Cannot popen(\"%s\").", command_buffer);
+ netdata_log_error("Cannot popen(\"%s\").", command_exec_buffer);
return CLAIM_AGENT_CANNOT_EXECUTE_CLAIM_SCRIPT;
}
- netdata_log_info("Waiting for claiming command to finish.");
- while (fgets(command_buffer, CLAIMING_COMMAND_LENGTH, fp_child_output) != NULL) {;}
+
+ netdata_log_info("Waiting for claiming command '%s' to finish.", command_exec_buffer);
+ char read_buffer[100 + 1];
+ while (fgets(read_buffer, 100, fp_child_output) != NULL) {;}
+
exit_code = netdata_pclose(fp_child_input, fp_child_output, command_pid);
- netdata_log_info("Agent claiming command returned with code %d", exit_code);
+
+ netdata_log_info("Agent claiming command '%s' returned with code %d", command_exec_buffer, exit_code);
if (0 == exit_code) {
load_claiming_state();
return CLAIM_AGENT_OK;
}
if (exit_code < 0) {
- netdata_log_error("Agent claiming command failed to complete its run.");
+ netdata_log_error("Agent claiming command '%s' failed to complete its run", command_exec_buffer);
return CLAIM_AGENT_CLAIM_SCRIPT_FAILED;
}
errno = 0;
unsigned maximum_known_exit_code = sizeof(claiming_errors) / sizeof(claiming_errors[0]) - 1;
if ((unsigned)exit_code > maximum_known_exit_code) {
- netdata_log_error("Agent failed to be claimed with an unknown error.");
+ netdata_log_error("Agent failed to be claimed with an unknown error. Cmd: '%s'", command_exec_buffer);
return CLAIM_AGENT_CLAIM_SCRIPT_RETURNED_INVALID_CODE;
}
- netdata_log_error("Agent failed to be claimed with the following error message:");
+ netdata_log_error("Agent failed to be claimed using the command '%s' with the following error message:",
+ command_exec_buffer);
+
netdata_log_error("\"%s\"", claiming_errors[exit_code]);
if(msg) *msg = claiming_errors[exit_code];