[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH v2] fixdep: add fstat error handling
From:       David Leonard <d+busybox () adaptive-enterprises ! com>
Date:       2024-04-25 8:21:01
Message-ID: 60o10n01-70q9-p3oo-o70r-np2n6o58s21s () nqncgvir-ragrecevfrf ! pbz
[Download RAW message or body]


On Tue, 23 Apr 2024, Sam James wrote:

> 	}
> -	fstat(fd, &st);
> +	if (fstat(fd, &st) < 0) {
> +		fprintf(stderr, "fixdep: fstat");
> +		perror(filename);
> +		exit(2);
> +	}
> 	if (st.st_size == 0) {
> 		close(fd);
> 		return;
> @@ -368,7 +372,11 @@ void print_deps(void)
> 		perror(depfile);
> 		exit(2);
> 	}
> -	fstat(fd, &st);
> +	if (fstat(fd, &st) < 0) {
> +		fprintf(stderr, "fixdep: fstat");
> +		perror(depfile);
> +		exit(2);
> +	}
> 	if (st.st_size == 0) {
> 		fprintf(stderr,"fixdep: %s is empty\n",depfile);
> 		close(fd);

I worry that the fprintf() may destroy the errno which perror() uses,
so you could get a random error message.
Perhaps remove the fprintf(s) completely? Because the context should be
clear enough from the filename alone that perror displays.

David
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic