All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nilfs-utils 0/2] trivial improvements of cleanerd
@ 2014-01-01  7:30 Hitoshi Mitake
       [not found] ` <1388561449-13980-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Hitoshi Mitake @ 2014-01-01  7:30 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA; +Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w

This patchset removes trivial problems in cleanerd. Below is a summary of the
problems:
1. current daemonize() of cleanerd doesn't ensure not to being a session leader
2. cleanerd doesn't adjust the OOM killer

Thanks,
Hitoshi

Hitoshi Mitake (2):
  cleanerd: call _exit(2) twice for ensuring not being a session leader
  cleanerd: adjust the OOM killer

 sbin/cleanerd/cleanerd.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found] ` <1388561449-13980-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-01  7:30   ` Hitoshi Mitake
       [not found]     ` <1388561449-13980-2-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-01  7:30   ` [PATCH nilfs-utils 2/2] cleanerd: adjust the OOM killer Hitoshi Mitake
  1 sibling, 1 reply; 8+ messages in thread
From: Hitoshi Mitake @ 2014-01-01  7:30 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA
  Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w, Hitoshi Mitake

Current daemonize() function of cleanerd call _exit(2) only once during its
process of becoming a daemon process. But in the linux environment, a daemon
process should call _exit(2) twice for ensuring not being a session leader. If a
process don't do that, unexpected SIGHUP can be sent to the process (though it
happens rarely). The signal would be confusing event for cleanerd of nilfs. This
patch removes this potential problem.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
---
 sbin/cleanerd/cleanerd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
index 26067bd..edfa083 100644
--- a/sbin/cleanerd/cleanerd.c
+++ b/sbin/cleanerd/cleanerd.c
@@ -676,6 +676,16 @@ static int daemonize(int nochdir, int noclose, int nofork)
 
 	/* umask(0); */
 
+	/* for ensuring I'm not a session leader */
+	if (!nofork) {
+		pid = fork();
+		if (pid < 0)
+			return -1;
+		else if (pid != 0)
+			/* parent */
+			_exit(0);
+	}
+
 	if (!nochdir && (chdir(ROOTDIR) < 0))
 		return -1;
 
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nilfs-utils 2/2] cleanerd: adjust the OOM killer
       [not found] ` <1388561449-13980-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-01  7:30   ` [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader Hitoshi Mitake
@ 2014-01-01  7:30   ` Hitoshi Mitake
       [not found]     ` <1388561449-13980-3-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Hitoshi Mitake @ 2014-01-01  7:30 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA
  Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w, Hitoshi Mitake

cleanerd is a very important process in a system which uses nilfs. So it should
adjust the OOM killer for reducing possibility of the killing as much as
possible.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
---
 sbin/cleanerd/cleanerd.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
index edfa083..3494a9a 100644
--- a/sbin/cleanerd/cleanerd.c
+++ b/sbin/cleanerd/cleanerd.c
@@ -654,6 +654,40 @@ nilfs_cleanerd_select_segments(struct nilfs_cleanerd *cleanerd,
 	return nssegs;
 }
 
+static int oom_adjust(void)
+{
+	int fd, err;
+	const char *path, *score;
+	struct stat st;
+
+	/* Avoid oom-killer */
+	path = "/proc/self/oom_score_adj";
+	score = "-1000\n";
+
+	if (stat(path, &st)) {
+		/* oom_score_adj cannot be used, try oom_adj */
+		path = "/proc/self/oom_adj";
+		score = "-17\n";
+	}
+
+	fd = open(path, O_WRONLY);
+	if (fd < 0) {
+		fprintf(stderr, "can't adjust oom-killer's pardon %s, %m\n",
+			path);
+		return errno;
+	}
+
+	err = write(fd, score, strlen(score));
+	if (err < 0) {
+		fprintf(stderr, "can't adjust oom-killer's pardon %s, %m\n",
+			path);
+		close(fd);
+		return errno;
+	}
+	close(fd);
+	return 0;
+}
+
 #define DEVNULL	"/dev/null"
 #define ROOTDIR	"/"
 
@@ -1549,6 +1583,11 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	if (oom_adjust() < 0) {
+		fprintf(stderr, "adjusting the OOM killer falied: %m\n");
+		exit(1);
+	}
+
 	openlog(progname, LOG_PID, LOG_DAEMON);
 	syslog(LOG_INFO, "start");
 
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH nilfs-utils 2/2] cleanerd: adjust the OOM killer
       [not found]     ` <1388561449-13980-3-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-01  9:16       ` Ryusuke Konishi
  0 siblings, 0 replies; 8+ messages in thread
From: Ryusuke Konishi @ 2014-01-01  9:16 UTC (permalink / raw)
  To: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w
  Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA,
	mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg

On Wed,  1 Jan 2014 16:30:49 +0900, Hitoshi Mitake wrote:
> cleanerd is a very important process in a system which uses nilfs. So it should
> adjust the OOM killer for reducing possibility of the killing as much as
> possible.
> 
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>

Looks OK to me.

Applied after I corrected a trivial typo: s/falied/failed/.

Thanks,
Ryusuke Konishi

> ---
>  sbin/cleanerd/cleanerd.c | 39 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
> index edfa083..3494a9a 100644
> --- a/sbin/cleanerd/cleanerd.c
> +++ b/sbin/cleanerd/cleanerd.c
> @@ -654,6 +654,40 @@ nilfs_cleanerd_select_segments(struct nilfs_cleanerd *cleanerd,
>  	return nssegs;
>  }
>  
> +static int oom_adjust(void)
> +{
> +	int fd, err;
> +	const char *path, *score;
> +	struct stat st;
> +
> +	/* Avoid oom-killer */
> +	path = "/proc/self/oom_score_adj";
> +	score = "-1000\n";
> +
> +	if (stat(path, &st)) {
> +		/* oom_score_adj cannot be used, try oom_adj */
> +		path = "/proc/self/oom_adj";
> +		score = "-17\n";
> +	}
> +
> +	fd = open(path, O_WRONLY);
> +	if (fd < 0) {
> +		fprintf(stderr, "can't adjust oom-killer's pardon %s, %m\n",
> +			path);
> +		return errno;
> +	}
> +
> +	err = write(fd, score, strlen(score));
> +	if (err < 0) {
> +		fprintf(stderr, "can't adjust oom-killer's pardon %s, %m\n",
> +			path);
> +		close(fd);
> +		return errno;
> +	}
> +	close(fd);
> +	return 0;
> +}
> +
>  #define DEVNULL	"/dev/null"
>  #define ROOTDIR	"/"
>  
> @@ -1549,6 +1583,11 @@ int main(int argc, char *argv[])
>  		exit(1);
>  	}
>  
> +	if (oom_adjust() < 0) {
> +		fprintf(stderr, "adjusting the OOM killer falied: %m\n");
> +		exit(1);
> +	}
> +
>  	openlog(progname, LOG_PID, LOG_DAEMON);
>  	syslog(LOG_INFO, "start");
>  
> -- 
> 1.8.1.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]     ` <1388561449-13980-2-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-01  9:30       ` Ryusuke Konishi
       [not found]         ` <20140101.183018.491730600.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Ryusuke Konishi @ 2014-01-01  9:30 UTC (permalink / raw)
  To: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w
  Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA,
	mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg

On Wed,  1 Jan 2014 16:30:48 +0900, Hitoshi Mitake wrote:
> Current daemonize() function of cleanerd call _exit(2) only once during its
> process of becoming a daemon process. But in the linux environment, a daemon
> process should call _exit(2) twice for ensuring not being a session leader. If a
> process don't do that, unexpected SIGHUP can be sent to the process (though it
> happens rarely). The signal would be confusing event for cleanerd of nilfs. This
> patch removes this potential problem.
> 
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
> ---
>  sbin/cleanerd/cleanerd.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
> index 26067bd..edfa083 100644
> --- a/sbin/cleanerd/cleanerd.c
> +++ b/sbin/cleanerd/cleanerd.c
> @@ -676,6 +676,16 @@ static int daemonize(int nochdir, int noclose, int nofork)
>  
>  	/* umask(0); */
>  
> +	/* for ensuring I'm not a session leader */
> +	if (!nofork) {
> +		pid = fork();
> +		if (pid < 0)
> +			return -1;
> +		else if (pid != 0)
> +			/* parent */
> +			_exit(0);
> +	}
> +

I tried your patch, but the cleaner daemon still was a session leader.

This turned out because nilfs_cleanerd is usually executed by
mount.nilfs2 program with the nofork option (-n).

To fix this problem, it looks like the above !nofork check of the
second fork() should be removed even though it becomes confusing.  In
that case, we may need to add some explanation why fork() should be
called even if nofork is specified.


Regards,
Ryusuke Konishi


>  	if (!nochdir && (chdir(ROOTDIR) < 0))
>  		return -1;
>  
> -- 
> 1.8.1.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]         ` <20140101.183018.491730600.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
@ 2014-01-04 13:18           ` Hitoshi Mitake
       [not found]             ` <CAE1WaKLvwoTwM0W5Wsv0wcWSzihWLjifNi3HXsPt3XK529tanQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Hitoshi Mitake @ 2014-01-04 13:18 UTC (permalink / raw)
  To: Ryusuke Konishi; +Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On Wed, Jan 1, 2014 at 6:30 PM, Ryusuke Konishi
<konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org> wrote:
> On Wed,  1 Jan 2014 16:30:48 +0900, Hitoshi Mitake wrote:
>> Current daemonize() function of cleanerd call _exit(2) only once during its
>> process of becoming a daemon process. But in the linux environment, a daemon
>> process should call _exit(2) twice for ensuring not being a session leader. If a
>> process don't do that, unexpected SIGHUP can be sent to the process (though it
>> happens rarely). The signal would be confusing event for cleanerd of nilfs. This
>> patch removes this potential problem.
>>
>> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
>> ---
>>  sbin/cleanerd/cleanerd.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
>> index 26067bd..edfa083 100644
>> --- a/sbin/cleanerd/cleanerd.c
>> +++ b/sbin/cleanerd/cleanerd.c
>> @@ -676,6 +676,16 @@ static int daemonize(int nochdir, int noclose, int nofork)
>>
>>       /* umask(0); */
>>
>> +     /* for ensuring I'm not a session leader */
>> +     if (!nofork) {
>> +             pid = fork();
>> +             if (pid < 0)
>> +                     return -1;
>> +             else if (pid != 0)
>> +                     /* parent */
>> +                     _exit(0);
>> +     }
>> +
>
> I tried your patch, but the cleaner daemon still was a session leader.

Thanks for your review and testing.

>
> This turned out because nilfs_cleanerd is usually executed by
> mount.nilfs2 program with the nofork option (-n).
>
> To fix this problem, it looks like the above !nofork check of the
> second fork() should be removed even though it becomes confusing.  In
> that case, we may need to add some explanation why fork() should be
> called even if nofork is specified.

For ensuring not being a session leader, fork() should be called twice. Removing
the second condition of !nofork is not enough. For this purpose, we need to
remove both of the conditions of !nofork.

BTW, what is an intention of "-n" option of cleanerd? I read the code of
nilfs_launch_cleanerd() but couldn't understand the reason of this option.

If this option is aiming to reduce calling of fork(), I think this can be
eliminated. Calling 3 fork()s (1 in mount.nilfs2, 2 in cleanerd) would be
acceptable.

Thanks,
Hitoshi
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]             ` <CAE1WaKLvwoTwM0W5Wsv0wcWSzihWLjifNi3HXsPt3XK529tanQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-01-04 14:28               ` Ryusuke Konishi
       [not found]                 ` <20140104.232806.190364467.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Ryusuke Konishi @ 2014-01-04 14:28 UTC (permalink / raw)
  To: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w
  Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA,
	mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg

Hi,
On Sat, 4 Jan 2014 22:18:00 +0900, Hitoshi Mitake wrote:
> On Wed, Jan 1, 2014 at 6:30 PM, Ryusuke Konishi
> <konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org> wrote:
>> On Wed,  1 Jan 2014 16:30:48 +0900, Hitoshi Mitake wrote:
>>> Current daemonize() function of cleanerd call _exit(2) only once during its
>>> process of becoming a daemon process. But in the linux environment, a daemon
>>> process should call _exit(2) twice for ensuring not being a session leader. If a
>>> process don't do that, unexpected SIGHUP can be sent to the process (though it
>>> happens rarely). The signal would be confusing event for cleanerd of nilfs. This
>>> patch removes this potential problem.
>>>
>>> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
>>> ---
>>>  sbin/cleanerd/cleanerd.c | 10 ++++++++++
>>>  1 file changed, 10 insertions(+)
>>>
>>> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
>>> index 26067bd..edfa083 100644
>>> --- a/sbin/cleanerd/cleanerd.c
>>> +++ b/sbin/cleanerd/cleanerd.c
>>> @@ -676,6 +676,16 @@ static int daemonize(int nochdir, int noclose, int nofork)
>>>
>>>       /* umask(0); */
>>>
>>> +     /* for ensuring I'm not a session leader */
>>> +     if (!nofork) {
>>> +             pid = fork();
>>> +             if (pid < 0)
>>> +                     return -1;
>>> +             else if (pid != 0)
>>> +                     /* parent */
>>> +                     _exit(0);
>>> +     }
>>> +
>>
>> I tried your patch, but the cleaner daemon still was a session leader.
> 
> Thanks for your review and testing.
> 
>>
>> This turned out because nilfs_cleanerd is usually executed by
>> mount.nilfs2 program with the nofork option (-n).
>>
>> To fix this problem, it looks like the above !nofork check of the
>> second fork() should be removed even though it becomes confusing.  In
>> that case, we may need to add some explanation why fork() should be
>> called even if nofork is specified.
> 
> For ensuring not being a session leader, fork() should be called twice. Removing
> the second condition of !nofork is not enough. For this purpose, we need to
> remove both of the conditions of !nofork.

Yes, I supposed here that the caller (the mount helper program)
already did a fork() call when -n option is specified.

But, anyway, removing only the latter check of !nofork isn't a good
idea.  It's a hacky.

> BTW, what is an intention of "-n" option of cleanerd? I read the code of
> nilfs_launch_cleanerd() but couldn't understand the reason of this option.

This is an option just to avoid fork doubly when mount.nilfs2 already
did a fork().

> If this option is aiming to reduce calling of fork(), I think this can be
> eliminated. Calling 3 fork()s (1 in mount.nilfs2, 2 in cleanerd) would be
> acceptable.

Okay, accepting 3 forks()s seems reasonable.  So, how about changing
both programs as follow?

 1) Change cleanerd to simply ignore -n option as a historical option
    (remove the existing !nofork check).
 2) Change cleanerd always fork twice to ensure that it will not be a
    session leader.
 3) Change cleaner_exec.c not to add -n option.

Thanks,
Ryusuke Konishi
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]                 ` <20140104.232806.190364467.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
@ 2014-01-05 15:24                   ` Hitoshi Mitake
  0 siblings, 0 replies; 8+ messages in thread
From: Hitoshi Mitake @ 2014-01-05 15:24 UTC (permalink / raw)
  To: Ryusuke Konishi
  Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w,
	linux-nilfs-u79uwXL29TY76Z2rM5mHXA,
	mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg

At Sat, 04 Jan 2014 23:28:06 +0900 (JST),
Ryusuke Konishi wrote:
> 
> Hi,
> On Sat, 4 Jan 2014 22:18:00 +0900, Hitoshi Mitake wrote:
> > On Wed, Jan 1, 2014 at 6:30 PM, Ryusuke Konishi
> > <konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org> wrote:
> >> On Wed,  1 Jan 2014 16:30:48 +0900, Hitoshi Mitake wrote:
> >>> Current daemonize() function of cleanerd call _exit(2) only once during its
> >>> process of becoming a daemon process. But in the linux environment, a daemon
> >>> process should call _exit(2) twice for ensuring not being a session leader. If a
> >>> process don't do that, unexpected SIGHUP can be sent to the process (though it
> >>> happens rarely). The signal would be confusing event for cleanerd of nilfs. This
> >>> patch removes this potential problem.
> >>>
> >>> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
> >>> ---
> >>>  sbin/cleanerd/cleanerd.c | 10 ++++++++++
> >>>  1 file changed, 10 insertions(+)
> >>>
> >>> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
> >>> index 26067bd..edfa083 100644
> >>> --- a/sbin/cleanerd/cleanerd.c
> >>> +++ b/sbin/cleanerd/cleanerd.c
> >>> @@ -676,6 +676,16 @@ static int daemonize(int nochdir, int noclose, int nofork)
> >>>
> >>>       /* umask(0); */
> >>>
> >>> +     /* for ensuring I'm not a session leader */
> >>> +     if (!nofork) {
> >>> +             pid = fork();
> >>> +             if (pid < 0)
> >>> +                     return -1;
> >>> +             else if (pid != 0)
> >>> +                     /* parent */
> >>> +                     _exit(0);
> >>> +     }
> >>> +
> >>
> >> I tried your patch, but the cleaner daemon still was a session leader.
> > 
> > Thanks for your review and testing.
> > 
> >>
> >> This turned out because nilfs_cleanerd is usually executed by
> >> mount.nilfs2 program with the nofork option (-n).
> >>
> >> To fix this problem, it looks like the above !nofork check of the
> >> second fork() should be removed even though it becomes confusing.  In
> >> that case, we may need to add some explanation why fork() should be
> >> called even if nofork is specified.
> > 
> > For ensuring not being a session leader, fork() should be called twice. Removing
> > the second condition of !nofork is not enough. For this purpose, we need to
> > remove both of the conditions of !nofork.
> 
> Yes, I supposed here that the caller (the mount helper program)
> already did a fork() call when -n option is specified.
> 
> But, anyway, removing only the latter check of !nofork isn't a good
> idea.  It's a hacky.
> 
> > BTW, what is an intention of "-n" option of cleanerd? I read the code of
> > nilfs_launch_cleanerd() but couldn't understand the reason of this option.
> 
> This is an option just to avoid fork doubly when mount.nilfs2 already
> did a fork().
> 
> > If this option is aiming to reduce calling of fork(), I think this can be
> > eliminated. Calling 3 fork()s (1 in mount.nilfs2, 2 in cleanerd) would be
> > acceptable.
> 
> Okay, accepting 3 forks()s seems reasonable.  So, how about changing
> both programs as follow?
> 
>  1) Change cleanerd to simply ignore -n option as a historical option
>     (remove the existing !nofork check).
>  2) Change cleanerd always fork twice to ensure that it will not be a
>     session leader.
>  3) Change cleaner_exec.c not to add -n option.

I agree with the above 3 policies. I'll send v2 based on them later.

Thanks,
Hitoshi
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-01-05 15:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01  7:30 [PATCH nilfs-utils 0/2] trivial improvements of cleanerd Hitoshi Mitake
     [not found] ` <1388561449-13980-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-01  7:30   ` [PATCH nilfs-utils 1/2] cleanerd: call _exit(2) twice for ensuring not being a session leader Hitoshi Mitake
     [not found]     ` <1388561449-13980-2-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-01  9:30       ` Ryusuke Konishi
     [not found]         ` <20140101.183018.491730600.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-04 13:18           ` Hitoshi Mitake
     [not found]             ` <CAE1WaKLvwoTwM0W5Wsv0wcWSzihWLjifNi3HXsPt3XK529tanQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-04 14:28               ` Ryusuke Konishi
     [not found]                 ` <20140104.232806.190364467.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-05 15:24                   ` Hitoshi Mitake
2014-01-01  7:30   ` [PATCH nilfs-utils 2/2] cleanerd: adjust the OOM killer Hitoshi Mitake
     [not found]     ` <1388561449-13980-3-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-01  9:16       ` Ryusuke Konishi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.