Skip to content

Commit

Permalink
Add pid_file configuration command
Browse files Browse the repository at this point in the history
The `pid_file` configuration command is an alternative approach to set
the PID file path in configuration file to the `-r` command-line option.
  • Loading branch information
nichamon authored and tom95858 committed Mar 5, 2024
1 parent 62b0d0b commit e2b0b25
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ldms/src/ldmsd/ldmsd_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions ldms/src/ldmsd/ldmsd_request_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit e2b0b25

Please sign in to comment.