本文共 1344 字,大约阅读时间需要 4 分钟。
asmlinkage long sys_stime(time_t __user *tptr);用于设置系统的时间其源码分析如下:SYSCALL_DEFINE1(stime, time_t __user *, tptr){ struct timespec64 tv; int err; #获得user space 设置的time值,这个值保存在tptr这个buffer中 if (get_user(tv.tv_sec, tptr)) return -EFAULT; tv.tv_nsec = 0; #检查是否有设置time的权限 err = security_settime64(&tv, NULL); if (err) return err; #原来最终是调用下面这个函数来设置timer do_settimeofday64(&tv); return 0;}int do_settimeofday64(const struct timespec64 *ts){ struct timekeeper *tk = &tk_core.timekeeper; struct timespec64 ts_delta, xt; unsigned long flags; int ret = 0; #检查要设置的时间是否合法。 if (!timespec64_valid_strict(ts)) return -EINVAL; raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); #给中间值的timespec64 赋值 xt = tk_xtime(tk); ts_delta.tv_sec = ts->tv_sec - xt.tv_sec; ts_delta.tv_nsec = ts->tv_nsec - xt.tv_nsec; #比较当前的墙上时间和要设置的时间相比,也就是说不能比当前时间落后 if (timespec64_compare(&tk->wall_to_monotonic, &ts_delta) > 0) { ret = -EINVAL; goto out; } #设置墙上时间 tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts_delta)); tk_set_xtime(tk, ts);out: #更新timekeeper timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); write_seqcount_end(&tk_core.seq); raw_spin_unlock_irqrestore(&timekeeper_lock, flags); /* signal hrtimers about time change */ #发出信号说明当前系统的时间已经改变了 clock_was_set(); return ret;}
转载地址:http://acnmi.baihongyu.com/