From e2b0b25a7dfd9c6b61cb036cf6021fecafe4787e Mon Sep 17 00:00:00 2001 From: Nichamon Naksinehaboon Date: Wed, 21 Feb 2024 13:21:30 -0600 Subject: [PATCH] Add pid_file configuration command The `pid_file` configuration command is an alternative approach to set the PID file path in configuration file to the `-r` command-line option. --- ldms/src/ldmsd/ldmsd_request.c | 31 +++++++++++++++++++++++++++++ ldms/src/ldmsd/ldmsd_request.h | 1 + ldms/src/ldmsd/ldmsd_request_util.c | 1 + 3 files changed, 33 insertions(+) diff --git a/ldms/src/ldmsd/ldmsd_request.c b/ldms/src/ldmsd/ldmsd_request.c index fe26be957..654a10df2 100644 --- a/ldms/src/ldmsd/ldmsd_request.c +++ b/ldms/src/ldmsd/ldmsd_request.c @@ -312,6 +312,7 @@ 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); /* executable for all */ #define XALL 0111 @@ -679,6 +680,9 @@ static struct request_handler_entry request_handler[] = { [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 + }, }; int is_req_id_priority(enum ldmsd_request req_id) @@ -697,6 +701,7 @@ int is_req_id_priority(enum ldmsd_request req_id) case LDMSD_DAEMON_NAME_SET_REQ: case LDMSD_WORKER_THR_SET_REQ: case LDMSD_DEFAULT_CREDITS_REQ: + case LDMSD_PID_FILE_REQ: return 1; default: return 0; @@ -9267,3 +9272,29 @@ static int default_credits_set_handler(ldmsd_req_ctxt_t reqc) 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; +} diff --git a/ldms/src/ldmsd/ldmsd_request.h b/ldms/src/ldmsd/ldmsd_request.h index 6e85dcc9c..047ef1c79 100644 --- a/ldms/src/ldmsd/ldmsd_request.h +++ b/ldms/src/ldmsd/ldmsd_request.h @@ -153,6 +153,7 @@ enum ldmsd_request { LDMSD_DAEMON_NAME_SET_REQ, LDMSD_WORKER_THR_SET_REQ, LDMSD_DEFAULT_CREDITS_REQ, + LDMSD_PID_FILE_REQ, /* failover requests by user */ LDMSD_FAILOVER_CONFIG_REQ = 0x700, /* "failover_config" user command */ diff --git a/ldms/src/ldmsd/ldmsd_request_util.c b/ldms/src/ldmsd/ldmsd_request_util.c index 9966c4843..4d779f449 100644 --- a/ldms/src/ldmsd/ldmsd_request_util.c +++ b/ldms/src/ldmsd/ldmsd_request_util.c @@ -98,6 +98,7 @@ const struct req_str_id req_str_id_table[] = { { "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 },