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
parent
4f866b2761
commit
d28f7721de
1
pmc.c
1
pmc.c
|
@ -553,6 +553,7 @@ int main(int argc, char *argv[])
|
||||||
pollfd[1].fd = fdarray.fd[FD_GENERAL];
|
pollfd[1].fd = fdarray.fd[FD_GENERAL];
|
||||||
pollfd[1].events = POLLIN|POLLPRI;
|
pollfd[1].events = POLLIN|POLLPRI;
|
||||||
|
|
||||||
|
print_set_progname(progname);
|
||||||
print_set_syslog(1);
|
print_set_syslog(1);
|
||||||
print_set_verbose(1);
|
print_set_verbose(1);
|
||||||
|
|
||||||
|
|
9
print.c
9
print.c
|
@ -27,6 +27,12 @@
|
||||||
static int verbose = 0;
|
static int verbose = 0;
|
||||||
static int print_level = LOG_INFO;
|
static int print_level = LOG_INFO;
|
||||||
static int use_syslog = 1;
|
static int use_syslog = 1;
|
||||||
|
static const char *progname;
|
||||||
|
|
||||||
|
void print_set_progname(const char *name)
|
||||||
|
{
|
||||||
|
progname = name;
|
||||||
|
}
|
||||||
|
|
||||||
void print_set_syslog(int value)
|
void print_set_syslog(int value)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +65,8 @@ void print(int level, char const *format, ...)
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (verbose) {
|
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);
|
ts.tv_sec, ts.tv_nsec / 1000000, buf);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
1
print.h
1
print.h
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
void print(int level, char const *format, ...);
|
void print(int level, char const *format, ...);
|
||||||
|
|
||||||
|
void print_set_progname(const char *name);
|
||||||
void print_set_syslog(int value);
|
void print_set_syslog(int value);
|
||||||
void print_set_level(int level);
|
void print_set_level(int level);
|
||||||
void print_set_verbose(int value);
|
void print_set_verbose(int value);
|
||||||
|
|
1
ptp4l.c
1
ptp4l.c
|
@ -246,6 +246,7 @@ int main(int argc, char *argv[])
|
||||||
ds->clockQuality.clockClass = 255;
|
ds->clockQuality.clockClass = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_set_progname(progname);
|
||||||
print_set_verbose(cfg_settings.verbose);
|
print_set_verbose(cfg_settings.verbose);
|
||||||
print_set_syslog(cfg_settings.use_syslog);
|
print_set_syslog(cfg_settings.use_syslog);
|
||||||
print_set_level(cfg_settings.print_level);
|
print_set_level(cfg_settings.print_level);
|
||||||
|
|
Loading…
Reference in New Issue