cp: allow prefixing all console messages with the guest name
[hvf.git] / cp / nucleus / printf.c
blob6f96cb47c531f694373fa1cd7796d04c920222fb
1 /*
2 * (C) Copyright 2007-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #include <channel.h>
9 #include <console.h>
10 #include <directory.h>
11 #include <ebcdic.h>
12 #include <slab.h>
13 #include <clock.h>
14 #include <sched.h>
15 #include <vsprintf.h>
16 #include <stdarg.h>
17 #include <vcpu.h>
19 int con_vprintf(struct virt_cons *con, const char *fmt, va_list args)
21 struct virt_sys *sys = container_of(con, struct virt_sys, console);
22 struct datetime dt;
23 char buf[128];
24 int off = 0;
25 int ret;
27 if (sys->print_ts) {
28 memset(&dt, 0, sizeof(dt));
29 ret = get_parsed_tod(&dt);
30 ret = snprintf(buf, sizeof(buf), "%02d:%02d:%02d ", dt.th, dt.tm,
31 dt.ts);
32 off += ret;
35 if (sys->print_name) {
36 ret = snprintf(buf + off, sizeof(buf) - off, "%s ",
37 sys->directory->userid);
38 off += ret;
41 ret = vsnprintf(buf + off, sizeof(buf) - off, fmt, args);
42 if (ret) {
43 if (sys->internal) {
44 /* internal guests direct all console traffic to sclp */
45 sclp_msg("%s", buf);
46 } else {
47 /* normal guests direct it to their console device */
48 ascii2ebcdic((u8 *) buf, off+ret);
49 //con_write(con, (u8 *) buf, off+ret);
53 return ret;
56 int con_printf(struct virt_cons *con, const char *fmt, ...)
58 va_list args;
59 int r;
61 va_start(args, fmt);
62 r = con_vprintf(con, fmt, args);
63 va_end(args);
65 return r;