options/posix: Implemented openlog and closelog
#include <syslog.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
#include <bits/ensure.h>
+static char log_ident[32];
+static int log_options;
+static int log_facility = LOG_USER;
+static int log_fd = -1;
+
+static const struct {
+ short sun_family;
+ char sun_path[9];
+} log_addr = {
+ AF_UNIX,
+ "/dev/log"
+};
+
void closelog(void) {
- __ensure(!"Not implemented");
- __builtin_unreachable();
+ close(log_fd);
+ log_fd = -1;
}
-void openlog(const char *, int, int) {
- __ensure(!"Not implemented");
- __builtin_unreachable();
+static void __openlog() {
+ log_fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ if(log_fd >= 0)
+ connect(log_fd, (const sockaddr *)&log_addr, sizeof log_addr);
+}
+
+void openlog(const char *ident, int options, int facility) {
+ 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_options = options;
+ log_facility = facility;
+
+ if((options & LOG_NDELAY) && log_fd < 0)
+ __openlog();
}
int setlogmask(int) {
