Skip to content

Commit

Permalink
Make LDMSD create a PID file only when a path is specified
Browse files Browse the repository at this point in the history
Without the patch, LDMSD always creates a PID file. It determines the
PID file location in the following order: the command-line option `-r`,
the environment variables `LDMSD_PIDFILE`, and the default path
`/var/run/ldmsd.pid`. Running LDMSD as a non-root user withput
specifying a PID file path always causes a permission-denied error
message because a non-root user cannot access `/var/run` directory.

The patch changes LDMSD so that it only create a PID file when either
the command-line option `-r` or the config command `pid_path` is
specified. Regarding starting LDMSD via `systemd`, `systemd` can be
configured to create a PID file for LDMSD.
  • Loading branch information
nichamon authored and tom95858 committed Mar 5, 2024
1 parent 2f1aa48 commit f6fbac6
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions ldms/src/ldmsd/ldmsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,38 +2208,24 @@ int main(int argc, char *argv[])
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) {
if( !access( pidfile, F_OK ) ) {
ovis_log(NULL, OVIS_LERROR, "Existing pid file named '%s': %s\n",
pidfile, "overwritten if writable");
}
if (!pidfile) {
ovis_log(NULL, OVIS_LERROR, "Out of memory\n");
av_free(auth_opt);
exit(1);
FILE *pfile = fopen_perm(pidfile,"w", LDMSD_DEFAULT_FILE_PERM);
if (!pfile) {
int piderr = errno;
ovis_log(NULL, OVIS_LERROR, "Could not open the pid file named '%s': %s\n",
pidfile, STRERROR(piderr));
free(pidfile);
pidfile = NULL;
} else {
pid_t mypid = getpid();
fprintf(pfile,"%ld\n",(long)mypid);
fclose(pfile);
}
}
if( !access( pidfile, F_OK ) ) {
ovis_log(NULL, OVIS_LERROR, "Existing pid file named '%s': %s\n",
pidfile, "overwritten if writable");
}
FILE *pfile = fopen_perm(pidfile,"w", LDMSD_DEFAULT_FILE_PERM);
if (!pfile) {
int piderr = errno;
ovis_log(NULL, OVIS_LERROR, "Could not open the pid file named '%s': %s\n",
pidfile, STRERROR(piderr));
free(pidfile);
pidfile = NULL;
} else {
pid_t mypid = getpid();
fprintf(pfile,"%ld\n",(long)mypid);
fclose(pfile);
}
if (pidfile && banner) {
char *suffix = ".version";
bannerfile = malloc(strlen(suffix)+strlen(pidfile)+1);
Expand Down

0 comments on commit f6fbac6

Please sign in to comment.