博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
系统调用之sys_stime
阅读量:4216 次
发布时间:2019-05-26

本文共 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/

你可能感兴趣的文章
android MediaPlayer 的使用背景音乐的播放
查看>>
感悟随笔1
查看>>
android list 保存点进行有关操作
查看>>
android menue键的相关设置 菜单的设置
查看>>
android应用上传至各应用平台(1)
查看>>
Android应用上传至各应用平台(2)
查看>>
eclipse中修改包名 Android应用上线包冲突问题
查看>>
android 消息接受传送与线程的启动
查看>>
android 欢迎界面的实现在一个activity中
查看>>
android menu 使用总结1
查看>>
C++结构体与链表总结
查看>>
c,c++宏
查看>>
c++中的枚举类型
查看>>
c++ 运算符重载
查看>>
android使用已安装程序实现分享功能
查看>>
android实现截图功能
查看>>
android 网络连接状态判断与数据类型
查看>>
android webview 实现网页加载进度
查看>>
《人性的弱点》
查看>>
《大师们是如何工作的》
查看>>