From d28f7721de44fd3a499e2ba53d3cbdbc1df87d5f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 29 Jan 2013 18:06:16 +0100 Subject: [PATCH] Set program name for print(). The printing facility is used by different programs, allow to set the program name which prefixes the messages written to stdout. Signed-off-by: Miroslav Lichvar --- pmc.c | 1 + print.c | 9 ++++++++- print.h | 1 + ptp4l.c | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pmc.c b/pmc.c index 3fe0be7..3d8ed68 100644 --- a/pmc.c +++ b/pmc.c @@ -553,6 +553,7 @@ int main(int argc, char *argv[]) pollfd[1].fd = fdarray.fd[FD_GENERAL]; pollfd[1].events = POLLIN|POLLPRI; + print_set_progname(progname); print_set_syslog(1); print_set_verbose(1); diff --git a/print.c b/print.c index 069cec6..7c21902 100644 --- a/print.c +++ b/print.c @@ -27,6 +27,12 @@ static int verbose = 0; static int print_level = LOG_INFO; static int use_syslog = 1; +static const char *progname; + +void print_set_progname(const char *name) +{ + progname = name; +} void print_set_syslog(int value) { @@ -59,7 +65,8 @@ void print(int level, char const *format, ...) va_end(ap); if (verbose) { - fprintf(stdout, "ptp4l[%ld.%03ld]: %s\n", + fprintf(stdout, "%s[%ld.%03ld]: %s\n", + progname ? progname : "", ts.tv_sec, ts.tv_nsec / 1000000, buf); fflush(stdout); } diff --git a/print.h b/print.h index d85b26f..56b2104 100644 --- a/print.h +++ b/print.h @@ -27,6 +27,7 @@ void print(int level, char const *format, ...); +void print_set_progname(const char *name); void print_set_syslog(int value); void print_set_level(int level); void print_set_verbose(int value); diff --git a/ptp4l.c b/ptp4l.c index f486516..345fa4f 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -246,6 +246,7 @@ int main(int argc, char *argv[]) ds->clockQuality.clockClass = 255; } + print_set_progname(progname); print_set_verbose(cfg_settings.verbose); print_set_syslog(cfg_settings.use_syslog); print_set_level(cfg_settings.print_level);