Created
November 7, 2014 01:40
-
-
Save anonymous/4740df21ec33d39c4db3 to your computer and use it in GitHub Desktop.
0001-fs-proc-uptime.s-allow-setting-uptime-from-userspace.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From a0c891cc8c48d2105f8972f372e4619535151a25 Mon Sep 17 00:00:00 2001 | |
From: Alexey Ignatov <lexszero@gmail.com> | |
Date: Fri, 7 Nov 2014 04:38:50 +0300 | |
Subject: [PATCH] fs/proc/uptime.s: allow setting uptime from userspace | |
Use `echo 100500 > /proc/uptime' to add 100500 seconds to displayed uptime | |
value. | |
Signed-off-by: Alexey Ignatov <lexszero@gmail.com> | |
--- | |
fs/proc/uptime.c | 25 +++++++++++++++++++++++-- | |
1 file changed, 23 insertions(+), 2 deletions(-) | |
diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c | |
index 33de567..302bdb7 100644 | |
--- a/fs/proc/uptime.c | |
+++ b/fs/proc/uptime.c | |
@@ -7,6 +7,8 @@ | |
#include <linux/kernel_stat.h> | |
#include <linux/cputime.h> | |
+static struct timespec uptime_offset = {0, 0}; | |
+ | |
static int uptime_proc_show(struct seq_file *m, void *v) | |
{ | |
struct timespec uptime; | |
@@ -21,6 +23,7 @@ static int uptime_proc_show(struct seq_file *m, void *v) | |
idletime += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE]; | |
get_monotonic_boottime(&uptime); | |
+ uptime = timespec_add_safe(uptime, uptime_offset); | |
nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC; | |
idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem); | |
idle.tv_nsec = rem; | |
@@ -32,6 +35,21 @@ static int uptime_proc_show(struct seq_file *m, void *v) | |
return 0; | |
} | |
+static ssize_t uptime_proc_write(struct file *file, const char __user *buf, | |
+ size_t size, loff_t *off) | |
+{ | |
+ int ret; | |
+ unsigned long val; | |
+ char tmp[20]; | |
+ ret = copy_from_user(tmp, buf, min(size, sizeof(tmp))); | |
+ tmp[min(size, sizeof(tmp)-1)] = 0; | |
+ ret = kstrtoul(tmp, 10, &val); | |
+ if (ret < 0) | |
+ return ret; | |
+ uptime_offset.tv_sec = val; | |
+ return size; | |
+} | |
+ | |
static int uptime_proc_open(struct inode *inode, struct file *file) | |
{ | |
return single_open(file, uptime_proc_show, NULL); | |
@@ -40,13 +58,16 @@ static int uptime_proc_open(struct inode *inode, struct file *file) | |
static const struct file_operations uptime_proc_fops = { | |
.open = uptime_proc_open, | |
.read = seq_read, | |
- .llseek = seq_lseek, | |
+ .write = uptime_proc_write, | |
+ /* This shit fucks something up on writes, to lazy to kludge it | |
+ * the right way */ | |
+ //.llseek = seq_lseek, | |
.release = single_release, | |
}; | |
static int __init proc_uptime_init(void) | |
{ | |
- proc_create("uptime", 0, NULL, &uptime_proc_fops); | |
+ proc_create("uptime", 0644, NULL, &uptime_proc_fops); | |
return 0; | |
} | |
fs_initcall(proc_uptime_init); | |
-- | |
1.8.5.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment