Index: /trunk/src/kash/Makefile.kmk
===================================================================
--- /trunk/src/kash/Makefile.kmk	(revision 2286)
+++ /trunk/src/kash/Makefile.kmk	(revision 2287)
@@ -126,5 +126,5 @@
 # Use the pregenerated code.
 #
-kash_ORDERDEPS :=
+kash_INTERMEDIATES :=
 kash_INCS += generated
 kash_SOURCES := $(patsubst $(PATH_kash)/%,generated/%,$(kash_SOURCES))
Index: /trunk/src/kash/shinstance.c
===================================================================
--- /trunk/src/kash/shinstance.c	(revision 2286)
+++ /trunk/src/kash/shinstance.c	(revision 2287)
@@ -651,5 +651,5 @@
 }
 
-int sh_sigismember(shsigset_t *setp, int signo)
+int sh_sigismember(shsigset_t const *setp, int signo)
 {
 #ifdef _MSC_VER
@@ -689,10 +689,10 @@
                 for (rc = 0; rc < NSIG; rc++)
                     if (sh_sigismember(newp, rc))
-                        sh_sigaddset(&mask);
+                        sh_sigaddset(&mask, rc);
                 break;
             case SIG_UNBLOCK:
                 for (rc = 0; rc < NSIG; rc++)
                     if (sh_sigismember(newp, rc))
-                        sh_sigdelset(&mask);
+                        sh_sigdelset(&mask, rc);
                 break;
             case SIG_SETMASK:
@@ -862,5 +862,5 @@
 #  else
     pid = -1;
-    error = ENOSYS;
+    errno = ENOSYS;
 #  endif
 # else
@@ -888,5 +888,5 @@
 # ifdef _MSC_VER
     pidret = -1;
-    error = ENOSYS;
+    errno = ENOSYS;
 # else
     pidret = waitpid(pid, statusp, flags);
@@ -919,5 +919,9 @@
 int sh_execve(shinstance *psh, const char *exe, const char * const *argv, const char * const *envp)
 {
+#ifdef _MSC_VER
+    intptr_t rc;
+#else
     int rc;
+#endif
 
 #ifdef DEBUG
@@ -946,168 +950,168 @@
     TRACE2((psh, "sh_execve -> %d [%d]\n", rc, errno));
     (void)psh;
+    return (int)rc;
+}
+
+uid_t sh_getuid(shinstance *psh)
+{
+#ifdef SH_PURE_STUB_MODE
+    uid_t uid = 0;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    uid_t uid = 0;
+# else
+    uid_t uid = getuid();
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_getuid() -> %d [%d]\n", uid, errno));
+    (void)psh;
+    return uid;
+}
+
+uid_t sh_geteuid(shinstance *psh)
+{
+#ifdef SH_PURE_STUB_MODE
+    uid_t euid = 0;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    uid_t euid = 0;
+# else
+    uid_t euid = geteuid();
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_geteuid() -> %d [%d]\n", euid, errno));
+    (void)psh;
+    return euid;
+}
+
+gid_t sh_getgid(shinstance *psh)
+{
+#ifdef SH_PURE_STUB_MODE
+    gid_t gid = 0;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    gid_t gid = 0;
+# else
+    gid_t gid = getgid();
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_getgid() -> %d [%d]\n", gid, errno));
+    (void)psh;
+    return gid;
+}
+
+gid_t sh_getegid(shinstance *psh)
+{
+#ifdef SH_PURE_STUB_MODE
+    gid_t egid = 0;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    gid_t egid = 0;
+# else
+    gid_t egid = getegid();
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_getegid() -> %d [%d]\n", egid, errno));
+    (void)psh;
+    return egid;
+}
+
+pid_t sh_getpid(shinstance *psh)
+{
+    pid_t pid;
+
+#ifdef SH_PURE_STUB_MODE
+    pid = 0;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    pid = _getpid();
+# else
+    pid = getpid();
+# endif
+#else
+#endif
+
+    (void)psh;
+    return pid;
+}
+
+pid_t sh_getpgrp(shinstance *psh)
+{
+#ifdef SH_PURE_STUB_MODE
+    pid_t pgrp = 0;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    pid_t pgrp = _getpid();
+# else
+    pid_t pgrp = getpgrp();
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_getpgrp() -> %d [%d]\n", pgrp, errno));
+    (void)psh;
+    return pgrp;
+}
+
+pid_t sh_getpgid(shinstance *psh, pid_t pid)
+{
+#ifdef SH_PURE_STUB_MODE
+    pid_t pgid = pid;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    pid_t pgid = pid;
+# else
+    pid_t pgid = getpgid(pid);
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_getpgid(%d) -> %d [%d]\n", pid, pgid, errno));
+    (void)psh;
+    return pgid;
+}
+
+int sh_setpgid(shinstance *psh, pid_t pid, pid_t pgid)
+{
+#ifdef SH_PURE_STUB_MODE
+    int rc = -1;
+
+#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
+# ifdef _MSC_VER
+    int rc = -1;
+    errno = ENOSYS;
+# else
+    int rc = setpgid(pid, pgid);
+# endif
+
+#else
+#endif
+
+    TRACE2((psh, "sh_setpgid(%d, %d) -> %d [%d]\n", pid, pgid, rc, errno));
+    (void)psh;
     return rc;
 }
 
-uid_t sh_getuid(shinstance *psh)
-{
-#ifdef SH_PURE_STUB_MODE
-    uid_t uid = 0;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    uid_t uid = 0;
-# else
-    uid_t uid = getuid();
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_getuid() -> %d [%d]\n", uid, errno));
-    (void)psh;
-    return uid;
-}
-
-uid_t sh_geteuid(shinstance *psh)
-{
-#ifdef SH_PURE_STUB_MODE
-    uid_t euid = 0;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    uid_t euid = 0;
-# else
-    uid_t euid = geteuid();
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_geteuid() -> %d [%d]\n", euid, errno));
-    (void)psh;
-    return euid;
-}
-
-gid_t sh_getgid(shinstance *psh)
-{
-#ifdef SH_PURE_STUB_MODE
-    gid_t gid = 0;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    gid_t gid = 0;
-# else
-    gid_t gid = getgid();
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_getgid() -> %d [%d]\n", gid, errno));
-    (void)psh;
-    return gid;
-}
-
-gid_t sh_getegid(shinstance *psh)
-{
-#ifdef SH_PURE_STUB_MODE
-    gid_t egid = 0;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    gid_t egid = 0;
-# else
-    gid_t egid = getegid();
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_getegid() -> %d [%d]\n", egid, errno));
-    (void)psh;
-    return egid;
-}
-
-pid_t sh_getpid(shinstance *psh)
-{
-    pid_t pid;
-
-#ifdef SH_PURE_STUB_MODE
-    pid = 0;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    pid = _getpid();
-# else
-    pid = getpid();
-# endif
-#else
-#endif
-
-    (void)psh;
-    return pid;
-}
-
-pid_t sh_getpgrp(shinstance *psh)
-{
-#ifdef SH_PURE_STUB_MODE
-    pid_t pgrp = 0;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    pid_t pgrp _getpid();
-# else
-    pid_t pgrp = getpgrp();
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_getpgrp() -> %d [%d]\n", pgrp, errno));
-    (void)psh;
-    return pgrp;
-}
-
-pid_t sh_getpgid(shinstance *psh, pid_t pid)
-{
-#ifdef SH_PURE_STUB_MODE
-    pid_t pgid = pid;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    pid_t pgid = pid;
-# else
-    pid_t pgid = getpgid(pid);
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_getpgid(%d) -> %d [%d]\n", pid, pgid, errno));
-    (void)psh;
-    return pgid;
-}
-
-int sh_setpgid(shinstance *psh, pid_t pid, pid_t pgid)
-{
-#ifdef SH_PURE_STUB_MODE
-    int rc = -1;
-
-#elif defined(SH_STUB_MODE) || defined(SH_FORKED_MODE)
-# ifdef _MSC_VER
-    int rc = -1;
-    error = ENOSYS;
-# else
-    int rc = setpgid(pid, pgid);
-# endif
-
-#else
-#endif
-
-    TRACE2((psh, "sh_setpgid(%d, %d) -> %d [%d]\n", pid, pgid, rc, errno));
-    (void)psh;
-    return rc;
-}
-
 pid_t sh_tcgetpgrp(shinstance *psh, int fd)
 {
@@ -1120,5 +1124,5 @@
 # ifdef _MSC_VER
     pgrp = -1;
-    error = ENOSYS;
+    errno = ENOSYS;
 # else
     pgrp = tcgetpgrp(fd);
@@ -1144,5 +1148,5 @@
 # ifdef _MSC_VER
     rc = -1;
-    error = ENOSYS;
+    errno = ENOSYS;
 # else
     rc = tcsetpgrp(fd, pgrp);
@@ -1165,5 +1169,5 @@
 # ifdef _MSC_VER
     int rc = -1;
-    error = ENOSYS;
+    errno = ENOSYS;
 # else
     int rc = getrlimit(resid, limp);
@@ -1188,5 +1192,5 @@
 # ifdef _MSC_VER
     int rc = -1;
-    error = ENOSYS;
+    errno = ENOSYS;
 # else
     int rc = setrlimit(resid, limp);
Index: /trunk/src/kash/shinstance.h
===================================================================
--- /trunk/src/kash/shinstance.h	(revision 2286)
+++ /trunk/src/kash/shinstance.h	(revision 2287)
@@ -342,4 +342,5 @@
 #define SH_SIG_ERR ((shsig_t)SIG_ERR)
 #ifdef _MSC_VER
+#   define SA_RESTART       0x02
 #   define SIG_BLOCK         1
 #   define SIG_UNBLOCK       2
@@ -368,5 +369,5 @@
 void sh_sigaddset(shsigset_t *, int);
 void sh_sigdelset(shsigset_t *, int);
-int sh_sigismember(shsigset_t *, int);
+int sh_sigismember(shsigset_t const *, int);
 int sh_sigprocmask(shinstance *, int, shsigset_t const *, shsigset_t *);
 void sh_abort(shinstance *) __attribute__((__noreturn__));
Index: /trunk/src/kash/show.c
===================================================================
--- /trunk/src/kash/show.c	(revision 2286)
+++ /trunk/src/kash/show.c	(revision 2287)
@@ -433,13 +433,13 @@
 		fd = shfile_open(&psh->fdtab, s, O_APPEND | O_RDWR | O_CREAT, 0600);
 		if (fd != -1) {
-			int fd2 = fcntl(fd, F_DUPFD, 199);
+			int fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 199);
 			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 99);
+				fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 99);
 			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 49);
+				fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 49);
 			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 18);
+				fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 18);
 			if (fd2 == -1)
-				fd2 = fcntl(fd, F_DUPFD, 10);
+				fd2 = shfile_fcntl(&psh->fdtab, fd, F_DUPFD, 10);
 			if (fd2 != -1) {
 				close(fd);
@@ -453,5 +453,5 @@
 		}
 	}
-	setvbuf(tracefile, (char *)NULL, _IOLBF, 0); //setlinebuf(tracefile);
+	setvbuf(tracefile, (char *)NULL, _IOLBF, 1024);
 	fputs("\nTracing started.\n", tracefile);
 }
