diff --git a/include/villas/super_node.h b/include/villas/super_node.h index bcd4169f2..064c31cc9 100644 --- a/include/villas/super_node.h +++ b/include/villas/super_node.h @@ -46,13 +46,8 @@ struct super_node { char *name; /**< A name of this super node. Usually the hostname. */ - struct { - int argc; - char **argv; - } cli; - enum state state; - + char *uri; /**< URI of configuration */ json_t *cfg; /**< JSON representation of the configuration. */ @@ -66,9 +61,6 @@ struct super_node { /** Inititalize configuration object before parsing the configuration. */ int super_node_init(struct super_node *sn); -/** Wrapper for super_node_parse() */ -int super_node_parse_cli(struct super_node *sn, int argc, char *argv[]); - /** Wrapper for super_node_parse() */ int super_node_parse_uri(struct super_node *sn, const char *uri); diff --git a/include/villas/utils.h b/include/villas/utils.h index 8c097e691..9f405931d 100644 --- a/include/villas/utils.h +++ b/include/villas/utils.h @@ -135,9 +135,12 @@ /* Forward declarations */ struct timespec; -/** Print copyright message to screen. */ +/** Print copyright message to stdout. */ void print_copyright(); +/** Print version to stdout. */ +void print_version(); + /** Normal random variate generator using the Box-Muller method * * @param m Mean diff --git a/lib/nodes/opal.c b/lib/nodes/opal.c index e48004be9..9b7aa5a98 100644 --- a/lib/nodes/opal.c +++ b/lib/nodes/opal.c @@ -41,6 +41,13 @@ static Opal_GenAsyncParam_Ctrl params; /** String and Float parameters, provided static pthread_mutex_t lock; /** Big Global Lock for libOpalAsync API */ +int opal_register_region(int argc, char *argv[]) +{ + async_shmem_name = argv[1]; + async_shmem_size = atoi(argv[2]); + print_shmem_name = argv[3]; +} + int opal_init(struct super_node *sn) { int err; @@ -50,10 +57,6 @@ int opal_init(struct super_node *sn) pthread_mutex_init(&lock, NULL); - async_shmem_name = sn->cli.argv[1]; - async_shmem_size = atoi(sn->cli.argv[2]); - print_shmem_name = sn->cli.argv[3]; - /* Enable the OpalPrint function. This prints to the OpalDisplay. */ err = OpalSystemCtrl_Register(print_shmem_name); if (err != EOK) diff --git a/lib/super_node.c b/lib/super_node.c index 99b3c26ba..6ab3ce01f 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -169,16 +169,6 @@ int super_node_parse_uri(struct super_node *sn, const char *uri) return 0; } -int super_node_parse_cli(struct super_node *sn, int argc, char *argv[]) -{ - char *uri = (argc == 2) ? argv[1] : NULL; - - sn->cli.argc = argc; - sn->cli.argv = argv; - - return super_node_parse_uri(sn, uri); -} - int super_node_parse_json(struct super_node *sn, json_t *cfg) { int ret; diff --git a/lib/utils.c b/lib/utils.c index 7239beb63..e7feacd24 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -44,6 +44,11 @@ void print_copyright() printf(" Steffen Vogel \n"); } +void print_version() +{ + printf("%s\n", BUILDID); +} + int version_parse(const char *s, struct version *v) { return sscanf(s, "%u.%u", &v->major, &v->minor) != 2; diff --git a/src/fpga.c b/src/fpga.c index 793c01f88..2f7d4f853 100644 --- a/src/fpga.c +++ b/src/fpga.c @@ -30,7 +30,9 @@ void usage() printf(" CONFIG path to a configuration file\n"); printf(" CARD name of the FPGA card\n"); printf(" OPTIONS is one or more of the following options:\n"); - printf(" -d Set log level\n"); + printf(" -d set log level\n"); + printf(" -h show this help\n"); + printf(" -V show the version of the tool\n"); printf("\n"); print_copyright(); } @@ -44,12 +46,16 @@ int main(int argc, char *argv[]) /* Parse arguments */ char c, *endptr; - while ((c = getopt(argc, argv, "d:")) != -1) { + while ((c = getopt(argc, argv, "Vd:h")) != -1) { switch (c) { + case 'V': + print_version(); + exit(EXIT_SUCCESS); case 'd': sn.log.level = strtoul(optarg, &endptr, 10); goto check; + case 'h': case '?': default: usage(); diff --git a/src/hook.c b/src/hook.c index da555d270..1d6838cf9 100644 --- a/src/hook.c +++ b/src/hook.c @@ -83,9 +83,10 @@ static void usage() printf(" PARAM* a string of configuration settings for the hook\n"); printf(" OPTIONS is one or more of the following options:\n"); printf(" -f FMT the data format\n"); - printf(" -h show this help\n"); printf(" -d LVL set debug level to LVL\n"); printf(" -v CNT process CNT smps at once\n"); + printf(" -h show this help\n"); + printf(" -V show the version of the tool\n"); printf("\n"); printf("The following hook functions are supported:\n"); @@ -114,8 +115,11 @@ int main(int argc, char *argv[]) json_t *cfg_cli = json_object(); char c, *endptr; - while ((c = getopt(argc, argv, "hv:d:f:o:")) != -1) { + while ((c = getopt(argc, argv, "Vhv:d:f:o:")) != -1) { switch (c) { + case 'V': + print_version(); + exit(EXIT_SUCCESS); case 'f': format = optarg; break; diff --git a/src/node.c b/src/node.c index 7d0515146..b399b5ced 100644 --- a/src/node.c +++ b/src/node.c @@ -66,7 +66,10 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) static void usage() { - printf("Usage: villas-node [CONFIG]\n"); + printf("Usage: villas-node [OPTIONS] [CONFIG]\n"); + printf(" OPTIONS is one or more of the following options:\n"); + printf(" -V show the version of the tool\n"); + printf(" -h show this help\n"); printf(" CONFIG is the path to an optional configuration file\n"); printf(" if omitted, VILLASnode will start without a configuration\n"); printf(" and wait for provisioning over the web interface.\n\n"); @@ -106,16 +109,28 @@ int main(int argc, char *argv[]) if (argc != 4) usage(argv[0]); + opal_register_region(argc, argv); + char *uri = "opal-shmem.conf"; #else - if (argc == 2) { - if (!strcmp(argv[1], "-h") || - !strcmp(argv[1], "--help")) - usage(); + char c; + while ((c = getopt(argc, argv, "hV")) != -1) { + switch (c) { + case 'V': + print_version(); + exit(EXIT_SUCCESS); + case 'h': + case '?': + usage(); + exit(c == '?' ? EXIT_FAILURE : EXIT_SUCCESS); + } + + continue; } - else if (argc > 2) - usage(); + + char *uri = argc == optind + 1 ? argv[optind] : NULL; #endif + info("This is VILLASnode %s (built on %s, %s)", CLR_BLD(CLR_YEL(BUILDID)), CLR_BLD(CLR_MAG(__DATE__)), CLR_BLD(CLR_MAG(__TIME__))); @@ -134,7 +149,7 @@ int main(int argc, char *argv[]) if (ret) error("Failed to initialize super node"); - ret = super_node_parse_cli(&sn, argc, argv); + ret = super_node_parse_uri(&sn, uri); if (ret) error("Failed to parse command line arguments"); diff --git a/src/pipe.c b/src/pipe.c index 44052f704..735964928 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -99,7 +99,8 @@ static void usage() printf(" -r only read data from node and write it to stdout\n"); printf(" -t NUM terminate after NUM seconds\n"); printf(" -L NUM terminate after NUM samples sent\n"); - printf(" -l NUM terminate after NUM samples received\n\n"); + printf(" -l NUM terminate after NUM samples received\n"); + printf(" -V show the version of the tool\n\n"); print_copyright(); } @@ -216,8 +217,11 @@ int main(int argc, char *argv[]) json_t *cfg_cli = json_object(); char c, *endptr; - while ((c = getopt(argc, argv, "hxrsd:l:L:t:f:o:")) != -1) { + while ((c = getopt(argc, argv, "Vhxrsd:l:L:t:f:o:")) != -1) { switch (c) { + case 'V': + print_version(); + exit(EXIT_SUCCESS); case 'f': format = optarg; break;