vhost: added option to save pid to file

Usage:
./vhost -f path/to/pidfile
A text file containing single pid number will be created

Change-Id: Ia7762ce3085400a47740c9a5f44b56d63c9fafc6
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/368518
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-07-07 12:56:04 +02:00 committed by Daniel Verkamp
parent 0d9842813f
commit 30c42b9b32

View File

@ -64,6 +64,7 @@ usage(char *executable_name)
printf("options:\n");
printf(" -c config config file (default: %s)\n", defaults.config_file);
printf(" -e mask tracepoint group mask for spdk trace buffers (default: 0x0)\n");
printf(" -f pidfile save pid to file under given path\n");
printf(" -m mask reactor core mask (default: 0x1)\n");
printf(" -n channel number of memory channels used for DPDK\n");
printf(" -p core master (primary) core for DPDK\n");
@ -75,6 +76,21 @@ usage(char *executable_name)
printf(" -q disable notice level logging to stderr\n");
}
static void
save_pid(const char *pid_path)
{
FILE *pid_file;
pid_file = fopen(pid_path, "w");
if (pid_file == NULL) {
fprintf(stderr, "Couldn't create pid file '%s': %s\n", pid_path, strerror(errno));
exit(EXIT_FAILURE);
}
fprintf(pid_file, "%d\n", getpid());
fclose(pid_file);
}
int
main(int argc, char *argv[])
{
@ -83,10 +99,11 @@ main(int argc, char *argv[])
int rc;
const char *socket_path = NULL;
enum spdk_log_level print_level = SPDK_LOG_NOTICE;
const char *pid_path = NULL;
vhost_app_opts_init(&opts);
while ((ch = getopt(argc, argv, "c:de:m:p:qs:S:t:h")) != -1) {
while ((ch = getopt(argc, argv, "c:de:f:m:p:qs:S:t:h")) != -1) {
switch (ch) {
case 'c':
opts.config_file = optarg;
@ -97,6 +114,9 @@ main(int argc, char *argv[])
case 'e':
opts.tpoint_group_mask = optarg;
break;
case 'f':
pid_path = optarg;
break;
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
@ -137,6 +157,10 @@ main(int argc, char *argv[])
}
}
if (pid_path) {
save_pid(pid_path);
}
if (print_level > SPDK_LOG_WARN &&
isatty(STDERR_FILENO) &&
!strncmp(ttyname(STDERR_FILENO), "/dev/tty", strlen("/dev/tty"))) {