-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup LDMSD's command-line options #1369
Changes from all commits
d57eb39
98308f8
0e86bf1
1e7e6ca
6f20aa6
820992a
d3f1d3b
6e8b776
5e29983
8f5de72
d0b7f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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=<KERNEL_FILE> 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=<DAEMON_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=<NUMBER OF THREADS> 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=<INTEGER> 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nichamon, @valleydlr do we need this message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this message could be helpful in identifying misconfiguration of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nichamon, I think this is reasonable. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nichamon, @valleydlr did we talk about getting rid of this banner file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the spreadsheet we went over together in Austin (I left early), it was decided to remove the command-line option There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @valleydlr, do you want to retain the Banner file? |
||
#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); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nichamon can you elaborate on this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the comment, when I refactored LDMSD to use the
ovis_log
library, as a reminder to find a better way for admins to change the time format of log messages from date-time to timestamp. Currently, admins can configure LDMSD to use timestamps in seconds from the epoch in log messages by setting the environment variableLDMSD_LOG_TIME_SEC
. I wasn't a fan of this approach because it is hard to use.Since I introduce this, there haven't been any use cases. Here are two path forwards:
log_file
config command fromlog_file path=<log file path>
to
log dest=<log file path> [time_format=<date-time|timestamp|none>]
.The
ovis_log
library supports the three modes: date-time (LDMSD default), timestamp in second from epoch, and no time information. Beside modifying the config command, I would remove the logic to get the time format from the environment. The only way to change the time format in LDMSD's log messages is to use the config command `log.What do you think?