Prints stderr to the kernel monitor
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 5 Apr 2010 00:11:23 +0000 (17:11 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:40 +0000 (17:35 -0700)
For apps that write directly to file descriptor 2, it will be
interpreted as an attempt to write to stderr.  While not complete, it
will catch some error messages when the appserver isn't configured.

kern/src/frontend.c
kern/src/syscall.c

index a27b85f..663f200 100644 (file)
@@ -234,8 +234,8 @@ int32_t frontend_syscall(pid_t pid, int32_t syscall_num,
                          uint32_t arg2, uint32_t arg3, int32_t* errno)
 {
 #ifndef __CONFIG_APPSERVER__
-       warn("No appserver support: either "
-            "don't make this syscall or enable the appserver!\n");
+       warn("No appserver support, requested syscall %d for proc %d", syscall_num,
+            pid);
        if(errno)
                *errno = ENOSYS;
        return -1;
index c6e48e9..975e00a 100644 (file)
@@ -709,10 +709,22 @@ static int sys_eth_recv_check(env_t* e)
 
 intreg_t sys_write(struct proc* p, int fd, const void* buf, int len)
 {
+       int ret = 0;
        void* kbuf = user_memdup_errno(p,buf,len);
        if(kbuf == NULL)
                return -1;
-       int ret = ufe(write,fd,PADDR(kbuf),len,0);
+#ifndef __CONFIG_APPSERVER__
+       /* Catch a common usage of stderr */
+       if (fd == 2) {
+               ((char*)kbuf)[len-1] = 0;
+               printk("[stderr]: %s\n", kbuf);
+               ret = len;
+       } else { // but warn/panic otherwise in ufe()
+               ret = ufe(write, fd, PADDR(kbuf), len, 0);
+       }
+#else
+       ret = ufe(write, fd, PADDR(kbuf), len, 0);
+#endif
        user_memdup_free(p,kbuf);
        return ret;
 }