+int fd_notif = -1;
+void notif_cb(void)
+{
+ int result;
+ struct trctl_msg msg;
+
+ /* FIXME: fd_notif should probably be protected by a spinlock */
+
+ if(fd_notif == -1)
+ return;
+
+ msg.type = MSG_NOTIF;
+ msg.size = sizeof(msg.type);
+
+ /* FIXME: don't block here */
+ result = write(fd_notif, &msg, msg.size+sizeof(msg.size));
+ if(result == -1) {
+ PERROR("write");
+ return;
+ }
+}
+
+int listener_main(void *p)
+{
+ int result;
+
+ /* Allowing only 1 connection for now. */
+ result = listen(pfd, 1);
+ if(result == -1) {
+ PERROR("listen");
+ return 1;
+ }
+
+ for(;;) {
+
+ uint32_t size;
+ int fd;
+ struct sockaddr_un addr;
+ socklen_t addrlen = sizeof(addr);
+
+ result = fd = accept(pfd, (struct sockaddr *)&addr, &addrlen);
+ if(result == -1) {
+ PERROR("accept");
+ continue;
+ }
+
+ for(;;) {
+ struct trctl_msg msg;
+ unsigned char dontclose=0;
+
+ result = read(fd, &msg.size, sizeof(msg.size));
+ if(result == -1) {
+ PERROR("read");
+ continue;
+ }
+
+ if(size > MAX_MSG_SIZE) {
+ ERR("trctl message too big");
+ break;
+ }
+
+ result = read(fd, &msg.type, sizeof(msg.type));
+ if(result == -1) {
+ PERROR("read");
+ continue;
+ }
+
+ switch(msg.type) {
+ case MSG_REGISTER_NOTIF:
+ /* TODO: put it in notif mode */
+ goto next_conn;
+ };
+ }
+ next_conn:;
+ }
+}
+
+void create_listener(void)
+{
+ int result;
+ static char listener_stack[16384];
+
+ result = clone(listener_main, listener_stack+sizeof(listener_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM, NULL);
+ if(result == -1) {
+ perror("clone");
+ }
+}
+