[PATCH] start-stop-daemon fails to stop processes and sometimes fails to start them.

Denys Vlasenko vda.linux at googlemail.com
Sat Apr 19 03:13:26 UTC 2008


On Thursday 17 April 2008 19:02, Joakim Tjernlund wrote:
> pid_is_cmd() would call "die" if it got a stale file.
> readdir() will fail if a file becomes stale, detect this and
> move on.
> 
> This patch is aginst bb 1.8.2 gentoo version so it might not apply
> cleanly. I hope that wont be a problem.

Hrm :(

> --- debianutils/start_stop_daemon.c.org	2008-04-17 16:02:51.000000000 +0200
> +++ debianutils/start_stop_daemon.c	2008-04-17 18:30:56.000000000 +0200
> @@ -62,16 +62,17 @@
>  	return (sb.st_uid == uid);
>  }
>  
> +#define MAX_READ 1024
>  static int pid_is_cmd(pid_t pid, const char *name)
>  {
>  	char fname[sizeof("/proc//stat") + sizeof(int)*3];
> -	char *buf;
> +	char buf[MAX_READ+1], *p;
>  	int r = 0;
>  
>  	sprintf(fname, "/proc/%u/stat", pid);
> -	buf = xmalloc_open_read_close(fname, NULL);
> -	if (buf) {
> -		char *p = strchr(buf, '(');
> +	if (open_read_close(fname, buf, MAX_READ) > 0) {

I think that it's better to fix xmalloc_open_read_close
to not die if fie does not exist. After all, it is not called
xmalloc_xopen_read_close, right?

>  	foundany = 0;
> -	while ((entry = readdir(procdir)) != NULL) {
> -		pid = bb_strtou(entry->d_name, NULL, 10);
> -		if (errno)
> +	while(1) {
> +		errno = 0;
> +		entry = readdir(procdir);
> +		if (errno) /* Stale file ? */
>  			continue;

When exactly this happens? I would like to document it in comment.

> +		if (!entry)
> +			break;
> +		pid = bb_strtou(entry->d_name, NULL, 10);
>  		foundany++;
> +		if (pid == UINT_MAX) /* NaN */
> +			continue;

I think foundany++ must be after this check.
--
vda



More information about the busybox mailing list