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 <mlichvar@redhat.com>
master
Miroslav Lichvar 2013-01-29 18:06:16 +01:00 committed by Richard Cochran
parent 4f866b2761
commit d28f7721de
4 changed files with 11 additions and 1 deletions

1
pmc.c
View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);