Skip to content

Commit

Permalink
Default Hirte Agent NodeName to hostname (#245)
Browse files Browse the repository at this point in the history
If the user does not specify a NodeName in the
agent config, then hirte-agent should default to
the system's hostname.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan authored Apr 24, 2023
1 parent fe13307 commit a674768
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/agent/agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[hirte-agent]
#
# The unique name of this agent.
# It's mandatory to set this option for each hirte-agent.
# NodeName defaults the system's hostname.
NodeName=

#
Expand Down
2 changes: 1 addition & 1 deletion config/agent/hirte-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[hirte-agent]
#
# The unique name of this agent.
# It's mandatory to set this option for each hirte-agent.
# NodeName defaults the system's hostname.
NodeName=

#
Expand Down
3 changes: 1 addition & 2 deletions doc/man/hirte-agent.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ by `hirte-agent`.

#### **NodeName** (string)

The unique name of this agent. The option doesn't have a default value, it's mandatory to set this option for each
`hirte-agent`.
The unique name of this agent. The option defaults to the system's hostname.

#### **ManagerAddress** (string)

Expand Down
1 change: 1 addition & 0 deletions src/agent/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ Agent *agent_new(void) {
agent->connection_state = AGENT_CONNECTION_STATE_DISCONNECTED;
agent->connection_retry_count = 0;

agent->name = get_hostname();
return steal_pointer(&agent);
}

Expand Down
10 changes: 10 additions & 0 deletions src/libhirte/common/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ UnitActiveState active_state_from_string(const char *s) {
}
return _UNIT_ACTIVE_STATE_INVALID;
}

char *get_hostname() {
char hostname[BUFSIZ];
memset((char *) hostname, 0, sizeof(hostname));
if (gethostname(hostname, sizeof(hostname)) < 0) {
fprintf(stderr, "Warning failed to gethostname, error code '%s'.\n", strerror(-errno));
return "";
}
return strdup(hostname);
}
2 changes: 2 additions & 0 deletions src/libhirte/common/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ typedef enum UnitActiveState {
const char *active_state_to_string(UnitActiveState s);
UnitActiveState active_state_from_string(const char *s);

char *get_hostname();

/* Agent to Hirte heartbeat signals */

// Application-level heartbeat set at 2 seconds.
Expand Down

0 comments on commit a674768

Please sign in to comment.