[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/NEWLIB PATCH 3/6] syslog.c: Import from osv


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Wed, 14 Aug 2019 21:57:02 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Wed, 14 Aug 2019 18:57:22 +0000
  • Ironport-phdr: 9a23:yVI1EhFtCbSdiSeDSdNbCZ1GYnF86YWxBRYc798ds5kLTJ7yr8iwAkXT6L1XgUPTWs2DsrQY0rCQ6vqxEjJfqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba5sIBmssAndqM0bjYRjJ6sz1xDEvmZGd+NKyG1yOFmdhQz85sC+/J5i9yRfpfcs/NNeXKv5Yqo1U6VWACwpPG4p6sLrswLDTRaU6XsHTmoWiBtIDBPb4xz8Q5z8rzH1tut52CmdIM32UbU5Uims4qt3VBPljjoMOjgk+2/Vl8NwlrpWrhK/qRJizYDaY4abO/hwfq7GYd8WWXBMUtpLWiBdHo+xaZYEAeobPeZfqonwv0UDrRylBQmwBePvzCJDiHnr3a0izuQqDAbL0xAnH9IVrHTUrdP1OL0WUeCo1KnI0C7OYO9N2Tvn8IjIbwsureuWXbJ3aMfcz1QkGQ3CjlWVs4PlPjWV2/wCs2ia8+pgVf+vhHU9pw5tpTivw8EhgZTKiIIN0l3I6Cp0zJsvKdC7SEN3e8CoHIVSui2AOYZ6Wt4uTm51tCogybALuYS3cDYExZkp3RLTdvOKf5aO7xn+TuieOy14i2hgeL+nghay9lWvxfPkW8mv1VZKsjJFkt7RtnARzxDT6taISv96/kq5xzaP0hrc6uBAIUwuiaXbMIQtwqYtlpUIq0jDBCj2lF33jK+QaEok5vCl5/nob7n7vJORNI95hhvgPqgwmMGzG+o1PhALX2eB+OS80LPj/Vf+QLVPlvA5jq7ZsIvGJcQaoK61GQtV0ps76xaiFDqpzM8YkWMfLFJYYx2LlZLpO1bWLPDiEfi/m0iskCtsx/3eO73hA5PNLnnEkLf6ZLpy9lBTyBQtwtBb/J9UDrABIOnvWk/qrtDZAQE2Mwquz+bgEtV92ZsUWXiTDa+BLKPSrViI6/ohI+aSYI8VuS79JOY/6/7ukH85mEMSfaiy0JsRdn+3AvBmLF+Cbnb2nNgBDH8AvhAiQ+zylF2CTTlTam6pX6I8/D47EpipDYHZSoC2mrOB2ju7Hp1MaWBAEF+MFGzld4OaVPgQbCKdONRuniYaWri8U4Uhzw2htBfmy7p7KerZ4jYYtZPm1Nhy4e3fjxIy9SFqAMSb0mCCUXt0k3gORzAowK9/pVZyxUyZ3admnvwLXeBUsvZIVAY9LtvQwvJ3D/j2WxndZZGZRVDgRc+pUh8rSddk6NgVf0d7U/G/lg2LiyGtGKMUkfqPGYQp2qnHmWDsLYBnzCCVh+Eak1A6T54XZiWdjall+l2LCg==
  • Ironport-sdr: JjWlKva3+Cse0RBnt+gkeLO1xIYWe/y6HWY9/0bwh7e3RlxnyFcOz6VXzKDbKnsaBvT1+u7jHO a5S+4E62XD3g==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.