All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nilfs-utils v2 0/4] rework daemonize() of cleanerd
@ 2014-01-05 15:52 Hitoshi Mitake
       [not found] ` <1388937165-32692-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Hitoshi Mitake @ 2014-01-05 15:52 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA; +Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w

Current daemonize() function of cleanerd has a problem. It cannot ensure that
the caller (cleanerd) doesn't become a session leader.

This patchset solves the above problem. In addition, the -n option of cleanerd
is removed because it is obsolete. The description of the option in a man page
is also removed.

Hitoshi Mitake (4):
  cleanerd: ignore nofork option
  cleanerd: call _exit(2) twice for ensuring not being a session leader
  mount: don't pass -n option to cleanerd
  man: remove a description of -n option

 lib/cleaner_exec.c       |  4 +---
 man/nilfs_cleanerd.8     |  4 ----
 sbin/cleanerd/cleanerd.c | 36 ++++++++++++++++++++----------------
 3 files changed, 21 insertions(+), 23 deletions(-)

-- 
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] 12+ messages in thread

* [PATCH nilfs-utils v2 1/4] cleanerd: ignore nofork option
       [not found] ` <1388937165-32692-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-05 15:52   ` Hitoshi Mitake
       [not found]     ` <1388937165-32692-2-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader Hitoshi Mitake
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Hitoshi Mitake @ 2014-01-05 15:52 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA
  Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w, Hitoshi Mitake

The nofork option aims to reduce call of fork(), but it is not
effective. This patch lets cleanerd ignore the option simply even if
it is passed.

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

diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
index e1f6a04..0b5bb70 100644
--- a/sbin/cleanerd/cleanerd.c
+++ b/sbin/cleanerd/cleanerd.c
@@ -113,7 +113,7 @@ do {						\
 const static struct option long_option[] = {
 	{"conffile", required_argument, NULL, 'c'},
 	{"help", no_argument, NULL, 'h'},
-	/* internal option for mount.nilfs2 only */
+	/* nofork option is obsolete. It does nothing even if passed */
 	{"nofork", no_argument, NULL, 'n'},
 	{"protection-period", required_argument, NULL, 'p'},
 	{"version", no_argument, NULL, 'V'},
@@ -691,20 +691,18 @@ static int oom_adjust(void)
 #define DEVNULL	"/dev/null"
 #define ROOTDIR	"/"
 
-static int daemonize(int nochdir, int noclose, int nofork)
+static int daemonize(int nochdir, int noclose)
 {
 	pid_t pid;
 
-	if (!nofork) {
-		pid = fork();
-		if (pid < 0)
-			return -1;
-		else if (pid != 0)
-			/* parent */
-			_exit(0);
-	}
+	pid = fork();
+	if (pid < 0)
+		return -1;
+	else if (pid != 0)
+		/* parent */
+		_exit(0);
 
-	/* child or nofork */
+	/* child */
 	if (setsid() < 0)
 		return -1;
 
@@ -1491,7 +1489,7 @@ int main(int argc, char *argv[])
 	char canonical[PATH_MAX + 2];
 	const char *dev, *dir;
 	char *endptr;
-	int status, nofork, c;
+	int status, c;
 #ifdef _GNU_SOURCE
 	int option_index;
 #endif	/* _GNU_SOURCE */
@@ -1499,7 +1497,6 @@ int main(int argc, char *argv[])
 	progname = (strrchr(argv[0], '/') != NULL) ?
 		strrchr(argv[0], '/') + 1 : argv[0];
 	conffile = NILFS_CLEANERD_CONFFILE;
-	nofork = 0;
 	status = 0;
 	protection_period = ULONG_MAX;
 	dev = NULL;
@@ -1520,8 +1517,7 @@ int main(int argc, char *argv[])
 			nilfs_cleanerd_usage(progname);
 			exit(0);
 		case 'n':
-			/* internal option for mount.nilfs2 only */
-			nofork = 1;
+			/* ignore nofork option, do nothing */
 			break;
 		case 'p':
 			protection_period = strtoul(optarg, &endptr, 10);
@@ -1568,7 +1564,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	if (daemonize(0, 0, nofork) < 0) {
+	if (daemonize(0, 0) < 0) {
 		fprintf(stderr, "%s: %s\n", progname, strerror(errno));
 		exit(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] 12+ messages in thread

* [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found] ` <1388937165-32692-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 1/4] cleanerd: ignore nofork option Hitoshi Mitake
@ 2014-01-05 15:52   ` Hitoshi Mitake
       [not found]     ` <1388937165-32692-3-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 3/4] mount: don't pass -n option to cleanerd Hitoshi Mitake
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 4/4] man: remove a description of -n option Hitoshi Mitake
  3 siblings, 1 reply; 12+ messages in thread
From: Hitoshi Mitake @ 2014-01-05 15:52 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
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 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
index 0b5bb70..86dfcf7 100644
--- a/sbin/cleanerd/cleanerd.c
+++ b/sbin/cleanerd/cleanerd.c
@@ -708,6 +708,14 @@ static int daemonize(int nochdir, int noclose)
 
 	/* umask(0); */
 
+	/* for ensuring I'm not a session leader */
+	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] 12+ messages in thread

* [PATCH nilfs-utils v2 3/4] mount: don't pass -n option to cleanerd
       [not found] ` <1388937165-32692-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 1/4] cleanerd: ignore nofork option Hitoshi Mitake
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader Hitoshi Mitake
@ 2014-01-05 15:52   ` Hitoshi Mitake
       [not found]     ` <1388937165-32692-4-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 4/4] man: remove a description of -n option Hitoshi Mitake
  3 siblings, 1 reply; 12+ messages in thread
From: Hitoshi Mitake @ 2014-01-05 15:52 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA
  Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w, Hitoshi Mitake

This patch lets mount.nilfs2 not pass the -n option to cleanerd,
because it is obsoleted.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
---
 lib/cleaner_exec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/cleaner_exec.c b/lib/cleaner_exec.c
index 299451c..edc55e3 100644
--- a/lib/cleaner_exec.c
+++ b/lib/cleaner_exec.c
@@ -75,7 +75,6 @@
 #define WAIT_CLEANERD_RETRY_TIMEOUT	8	/* in seconds */
 
 static const char cleanerd[] = "/sbin/" NILFS_CLEANERD_NAME;
-static const char cleanerd_nofork_opt[] = "-n";
 static const char cleanerd_protperiod_opt[] = "-p";
 
 static void default_logger(int priority, const char *fmt, ...)
@@ -118,7 +117,7 @@ static inline int process_is_alive(pid_t pid)
 int nilfs_launch_cleanerd(const char *device, const char *mntdir,
 			  unsigned long protperiod, pid_t *ppid)
 {
-	const char *dargs[7];
+	const char *dargs[6];
 	struct stat statbuf;
 	sigset_t sigs;
 	int i = 0;
@@ -146,7 +145,6 @@ int nilfs_launch_cleanerd(const char *device, const char *mntdir,
 			exit(1);
 		}
 		dargs[i++] = cleanerd;
-		dargs[i++] = cleanerd_nofork_opt;
 		if (protperiod != ULONG_MAX) {
 			dargs[i++] = cleanerd_protperiod_opt;
 			snprintf(buf, sizeof(buf), "%lu", protperiod);
-- 
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] 12+ messages in thread

* [PATCH nilfs-utils v2 4/4] man: remove a description of -n option
       [not found] ` <1388937165-32692-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2014-01-05 15:52   ` [PATCH nilfs-utils v2 3/4] mount: don't pass -n option to cleanerd Hitoshi Mitake
@ 2014-01-05 15:52   ` Hitoshi Mitake
       [not found]     ` <1388937165-32692-5-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  3 siblings, 1 reply; 12+ messages in thread
From: Hitoshi Mitake @ 2014-01-05 15:52 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA
  Cc: mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w, Hitoshi Mitake

Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
---
 man/nilfs_cleanerd.8 | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/man/nilfs_cleanerd.8 b/man/nilfs_cleanerd.8
index ad6d188..46caef2 100644
--- a/man/nilfs_cleanerd.8
+++ b/man/nilfs_cleanerd.8
@@ -35,10 +35,6 @@ Display help message and exit.
 \fB\-c \fIfile\fR, \fB\-\-conf\fR=\fIfile\fR
 Specify configuration file.
 .TP
-\fB\-n\fR, \fB\-\-nofork\fR
-invoke cleanerd without forking process. This option is intended for
-internal use from \fBmount.nilfs2\fP(8).
-.TP
 \fB\-p \fIinterval\fR, \fB\-\-protection-period\fR=\fIinterval\fR
 Override protection period with the specified number of seconds.
 .SH SIGNALS
-- 
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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 1/4] cleanerd: ignore nofork option
       [not found]     ` <1388937165-32692-2-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-05 17:19       ` Ryusuke Konishi
  0 siblings, 0 replies; 12+ messages in thread
From: Ryusuke Konishi @ 2014-01-05 17:19 UTC (permalink / raw)
  To: Hitoshi Mitake; +Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On Mon,  6 Jan 2014 00:52:42 +0900, Hitoshi Mitake wrote:
> The nofork option aims to reduce call of fork(), but it is not
> effective. This patch lets cleanerd ignore the option simply even if
> it is passed.
> 
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
> ---
>  sbin/cleanerd/cleanerd.c | 28 ++++++++++++----------------
>  1 file changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
> index e1f6a04..0b5bb70 100644
> --- a/sbin/cleanerd/cleanerd.c
> +++ b/sbin/cleanerd/cleanerd.c
> @@ -113,7 +113,7 @@ do {						\
>  const static struct option long_option[] = {
>  	{"conffile", required_argument, NULL, 'c'},
>  	{"help", no_argument, NULL, 'h'},
> -	/* internal option for mount.nilfs2 only */
> +	/* nofork option is obsolete. It does nothing even if passed */
>  	{"nofork", no_argument, NULL, 'n'},
>  	{"protection-period", required_argument, NULL, 'p'},
>  	{"version", no_argument, NULL, 'V'},
> @@ -691,20 +691,18 @@ static int oom_adjust(void)
>  #define DEVNULL	"/dev/null"
>  #define ROOTDIR	"/"
>  
> -static int daemonize(int nochdir, int noclose, int nofork)
> +static int daemonize(int nochdir, int noclose)
>  {
>  	pid_t pid;
>  
> -	if (!nofork) {
> -		pid = fork();
> -		if (pid < 0)
> -			return -1;
> -		else if (pid != 0)
> -			/* parent */
> -			_exit(0);
> -	}
> +	pid = fork();
> +	if (pid < 0)
> +		return -1;
> +	else if (pid != 0)
> +		/* parent */
> +		_exit(0);
>  
> -	/* child or nofork */
> +	/* child */
>  	if (setsid() < 0)
>  		return -1;
>  
> @@ -1491,7 +1489,7 @@ int main(int argc, char *argv[])
>  	char canonical[PATH_MAX + 2];
>  	const char *dev, *dir;
>  	char *endptr;
> -	int status, nofork, c;
> +	int status, c;
>  #ifdef _GNU_SOURCE
>  	int option_index;
>  #endif	/* _GNU_SOURCE */
> @@ -1499,7 +1497,6 @@ int main(int argc, char *argv[])
>  	progname = (strrchr(argv[0], '/') != NULL) ?
>  		strrchr(argv[0], '/') + 1 : argv[0];
>  	conffile = NILFS_CLEANERD_CONFFILE;
> -	nofork = 0;
>  	status = 0;
>  	protection_period = ULONG_MAX;
>  	dev = NULL;
> @@ -1520,8 +1517,7 @@ int main(int argc, char *argv[])
>  			nilfs_cleanerd_usage(progname);
>  			exit(0);
>  		case 'n':
> -			/* internal option for mount.nilfs2 only */
> -			nofork = 1;
> +			/* ignore nofork option, do nothing */
>  			break;
>  		case 'p':
>  			protection_period = strtoul(optarg, &endptr, 10);
> @@ -1568,7 +1564,7 @@ int main(int argc, char *argv[])
>  		}
>  	}
>  
> -	if (daemonize(0, 0, nofork) < 0) {
> +	if (daemonize(0, 0) < 0) {
>  		fprintf(stderr, "%s: %s\n", progname, strerror(errno));
>  		exit(1);
>  	}
> -- 
> 1.8.1.2

Looks good to me. Applied.

Thank a lot.

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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]     ` <1388937165-32692-3-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-05 17:20       ` Ryusuke Konishi
       [not found]         ` <20140106.022042.112826181.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Ryusuke Konishi @ 2014-01-05 17:20 UTC (permalink / raw)
  To: Hitoshi Mitake; +Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On Mon,  6 Jan 2014 00:52:43 +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
> 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 | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
> index 0b5bb70..86dfcf7 100644
> --- a/sbin/cleanerd/cleanerd.c
> +++ b/sbin/cleanerd/cleanerd.c
> @@ -708,6 +708,14 @@ static int daemonize(int nochdir, int noclose)
>  
>  	/* umask(0); */
>  
> +	/* for ensuring I'm not a session leader */
> +	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

Looks good.

Applied, thank you.

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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 3/4] mount: don't pass -n option to cleanerd
       [not found]     ` <1388937165-32692-4-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-05 17:21       ` Ryusuke Konishi
  0 siblings, 0 replies; 12+ messages in thread
From: Ryusuke Konishi @ 2014-01-05 17:21 UTC (permalink / raw)
  To: Hitoshi Mitake; +Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On Mon,  6 Jan 2014 00:52:44 +0900, Hitoshi Mitake wrote:
> This patch lets mount.nilfs2 not pass the -n option to cleanerd,
> because it is obsoleted.
> 
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
> ---
>  lib/cleaner_exec.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/lib/cleaner_exec.c b/lib/cleaner_exec.c
> index 299451c..edc55e3 100644
> --- a/lib/cleaner_exec.c
> +++ b/lib/cleaner_exec.c
> @@ -75,7 +75,6 @@
>  #define WAIT_CLEANERD_RETRY_TIMEOUT	8	/* in seconds */
>  
>  static const char cleanerd[] = "/sbin/" NILFS_CLEANERD_NAME;
> -static const char cleanerd_nofork_opt[] = "-n";
>  static const char cleanerd_protperiod_opt[] = "-p";
>  
>  static void default_logger(int priority, const char *fmt, ...)
> @@ -118,7 +117,7 @@ static inline int process_is_alive(pid_t pid)
>  int nilfs_launch_cleanerd(const char *device, const char *mntdir,
>  			  unsigned long protperiod, pid_t *ppid)
>  {
> -	const char *dargs[7];
> +	const char *dargs[6];
>  	struct stat statbuf;
>  	sigset_t sigs;
>  	int i = 0;
> @@ -146,7 +145,6 @@ int nilfs_launch_cleanerd(const char *device, const char *mntdir,
>  			exit(1);
>  		}
>  		dargs[i++] = cleanerd;
> -		dargs[i++] = cleanerd_nofork_opt;
>  		if (protperiod != ULONG_MAX) {
>  			dargs[i++] = cleanerd_protperiod_opt;
>  			snprintf(buf, sizeof(buf), "%lu", protperiod);
> -- 
> 1.8.1.2

Looks good, applied.

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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 4/4] man: remove a description of -n option
       [not found]     ` <1388937165-32692-5-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-01-05 17:22       ` Ryusuke Konishi
  0 siblings, 0 replies; 12+ messages in thread
From: Ryusuke Konishi @ 2014-01-05 17:22 UTC (permalink / raw)
  To: Hitoshi Mitake; +Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On Mon,  6 Jan 2014 00:52:45 +0900, Hitoshi Mitake wrote:
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
> ---
>  man/nilfs_cleanerd.8 | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/man/nilfs_cleanerd.8 b/man/nilfs_cleanerd.8
> index ad6d188..46caef2 100644
> --- a/man/nilfs_cleanerd.8
> +++ b/man/nilfs_cleanerd.8
> @@ -35,10 +35,6 @@ Display help message and exit.
>  \fB\-c \fIfile\fR, \fB\-\-conf\fR=\fIfile\fR
>  Specify configuration file.
>  .TP
> -\fB\-n\fR, \fB\-\-nofork\fR
> -invoke cleanerd without forking process. This option is intended for
> -internal use from \fBmount.nilfs2\fP(8).
> -.TP
>  \fB\-p \fIinterval\fR, \fB\-\-protection-period\fR=\fIinterval\fR
>  Override protection period with the specified number of seconds.
>  .SH SIGNALS
> -- 
> 1.8.1.2

Applied, thank you.

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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]         ` <20140106.022042.112826181.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
@ 2014-01-05 18:28           ` Ryusuke Konishi
       [not found]             ` <CAFPMYnH8LTD9ctZCSht5NZv6j1TZMfpCZh2pHyLO4wN-5dRDdw@mail.gmail.com>
       [not found]             ` <20140106.032857.373562363.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Ryusuke Konishi @ 2014-01-05 18:28 UTC (permalink / raw)
  To: Hitoshi Mitake; +Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On Mon, 06 Jan 2014 02:20:42 +0900 (JST), Ryusuke Konishi wrote:
> On Mon,  6 Jan 2014 00:52:43 +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
>> 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 | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>> 
>> diff --git a/sbin/cleanerd/cleanerd.c b/sbin/cleanerd/cleanerd.c
>> index 0b5bb70..86dfcf7 100644
>> --- a/sbin/cleanerd/cleanerd.c
>> +++ b/sbin/cleanerd/cleanerd.c
>> @@ -708,6 +708,14 @@ static int daemonize(int nochdir, int noclose)
>>  
>>  	/* umask(0); */
>>  
>> +	/* for ensuring I'm not a session leader */
>> +	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
> 
> Looks good.
> 
> Applied, thank you.
> 
> Ryusuke Konishi

Oh no, I found this series has a critical issue after I applied them.

The current umount.nilfs2 (and mount.nilfs2 -o remount,nogc) uses pid
of cleanerd to shutdown it, and this series breaks the logic since the
fork of cleanerd changes its pid.  That was the true reason why nofork
option is required.

We need to fix it by reverting the series or other means.

Regards,
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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]               ` <CAFPMYnH8LTD9ctZCSht5NZv6j1TZMfpCZh2pHyLO4wN-5dRDdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-01-06  3:53                 ` Hitoshi Mitake
  0 siblings, 0 replies; 12+ messages in thread
From: Hitoshi Mitake @ 2014-01-06  3:53 UTC (permalink / raw)
  To: Сергей Александров
  Cc: Ryusuke Konishi, Hitoshi Mitake,
	linux-nilfs-u79uwXL29TY76Z2rM5mHXA

At Sun, 5 Jan 2014 22:44:41 +0400,
Сергей Александров wrote:
> 
> [1  <text/plain; KOI8-R (quoted-printable)>]
> Hello,
> May be it makes sense to use pid files in /var/run folder with special
> names like nilfs_cleanerd_<dev>.pid (nilfs_cleanerd_sda1.pid for instance)
> for this purpose? But it looks a little bit over engineered and may also
> have some issues while mounting from initrd.
> 
> Regards,
> Aleksandrov Sergey

OKay, I'll try to solve the problem with a way of pidfile or other methods.
If we can't find a suitable way, let's revert the series.

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] 12+ messages in thread

* Re: [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader
       [not found]             ` <20140106.032857.373562363.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
@ 2014-01-07 21:19               ` Michael Conrad
  0 siblings, 0 replies; 12+ messages in thread
From: Michael Conrad @ 2014-01-07 21:19 UTC (permalink / raw)
  To: Ryusuke Konishi, Hitoshi Mitake
  Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Hitoshi Mitake

On 1/5/2014 1:28 PM, Ryusuke Konishi wrote:
> Oh no, I found this series has a critical issue after I applied them.
>
> The current umount.nilfs2 (and mount.nilfs2 -o remount,nogc) uses pid
> of cleanerd to shutdown it, and this series breaks the logic since the
> fork of cleanerd changes its pid.  That was the true reason why nofork
> option is required.
>
> We need to fix it by reverting the series or other means.
>
> Regards,
> Ryusuke Konishi

 From what I've learned of writing daemons, good practice is:

   * Allow an option for writing a PID file, but don't by default 
(location is often distro-specific)
   * To daemonize, double-fork, chdir("/"), and then redirect stdin, 
stdout, stderr to /dev/null
   * Allow users to request messages to syslog, since stdout is lost.
   * If you want to capture the PID, have an option to print it on 
stderr before redirecting to /dev/null.  The caller can read a pipe to 
find the final PID of the daemon.
   * Allow the option to run the program in the foreground (i.e. do not 
daemonize at all) for debugging or in case you want to run the daemon 
from a monitoring program which wait()s on it.  In this case do not 
close stdout, so that debugging messages may be seen on the terminal, or 
the messages can be piped to a logger.

Until now, I had thought "-n" was the "no-daemonize" option, which I 
thought was strange for mount to use.

-Mike
--
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] 12+ messages in thread

end of thread, other threads:[~2014-01-07 21:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-05 15:52 [PATCH nilfs-utils v2 0/4] rework daemonize() of cleanerd Hitoshi Mitake
     [not found] ` <1388937165-32692-1-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-05 15:52   ` [PATCH nilfs-utils v2 1/4] cleanerd: ignore nofork option Hitoshi Mitake
     [not found]     ` <1388937165-32692-2-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-05 17:19       ` Ryusuke Konishi
2014-01-05 15:52   ` [PATCH nilfs-utils v2 2/4] cleanerd: call _exit(2) twice for ensuring not being a session leader Hitoshi Mitake
     [not found]     ` <1388937165-32692-3-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-05 17:20       ` Ryusuke Konishi
     [not found]         ` <20140106.022042.112826181.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-05 18:28           ` Ryusuke Konishi
     [not found]             ` <CAFPMYnH8LTD9ctZCSht5NZv6j1TZMfpCZh2pHyLO4wN-5dRDdw@mail.gmail.com>
     [not found]               ` <CAFPMYnH8LTD9ctZCSht5NZv6j1TZMfpCZh2pHyLO4wN-5dRDdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-06  3:53                 ` Hitoshi Mitake
     [not found]             ` <20140106.032857.373562363.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-07 21:19               ` Michael Conrad
2014-01-05 15:52   ` [PATCH nilfs-utils v2 3/4] mount: don't pass -n option to cleanerd Hitoshi Mitake
     [not found]     ` <1388937165-32692-4-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-05 17:21       ` Ryusuke Konishi
2014-01-05 15:52   ` [PATCH nilfs-utils v2 4/4] man: remove a description of -n option Hitoshi Mitake
     [not found]     ` <1388937165-32692-5-git-send-email-mitake.hitoshi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-05 17:22       ` 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.