Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b34e428 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

introduce PF_KTHREAD flag



Introduce the new PF_KTHREAD flag to mark the kernel threads.  It is set
by INIT_TASK() and copied to the forked childs (we could set it in
kthreadd() along with PF_NOFREEZE instead).

daemonize() was changed as well.  In that case testing of PF_KTHREAD is
racy, but daemonize() is hopeless anyway.

This flag is cleared in do_execve(), before search_binary_handler().
Probably not the best place, we can do this in exec_mmap() or in
start_thread(), or clear it along with PF_FORKNOEXEC.  But I think this
doesn't matter in practice, and if do_execve() fails kthread should die
soon.

Signed-off-by: default avatarOleg Nesterov <oleg@tv-sign.ru>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3d749b9e
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -1326,6 +1326,7 @@ int do_execve(char * filename,
	if (retval < 0)
	if (retval < 0)
		goto out;
		goto out;


	current->flags &= ~PF_KTHREAD;
	retval = search_binary_handler(bprm,regs);
	retval = search_binary_handler(bprm,regs);
	if (retval >= 0) {
	if (retval >= 0) {
		/* execve success */
		/* execve success */
+1 −1
Original line number Original line Diff line number Diff line
@@ -122,7 +122,7 @@ extern struct group_info init_groups;
	.state		= 0,						\
	.state		= 0,						\
	.stack		= &init_thread_info,				\
	.stack		= &init_thread_info,				\
	.usage		= ATOMIC_INIT(2),				\
	.usage		= ATOMIC_INIT(2),				\
	.flags		= 0,						\
	.flags		= PF_KTHREAD,					\
	.lock_depth	= -1,						\
	.lock_depth	= -1,						\
	.prio		= MAX_PRIO-20,					\
	.prio		= MAX_PRIO-20,					\
	.static_prio	= MAX_PRIO-20,					\
	.static_prio	= MAX_PRIO-20,					\
+1 −0
Original line number Original line Diff line number Diff line
@@ -1483,6 +1483,7 @@ static inline void put_task_struct(struct task_struct *t)
#define PF_EXITING	0x00000004	/* getting shut down */
#define PF_EXITING	0x00000004	/* getting shut down */
#define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
#define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
#define PF_VCPU		0x00000010	/* I'm a virtual CPU */
#define PF_VCPU		0x00000010	/* I'm a virtual CPU */
#define PF_KTHREAD	0x00000020	/* I am a kernel thread */
#define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
#define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
#define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
#define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
#define PF_DUMPCORE	0x00000200	/* dumped core */
#define PF_DUMPCORE	0x00000200	/* dumped core */
+1 −1
Original line number Original line Diff line number Diff line
@@ -430,7 +430,7 @@ void daemonize(const char *name, ...)
	 * We don't want to have TIF_FREEZE set if the system-wide hibernation
	 * We don't want to have TIF_FREEZE set if the system-wide hibernation
	 * or suspend transition begins right now.
	 * or suspend transition begins right now.
	 */
	 */
	current->flags |= PF_NOFREEZE;
	current->flags |= (PF_NOFREEZE | PF_KTHREAD);


	if (current->nsproxy != &init_nsproxy) {
	if (current->nsproxy != &init_nsproxy) {
		get_nsproxy(&init_nsproxy);
		get_nsproxy(&init_nsproxy);