Skip "loom." prefix from hostname

This commit is contained in:
Rodrigo Arias 2023-02-16 16:54:25 +01:00 committed by Rodrigo Arias Mallo
parent 28517c2000
commit 3da9e27190
2 changed files with 18 additions and 2 deletions

View File

@ -13,13 +13,16 @@
static void static void
set_hostname(char host[PATH_MAX], const char name[PATH_MAX]) set_hostname(char host[PATH_MAX], const char name[PATH_MAX])
{ {
/* Skip prefix */
const char *start = name + strlen("loom.");
/* Copy until dot or end */ /* Copy until dot or end */
int i; int i;
for (i = 0; i < PATH_MAX - 1; i++) { for (i = 0; i < PATH_MAX - 1; i++) {
if (name[i] == '.' || name[i] == '\0') if (start[i] == '.' || start[i] == '\0')
break; break;
host[i] = name[i]; host[i] = start[i];
} }
host[i] = '\0'; host[i] = '\0';

View File

@ -34,6 +34,18 @@ test_bad_name(struct loom *loom)
err("ok"); err("ok");
} }
static void
test_hostname(struct loom *loom)
{
if (loom_init_begin(loom, "loom.node1.blah") != 0)
die("loom_init_begin failed");
if (strcmp(loom->hostname, "node1") != 0)
die("wrong hostname: %s", loom->hostname);
err("ok");
}
static void static void
test_negative_cpu(struct loom *loom) test_negative_cpu(struct loom *loom)
{ {
@ -125,6 +137,7 @@ int main(void)
struct loom loom; struct loom loom;
test_bad_name(&loom); test_bad_name(&loom);
test_hostname(&loom);
test_negative_cpu(&loom); test_negative_cpu(&loom);
test_duplicate_cpus(&loom); test_duplicate_cpus(&loom);
//test_sort_cpus(&loom); //test_sort_cpus(&loom);