diff --git a/src/emu/loom.c b/src/emu/loom.c index b1f54ef..7b9d99e 100644 --- a/src/emu/loom.c +++ b/src/emu/loom.c @@ -13,13 +13,16 @@ static void set_hostname(char host[PATH_MAX], const char name[PATH_MAX]) { + /* Skip prefix */ + const char *start = name + strlen("loom."); + /* Copy until dot or end */ int i; for (i = 0; i < PATH_MAX - 1; i++) { - if (name[i] == '.' || name[i] == '\0') + if (start[i] == '.' || start[i] == '\0') break; - host[i] = name[i]; + host[i] = start[i]; } host[i] = '\0'; diff --git a/test/unit/loom.c b/test/unit/loom.c index cd414e2..51377ff 100644 --- a/test/unit/loom.c +++ b/test/unit/loom.c @@ -34,6 +34,18 @@ test_bad_name(struct loom *loom) 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 test_negative_cpu(struct loom *loom) { @@ -125,6 +137,7 @@ int main(void) struct loom loom; test_bad_name(&loom); + test_hostname(&loom); test_negative_cpu(&loom); test_duplicate_cpus(&loom); //test_sort_cpus(&loom);