2008-04-19  Dmitry V. Levin <ldv@altlinux.org>

	* syscall.c (is_restart_error): New function.
	* defs.h (is_restart_error): Declare it.

	* linux/dummy.h (sys_nanosleep): Uncouple from sys_adjtime().
	* time.c (sys_nanosleep): New function, based on is_restart_error().
diff --git a/ChangeLog b/ChangeLog
index 4d9c25d..9059cbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-04-19  Dmitry V. Levin <ldv@altlinux.org>
 
+	* syscall.c (is_restart_error): New function.
+	* defs.h (is_restart_error): Declare it.
+
+	* linux/dummy.h (sys_nanosleep): Uncouple from sys_adjtime().
+	* time.c (sys_nanosleep): New function, based on is_restart_error().
+
 	* process.c (sys_prctl): Decode PR_SET_PDEATHSIG, PR_GET_PDEATHSIG,
 	PR_SET_DUMPABLE, PR_GET_DUMPABLE, PR_SET_KEEPCAPS, PR_GET_KEEPCAPS.
 	Fix PR_GET_UNALIGN decoder.
diff --git a/defs.h b/defs.h
index df11dc6..b2f6fe3 100644
--- a/defs.h
+++ b/defs.h
@@ -507,6 +507,7 @@
 extern void call_summary P((FILE *));
 extern void tprint_iov P((struct tcb *, unsigned long, unsigned long));
 extern void tprint_open_modes P((struct tcb *, mode_t));
+extern int is_restart_error P((struct tcb *));
 
 #ifdef LINUX
 extern int internal_clone P((struct tcb *));
diff --git a/linux/dummy.h b/linux/dummy.h
index 5c6cfb6..92e6886 100644
--- a/linux/dummy.h
+++ b/linux/dummy.h
@@ -58,7 +58,6 @@
 #define	sys_fchdir		sys_close
 #define	sys_setfsuid		sys_setuid
 #define	sys_setfsgid		sys_setgid
-#define sys_nanosleep		sys_adjtime
 #define	sys_acct		sys_chdir
 #define sys_fdatasync		sys_close
 #define sys_mlock		sys_munmap
diff --git a/syscall.c b/syscall.c
index 91331aa..f1b7054 100644
--- a/syscall.c
+++ b/syscall.c
@@ -2641,3 +2641,22 @@
 	return 0;
 }
 #endif /* SUNOS4 */
+
+int
+is_restart_error(struct tcb *tcp)
+{
+#ifdef LINUX
+	if (!syserror(tcp))
+		return 0;
+	switch (tcp->u_error) {
+		case ERESTARTSYS:
+		case ERESTARTNOINTR:
+		case ERESTARTNOHAND:
+		case ERESTART_RESTARTBLOCK:
+			return 1;
+		default:
+			break;
+	}
+#endif /* LINUX */
+	return 0;
+}
diff --git a/time.c b/time.c
index 651ec40..204a6da 100644
--- a/time.c
+++ b/time.c
@@ -329,6 +329,21 @@
 	return 0;
 }
 
+int
+sys_nanosleep(struct tcb *tcp)
+{
+	if (entering(tcp)) {
+		print_timespec(tcp, tcp->u_arg[0]);
+		tprintf(", ");
+	} else {
+		if (!tcp->u_arg[1] || is_restart_error(tcp))
+			print_timespec(tcp, tcp->u_arg[1]);
+		else
+			tprintf("%#lx", tcp->u_arg[1]);
+	}
+	return 0;
+}
+
 static const struct xlat which[] = {
 	{ ITIMER_REAL,	"ITIMER_REAL"	},
 	{ ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},