[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT/NEWLIB PATCH 3/6] syslog.c: Import from osv
Hi Costin, Bogdan, this patch looks good, thanks. There are some minor typos in the commit message which I'll fix on upstream. -- Felipe Reviewed-by: Felipe Huici <felipe.huici@xxxxxxxxx> On 14.08.19, 20:57, "Costin Lupu" <costin.lupu@xxxxxxxxx> wrote: Copied as is from the official osv git mirror https://github.com/cloudius-systems/osv.git, commit ee7a2cd4. Original file locations: * libc/syslog.c We had to decide between importing from musl or osv. We decided to pick the osv variant because its simpler: it outputs to stdio. The musl implementation uses UNIX sockets, which we currently don't have in Unikraft. Moreover, the osv implementation was originally imported from musl and adapted. This is also the reason why we put the file under the musl-imported/ subdirectory. In the future, a better syslog implementation may replace this one and it might even become an internal library will fully fledged functionality, just like classic OSes. Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx> --- musl-imported/src/syslog.c | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 musl-imported/src/syslog.c diff --git a/musl-imported/src/syslog.c b/musl-imported/src/syslog.c new file mode 100644 index 0000000..be7cfb6 --- /dev/null +++ b/musl-imported/src/syslog.c @@ -0,0 +1,73 @@ + +// adapted from musl's version, just writes to stdio + +#include <syslog.h> +#include <stdio.h> +#include <time.h> +#include <string.h> +#include <stdarg.h> +#include <unistd.h> +#include <libc.h> + +static mutex_t lock; +static char log_ident[32]; +static int log_opt; +static int log_facility = LOG_USER; + +void openlog(const char *ident, int opt, int facility) +{ + LOCK(lock); + + if (ident) { + size_t n = strnlen(ident, sizeof log_ident - 1); + memcpy(log_ident, ident, n); + log_ident[n] = 0; + } else { + log_ident[0] = 0; + } + log_opt = opt; + log_facility = facility; + + UNLOCK(lock); +} + +void closelog(void) +{ +} + +void __syslog_chk(int priority, int flag, const char *message, ...) +{ + LOCK(lock); + + va_list ap; + va_start(ap, message); + + char timebuf[16]; + time_t now; + struct tm tm; + char buf[256]; + int pid; + int l, l2; + + if (!(priority & LOG_FACMASK)) priority |= log_facility; + + now = time(NULL); + gmtime_r(&now, &tm); + strftime(timebuf, sizeof timebuf, "%b %e %T", &tm); + + pid = (log_opt & LOG_PID) ? getpid() : 0; + l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ", + priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid); + l2 = vsnprintf(buf+l, sizeof buf - l, message, ap); + if (l2 >= 0) { + if (l2 >= sizeof buf - l) l = sizeof buf - 1; + else l += l2; + if (buf[l-1] != '\n') buf[l++] = '\n'; + fwrite(buf, 1, l, LOG_PRI(priority) >= LOG_ERR ? stderr : stdout); + } + + va_end(ap); + + UNLOCK(lock); +} + -- 2.20.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |