[CRIU] [PATCH 10/12] posix-timer: Restore timers, need create and delete 'fake' timers

Pavel Tikhomirov snorcht at gmail.com
Thu Jun 27 12:32:26 EDT 2013


Signed-off-by: Pavel Tikhomirov <snorcht at gmail.com>
---
 pie/restorer.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/pie/restorer.c b/pie/restorer.c
index 06b24a9..7598e57 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -473,6 +473,52 @@ static int vma_remap(unsigned long src, unsigned long dst, unsigned long len)
 	return 0;
 }
 
+static int restore_posix_timers(struct task_restore_core_args *args)
+{
+	int ret = 0;
+
+	if (args->timer_n > 0) {
+		int i;
+		timer_t next_id;
+		struct sigevent sev;
+
+		for (i = 0; i < args->timer_n; i++) {
+			sev.sigev_notify = args->posix_timers[i].spt.it_sigev_notify;
+			sev.sigev_signo = args->posix_timers[i].spt.si_signo;
+			sev.sigev_value.sival_ptr = args->posix_timers[i].spt.sival_ptr;
+
+			while (1) {
+				ret = sys_timer_create(args->posix_timers[i].spt.clock_id, &sev, &next_id);
+				if (ret < 0) {
+					pr_err("Can't create posix timer - %d\n", i);
+					return ret;
+				}
+
+				if ((long)next_id == args->posix_timers[i].spt.it_id)
+					break;
+
+				ret = sys_timer_delete(next_id);
+				if (ret < 0) {
+					pr_err("Can't remove temporaty posix timer %lx\n", (long) next_id);
+					return ret;
+				}
+
+				if ((long)next_id > args->posix_timers[i].spt.it_id) {
+					pr_err("Can't create timers, kernel don't give them consequently");
+					return -1;
+				}
+			}
+
+			ret = sys_timer_settime(next_id, 0, &args->posix_timers[i].val, NULL);
+			if (ret < 0) {
+				pr_err("Can't set posix timer %lx\n", (long) next_id);
+				return ret;
+			}
+		}
+	}
+	return 0;
+}
+
 /*
  * The main routine to restore task via sigreturn.
  * This one is very special, we never return there
@@ -839,6 +885,12 @@ long __export_restore_task(struct task_restore_core_args *args)
 		}
 	}
 
+	ret = restore_posix_timers(args);
+	if (ret < 0){
+		pr_err("Can't restore posix timers %ld\n", ret);
+		goto core_restore_end;
+	}
+
 	rst_tcp_socks_all(args->rst_tcp_socks, args->rst_tcp_socks_size);
 
 	/* 
-- 
1.7.9.5



More information about the CRIU mailing list