diff --git a/ldms/src/ldmsd/ldmsd.c b/ldms/src/ldmsd/ldmsd.c index 3bc682740..c94684ef1 100644 --- a/ldms/src/ldmsd/ldmsd.c +++ b/ldms/src/ldmsd/ldmsd.c @@ -135,7 +135,6 @@ char myname[512]; /* name to identify ldmsd */ /* DEFAULT: myhostname:port */ char myhostname[80]; char ldmstype[20]; -int foreground; int cfg_cntr = 0; pthread_t event_thread = (pthread_t)-1; char *logfile; @@ -277,7 +276,7 @@ void cleanup(int x, const char *reason) ldms = NULL; } - if (!foreground && pidfile) { + if (pidfile) { unlink(pidfile); free(pidfile); pidfile = NULL; @@ -289,10 +288,6 @@ void cleanup(int x, const char *reason) bannerfile = NULL; } } - if (pidfile) { - free(pidfile); - pidfile = NULL; - } ovis_log(NULL, OVIS_LALWAYS, "LDMSD_ cleanup end.\n"); @@ -1869,6 +1864,13 @@ int ldmsd_process_cmd_line_arg(char opt, char *value) max_mem_sz_str = strdup(value); if (!max_mem_sz_str) return ENOMEM; + max_mem_size = ovis_get_mem_size(max_mem_sz_str); + if (!max_mem_size) { + ovis_log(NULL, OVIS_LCRITICAL, + "Invalid memory size '%s'\n.", + max_mem_sz_str); + return EINVAL; + } } break; case 'c': @@ -2040,9 +2042,6 @@ int main(int argc, char *argv[]) opterr = 0; while ((op = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { switch (op) { - case 'F': - foreground = 1; - break; case 'u': if (check_arg("u", optarg, LO_NAME)) return 1; @@ -2070,6 +2069,36 @@ int main(int argc, char *argv[]) case 'c': /* Handle below */ break; + case 'k': + case 's': + ovis_log(NULL, OVIS_LCRIT, + "The options `-k` and `-s` are obsolete. " + "Please specify `publish_kernel path= in a configuration file.\n"); + cleanup(EINVAL, "Received an obsolete command-line option"); + case 'n': + ovis_log(NULL, OVIS_LCRIT, + "The option `-n` is obsolete. " + "Please specify `daemon_name name= in a configuration file.\n"); + cleanup(EINVAL, "Received an obsolete command-line option"); + case 'P': + ovis_log(NULL, OVIS_LCRIT, + "The option `-P` is obsolete. " + "Please specify `worker_threads num= in a configuration file.\n"); + cleanup(EINVAL, "Received an obsolete command-line option"); + case 'C': + ovis_log(NULL, OVIS_LCRIT, + "The option `-C` is obsolete. " + "Please specify `default_credits credits= in a configuration file.\n"); + cleanup(EINVAL, "Received an obsolete command-line option"); + case 'B': + ovis_log(NULL, OVIS_LCRIT, + "The option `-B` is obsolete. " + "Please specify `banner mode=<0|1|2>` in a configuration file."); + cleanup(EINVAL, "Received an obsolete command-line option"); + case 'F': + ovis_log(NULL, OVIS_LCRIT, + "The option `-F` is obsolete. "); + cleanup(EINVAL, "Received an obsolete command-line option"); default: ret = ldmsd_process_cmd_line_arg(op, optarg); if (ret) { @@ -2097,13 +2126,6 @@ int main(int argc, char *argv[]) exit(0); } - if (!foreground) { - if (daemon(1, 1)) { - perror("ldmsd: "); - cleanup(8, "daemon failed to start"); - } - } - /* * TODO: It should be a better way to get this information. */ @@ -2164,7 +2186,6 @@ int main(int argc, char *argv[]) if ((max_mem_size = ovis_get_mem_size(max_mem_sz_str)) == 0) { ovis_log(NULL, OVIS_LCRITICAL, "Invalid memory size '%s'. " "See the -m option.\n", max_mem_sz_str); - usage(argv); } if (ldms_init(max_mem_size)) { ovis_log(NULL, OVIS_LCRITICAL, "LDMS could not pre-allocate " @@ -2173,25 +2194,7 @@ int main(int argc, char *argv[]) exit(1); } - if (!foreground) { - /* Create pidfile for daemon that usually goes away on exit. */ - /* user arg, then env, then default to get pidfile name */ - if (!pidfile) { - char *pidpath = getenv("LDMSD_PIDFILE"); - if (!pidpath) { - pidfile = malloc(strlen(LDMSD_PIDFILE_FMT) - + strlen(basename(argv[0]) + 1)); - if (pidfile) - sprintf(pidfile, LDMSD_PIDFILE_FMT, basename(argv[0])); - } else { - pidfile = strdup(pidpath); - } - if (!pidfile) { - ovis_log(NULL, OVIS_LERROR, "Out of memory\n"); - av_free(auth_opt); - exit(1); - } - } + if (pidfile) { if( !access( pidfile, F_OK ) ) { ovis_log(NULL, OVIS_LERROR, "Existing pid file named '%s': %s\n", pidfile, "overwritten if writable"); @@ -2208,27 +2211,28 @@ int main(int argc, char *argv[]) fprintf(pfile,"%ld\n",(long)mypid); fclose(pfile); } - if (pidfile && banner) { - char *suffix = ".version"; - bannerfile = malloc(strlen(suffix)+strlen(pidfile)+1); - if (!bannerfile) { - ovis_log(NULL, OVIS_LCRITICAL, "Memory allocation failure.\n"); - av_free(auth_opt); - exit(1); - } - sprintf(bannerfile, "%s%s", pidfile, suffix); - if( !access( bannerfile, F_OK ) ) { - ovis_log(NULL, OVIS_LERROR, "Existing banner file named '%s': %s\n", - bannerfile, "overwritten if writable"); - } - FILE *bfile = fopen_perm(bannerfile,"w", LDMSD_DEFAULT_FILE_PERM); - if (!bfile) { - int banerr = errno; - ovis_log(NULL, OVIS_LERROR, "Could not open the banner file named '%s': %s\n", - bannerfile, STRERROR(banerr)); - free(bannerfile); - bannerfile = NULL; - } else { + } + if (pidfile && banner) { + char *suffix = ".version"; + bannerfile = malloc(strlen(suffix)+strlen(pidfile)+1); + if (!bannerfile) { + ovis_log(NULL, OVIS_LCRITICAL, "Memory allocation failure.\n"); + av_free(auth_opt); + exit(1); + } + sprintf(bannerfile, "%s%s", pidfile, suffix); + if( !access( bannerfile, F_OK ) ) { + ovis_log(NULL, OVIS_LERROR, "Existing banner file named '%s': %s\n", + bannerfile, "overwritten if writable"); + } + FILE *bfile = fopen_perm(bannerfile,"w", LDMSD_DEFAULT_FILE_PERM); + if (!bfile) { + int banerr = errno; + ovis_log(NULL, OVIS_LERROR, "Could not open the banner file named '%s': %s\n", + bannerfile, STRERROR(banerr)); + free(bannerfile); + bannerfile = NULL; + } else { #define BANNER_PART1_A "Started LDMS Daemon with authentication " #define BANNER_PART1_NOA "Started LDMS Daemon without authentication " @@ -2241,13 +2245,12 @@ int main(int argc, char *argv[]) ldms_version.flags, OVIS_GIT_LONG #if OVIS_LDMS_HAVE_AUTH - fprintf(bfile, BANNER_PART1_A + fprintf(bfile, BANNER_PART1_A #else /* OVIS_LDMS_HAVE_AUTH */ - fprintf(bfile, BANNER_PART1_NOA + fprintf(bfile, BANNER_PART1_NOA #endif /* OVIS_LDMS_HAVE_AUTH */ - BANNER_PART2); - fclose(bfile); - } + BANNER_PART2); + fclose(bfile); } } diff --git a/ldms/src/ldmsd/ldmsd_request.c b/ldms/src/ldmsd/ldmsd_request.c index 44be61795..5058ff65f 100644 --- a/ldms/src/ldmsd/ldmsd_request.c +++ b/ldms/src/ldmsd/ldmsd_request.c @@ -302,7 +302,18 @@ static int auth_add_handler(ldmsd_req_ctxt_t reqc); static int auth_del_handler(ldmsd_req_ctxt_t reqc); static int set_default_authz_handler(ldmsd_req_ctxt_t reqc); + +/* The handler of configuration that needs to the start-up time. */ static int cmd_line_arg_set_handler(ldmsd_req_ctxt_t reqc); +static int default_auth_handler(ldmsd_req_ctxt_t reqc); +static int set_memory_handler(ldmsd_req_ctxt_t reqc); +static int log_file_handler(ldmsd_req_ctxt_t reqc); +static int publish_kernel_handler(ldmsd_req_ctxt_t reqc); +static int daemon_name_set_handler(ldmsd_req_ctxt_t reqc); +static int worker_threads_set_handler(ldmsd_req_ctxt_t reqc); +static int default_credits_set_handler(ldmsd_req_ctxt_t reqc); +static int pid_file_handler(ldmsd_req_ctxt_t reqc); +static int banner_mode_handler(ldmsd_req_ctxt_t reqc); /* executable for all */ #define XALL 0111 @@ -649,6 +660,33 @@ static struct request_handler_entry request_handler[] = { [LDMSD_CMDLINE_OPTIONS_SET_REQ] = { LDMSD_CMDLINE_OPTIONS_SET_REQ, cmd_line_arg_set_handler, XUG }, + [LDMSD_DEFAULT_AUTH_REQ] = { + LDMSD_DEFAULT_AUTH_REQ, default_auth_handler, XUG + }, + [LDMSD_MEMORY_REQ] = { + LDMSD_MEMORY_REQ, set_memory_handler, XUG + }, + [LDMSD_LOG_FILE_REQ] = { + LDMSD_LOG_FILE_REQ, log_file_handler, XUG + }, + [LDMSD_PUBLISH_KERNEL_REQ] = { + LDMSD_PUBLISH_KERNEL_REQ, publish_kernel_handler, XUG + }, + [LDMSD_DAEMON_NAME_SET_REQ] = { + LDMSD_DAEMON_NAME_SET_REQ, daemon_name_set_handler, XUG + }, + [LDMSD_WORKER_THR_SET_REQ] = { + LDMSD_WORKER_THR_SET_REQ, worker_threads_set_handler, XUG + }, + [LDMSD_DEFAULT_CREDITS_REQ] = { + LDMSD_DEFAULT_CREDITS_REQ, default_credits_set_handler, XUG + }, + [LDMSD_PID_FILE_REQ] = { + LDMSD_PID_FILE_REQ, pid_file_handler, XUG + }, + [LDMSD_BANNER_MODE_REQ] = { + LDMSD_BANNER_MODE_REQ, banner_mode_handler, XUG + }, }; int is_req_id_priority(enum ldmsd_request req_id) @@ -660,6 +698,15 @@ int is_req_id_priority(enum ldmsd_request req_id) case LDMSD_AUTH_ADD_REQ: case LDMSD_CMDLINE_OPTIONS_SET_REQ: case LDMSD_INCLUDE_REQ: + case LDMSD_DEFAULT_AUTH_REQ: + case LDMSD_MEMORY_REQ: + case LDMSD_LOG_FILE_REQ: + case LDMSD_PUBLISH_KERNEL_REQ: + case LDMSD_DAEMON_NAME_SET_REQ: + case LDMSD_WORKER_THR_SET_REQ: + case LDMSD_DEFAULT_CREDITS_REQ: + case LDMSD_PID_FILE_REQ: + case LDMSD_BANNER_MODE_REQ: return 1; default: return 0; @@ -9031,3 +9078,251 @@ static int stats_reset_handler(ldmsd_req_ctxt_t reqc) ldmsd_send_req_response(reqc, reqc->line_buf); return rc; } + +static int default_auth_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *plugin_name, *auth_attr; + plugin_name = auth_attr = NULL; + + reqc->errcode = 0; + + plugin_name = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_PLUGIN); + if (!plugin_name) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'plugin' is missing."); + goto send_reply; + } + + auth_attr = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_STRING); + + reqc->errcode = ldmsd_process_cmd_line_arg('a', plugin_name); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to process 'default_auth'."); + goto send_reply; + } + + if (auth_attr) { + reqc->errcode = ldmsd_process_cmd_line_arg('A', auth_attr); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to process the default auth attributes."); + goto send_reply; + } + } + +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(plugin_name); + free(auth_attr); + return rc; +} + +static int set_memory_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *value = NULL; + + value = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_SIZE); + if (!value) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'size' is missing."); + goto send_reply; + } + + reqc->errcode = ldmsd_process_cmd_line_arg('m', value); + if (reqc->errcode) { + snprintf(reqc->line_buf, reqc->line_len, + "The given value '%s' is invalid.", + value); + goto send_reply; + } + +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(value); + return rc; +} + +static int log_file_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *path = NULL; + + path = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_PATH); + if (!path) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'path' is missing."); + goto send_reply; + } + + reqc->errcode = ldmsd_process_cmd_line_arg('l', path); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to open the log file '%s'.", path); + goto send_reply; + } + +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(path); + return rc; +} + +static int publish_kernel_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *path = NULL; + + path = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_PATH); + if (path) { + /* + * The kernel setfile will be opened later. + * The process will exit if it fails to open the setfile. + * See k_proc(). + */ + reqc->errcode = ldmsd_process_cmd_line_arg('s', path); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to process the kernel set file path '%s'.", path); + goto send_reply; + } + } + reqc->errcode = ldmsd_process_cmd_line_arg('k', NULL); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to config LDMSD to publish the kernel metrics."); + goto send_reply; + } + +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(path); + return rc; +} + +static int daemon_name_set_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *name = NULL; + + name = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_NAME); + if (!name) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'name' is missing."); + goto send_reply; + } + reqc->errcode = ldmsd_process_cmd_line_arg('n', name); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to process the `daemon_name` command."); + goto send_reply; + } + +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(name); + return rc; +} + +static int worker_threads_set_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *value = NULL; + + value = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_SIZE); + if (!value) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'num' is missing."); + goto send_reply; + } + reqc->errcode = ldmsd_process_cmd_line_arg('P', value); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to process the 'worker_threads' command"); + goto send_reply; + } +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(value); + return rc; +} + +static int default_credits_set_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *value = NULL; + + value = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_CREDITS); + if (!value) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'credits' is missing."); + goto send_reply; + } + reqc->errcode = ldmsd_process_cmd_line_arg('C', value); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to process the 'default_credits' command"); + goto send_reply; + } +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(value); + return rc; +} + +static int pid_file_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *path = NULL; + + path = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_PATH); + if (!path) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'path' is missing."); + goto send_reply; + } + + reqc->errcode = ldmsd_process_cmd_line_arg('r', path); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "Failed to open the log file '%s'.", path); + goto send_reply; + } + +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(path); + return rc; +} + +static int banner_mode_handler(ldmsd_req_ctxt_t reqc) +{ + int rc = 0; + char *mode_s = NULL; + mode_s = ldmsd_req_attr_str_value_get_by_id(reqc, LDMSD_ATTR_LEVEL); + if (!mode_s) { + reqc->errcode = EINVAL; + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The attribute 'mode' is missing."); + goto send_reply; + } + reqc->errcode = ldmsd_process_cmd_line_arg('B', mode_s); + if (reqc->errcode) { + reqc->line_off = snprintf(reqc->line_buf, reqc->line_len, + "The given banner mode '%s' is invalid.", mode_s); + goto send_reply; + } +send_reply: + ldmsd_send_req_response(reqc, reqc->line_buf); + free(mode_s); + return rc; +} diff --git a/ldms/src/ldmsd/ldmsd_request.h b/ldms/src/ldmsd/ldmsd_request.h index 258f2b8a2..4b96bc096 100644 --- a/ldms/src/ldmsd/ldmsd_request.h +++ b/ldms/src/ldmsd/ldmsd_request.h @@ -146,6 +146,15 @@ enum ldmsd_request { LDMSD_SET_SEC_MOD_REQ, LDMSD_LOG_STATUS_REQ, LDMSD_STATS_RESET_REQ, + LDMSD_DEFAULT_AUTH_REQ, + LDMSD_MEMORY_REQ, + LDMSD_LOG_FILE_REQ, + LDMSD_PUBLISH_KERNEL_REQ, + LDMSD_DAEMON_NAME_SET_REQ, + LDMSD_WORKER_THR_SET_REQ, + LDMSD_DEFAULT_CREDITS_REQ, + LDMSD_PID_FILE_REQ, + LDMSD_BANNER_MODE_REQ, /* failover requests by user */ LDMSD_FAILOVER_CONFIG_REQ = 0x700, /* "failover_config" user command */ @@ -234,6 +243,7 @@ enum ldmsd_request_attr { LDMSD_ATTR_CREDITS, LDMSD_ATTR_RX_RATE, LDMSD_ATTR_SUMMARY, + LDMSD_ATTR_SIZE, LDMSD_ATTR_LAST, }; diff --git a/ldms/src/ldmsd/ldmsd_request_util.c b/ldms/src/ldmsd/ldmsd_request_util.c index 09f2aa5b5..ad4f7422f 100644 --- a/ldms/src/ldmsd/ldmsd_request_util.c +++ b/ldms/src/ldmsd/ldmsd_request_util.c @@ -65,6 +65,7 @@ const struct req_str_id req_str_id_table[] = { /* This table need to be sorted by keyword for bsearch() */ { "auth_add", LDMSD_AUTH_ADD_REQ }, { "auth_del", LDMSD_AUTH_DEL_REQ }, + { "banner", LDMSD_BANNER_MODE_REQ }, { "bridge_add", LDMSD_BRIDGE_ADD_REQ }, { "bridge_del", LDMSD_PRDCR_DEL_REQ }, { "bridge_start", LDMSD_PRDCR_START_REQ }, @@ -72,7 +73,10 @@ const struct req_str_id req_str_id_table[] = { { "config", LDMSD_PLUGN_CONFIG_REQ }, { "daemon", LDMSD_DAEMON_STATUS_REQ }, { "daemon_exit", LDMSD_EXIT_DAEMON_REQ }, + { "daemon_name", LDMSD_DAEMON_NAME_SET_REQ }, { "daemon_status", LDMSD_DAEMON_STATUS_REQ }, + { "default_auth", LDMSD_DEFAULT_AUTH_REQ }, + { "default_credits", LDMSD_DEFAULT_CREDITS_REQ }, { "dump_cfg", LDMSD_DUMP_CFG_REQ }, { "env", LDMSD_ENV_REQ }, { "exit", LDMSD_EXIT_DAEMON_REQ }, @@ -86,13 +90,16 @@ const struct req_str_id req_str_id_table[] = { { "include", LDMSD_INCLUDE_REQ }, { "listen", LDMSD_LISTEN_REQ }, { "load", LDMSD_PLUGN_LOAD_REQ }, + { "log_file", LDMSD_LOG_FILE_REQ }, { "log_level", LDMSD_VERBOSE_REQ }, { "log_status", LDMSD_LOG_STATUS_REQ }, - { "loglevel", LDMSD_VERBOSE_REQ }, /* It is being deprecated. */ + { "loglevel", LDMSD_VERBOSE_REQ }, /* It is being deprecated. */ { "logrotate", LDMSD_LOGROTATE_REQ }, + { "memory", LDMSD_MEMORY_REQ }, { "metric_sets_default_authz", LDMSD_SET_DEFAULT_AUTHZ_REQ }, { "oneshot", LDMSD_ONESHOT_REQ }, { "option", LDMSD_CMDLINE_OPTIONS_SET_REQ }, + { "pid_file", LDMSD_PID_FILE_REQ }, { "plugn_sets", LDMSD_PLUGN_SETS_REQ }, { "plugn_status", LDMSD_PLUGN_STATUS_REQ }, { "prdcr_add", LDMSD_PRDCR_ADD_REQ }, @@ -108,6 +115,8 @@ const struct req_str_id req_str_id_table[] = { { "prdcr_stream_status",LDMSD_PRDCR_STREAM_STATUS_REQ }, { "prdcr_subscribe", LDMSD_PRDCR_SUBSCRIBE_REQ }, { "prdcr_unsubscribe", LDMSD_PRDCR_UNSUBSCRIBE_REQ }, + { "publish_kernel", LDMSD_PUBLISH_KERNEL_REQ }, + { "set_memory", LDMSD_MEMORY_REQ }, { "set_route", LDMSD_SET_ROUTE_REQ }, { "set_sec_mod", LDMSD_SET_SEC_MOD_REQ }, { "set_stats", LDMSD_SET_STATS_REQ }, @@ -147,6 +156,7 @@ const struct req_str_id req_str_id_table[] = { { "updtr_task", LDMSD_UPDTR_TASK_REQ }, { "usage", LDMSD_PLUGN_LIST_REQ }, { "version", LDMSD_VERSION_REQ }, + { "worker_threads", LDMSD_WORKER_THR_SET_REQ }, { "xprt_stats", LDMSD_XPRT_STATS_REQ }, }; @@ -169,7 +179,9 @@ const struct req_str_id attr_str_id_table[] = { { "level", LDMSD_ATTR_LEVEL }, { "match", LDMSD_ATTR_MATCH }, { "metric", LDMSD_ATTR_METRIC }, + { "mode", LDMSD_ATTR_LEVEL }, { "name", LDMSD_ATTR_NAME }, + { "num", LDMSD_ATTR_SIZE }, { "offset", LDMSD_ATTR_OFFSET }, { "path", LDMSD_ATTR_PATH }, { "peer_name", LDMSD_ATTR_PEER_NAME }, @@ -184,6 +196,7 @@ const struct req_str_id attr_str_id_table[] = { { "reset", LDMSD_ATTR_RESET }, { "rx_rate", LDMSD_ATTR_RX_RATE }, { "schema", LDMSD_ATTR_SCHEMA }, + { "size", LDMSD_ATTR_SIZE }, { "stream", LDMSD_ATTR_STREAM }, { "string", LDMSD_ATTR_STRING }, { "summary", LDMSD_ATTR_SUMMARY }, @@ -793,6 +806,68 @@ int __ldmsd_parse_bridge_add_req(struct ldmsd_parse_ctxt *ctxt) return rc; } +int __ldmsd_parse_default_auth_req(struct ldmsd_parse_ctxt *ctxt) +{ + char *av = ctxt->av; + size_t len = strlen(av); + size_t cnt = 0; + char *tmp, *name, *value, *ptr, *dummy; + int rc; + dummy = NULL; + tmp = malloc(len); + if (!tmp) { + rc = ENOMEM; + goto out; + } + av = strtok_r(av, __ldmsd_cfg_delim, &ptr); + while (av) { + ctxt->av = av; + dummy = strdup(av); + if (!dummy) { + rc = ENOMEM; + goto out; + } + __get_attr_name_value(dummy, &name, &value); + if (!name) { + /* av is neither attribute value nor keyword */ + rc = EINVAL; + goto out; + } + if (0 == strncmp(name, "plugin", 4)) { + /* Find the name attribute */ + rc = add_attr_from_attr_str(name, value, + &ctxt->request, + &ctxt->request_sz); + if (rc) + goto out; + } else { + /* Construct the other attribute into a ATTR_STRING */ + if (value) { + cnt += snprintf(&tmp[cnt], len - cnt, + "%s=%s ", name, value); + } else { + cnt += snprintf(&tmp[cnt], len - cnt, + "%s ", name); + } + } + av = strtok_r(NULL, __ldmsd_cfg_delim, &ptr); + free(dummy); + dummy = NULL; + } + tmp[cnt-1] = '\0'; /* Replace the last ' ' with '\0' */ + /* Add an attribute of type 'STRING' */ + rc = add_attr_from_attr_str(NULL, tmp, + &ctxt->request, + &ctxt->request_sz); +out: + if (tmp) + free(tmp); + if (dummy) + free(dummy); + return rc; +} + + struct ldmsd_req_array * ldmsd_parse_config_str(const char *cfg, uint32_t msg_no, size_t xprt_max_msg) { @@ -865,6 +940,9 @@ ldmsd_parse_config_str(const char *cfg, uint32_t msg_no, size_t xprt_max_msg) case LDMSD_BRIDGE_ADD_REQ: rc = __ldmsd_parse_bridge_add_req(&ctxt); break; + case LDMSD_DEFAULT_AUTH_REQ: + rc = __ldmsd_parse_default_auth_req(&ctxt); + break; default: rc = __ldmsd_parse_generic(&ctxt); break;