[PATCH 2/2] procfs: lseek(/proc/PID/comm, 0, SEEK_END)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement lseek(fd, 0, SEEK_END) for /proc/PID/comm to return max
task name length.

This will allow eg. pthread_getname_np() to be able to return ERANGE
without modifying thread's name.

Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
---
 fs/proc/base.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 3a3b566443e5..80f5911f2ea9 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1575,11 +1575,20 @@ static int comm_open(struct inode *inode, struct file *filp)
 	return single_open(filp, comm_show, inode);
 }
 
+static loff_t comm_lseek(struct file *file, loff_t offset, int whence)
+{
+	/* SEEK_END for seq_files normally gets -EINVAL */
+	if (whence == SEEK_END && offset == 0)
+		return TASK_COMM_LEN - 1;
+
+	return seq_lseek(file, offset, whence);
+}
+
 static const struct file_operations proc_pid_set_comm_operations = {
 	.open		= comm_open,
 	.read		= seq_read,
 	.write		= comm_write,
-	.llseek		= seq_lseek,
+	.llseek		= comm_lseek,
 	.release	= single_release,
 };
 
-- 
2.19.2




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux