[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH] Correct problem with initrd.addrsize generation (#546422)



Please do also adapt the error message just in case this breaks during
compose in the future so we know exactly where it broke.

On 05/25/2010 07:51 PM, David Cantrell wrote:
> The last write() line was writing out the addr value again instead of
> size.  Also include libgen.h for basename() call and lose the char *
> we never use from the strtoul() call.
> ---
>  utils/addrsize.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/addrsize.c b/utils/addrsize.c
> index 5933a00..f1b1a7d 100644
> --- a/utils/addrsize.c
> +++ b/utils/addrsize.c
> @@ -32,6 +32,7 @@
>  #include <unistd.h>
>  #include <errno.h>
>  #include <string.h>
> +#include <libgen.h>
> 
>  int main(int argc,char **argv) {
>      char *cmd = basename(argv[0]);
> @@ -39,7 +40,6 @@ int main(int argc,char **argv) {
>      struct stat initrd_stat;
>      unsigned int addr = 0, size = 0, zero = 0;
>      int fd, rc;
> -    char *tmp = NULL;
>      mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
> 
>      if (argc != 4) {
> @@ -59,7 +59,7 @@ int main(int argc,char **argv) {
>          return 2;
>      }
> 
> -    addr = htonl(strtoul(address, &tmp, 0));
> +    addr = htonl(strtoul(address, NULL, 0));
>      size = htonl(initrd_stat.st_size);
>      fd = open(output, O_CREAT | O_RDWR, mode);
> 
> @@ -78,7 +78,7 @@ int main(int argc,char **argv) {
>          return 5;
>      }
> 
> -    if (write(fd, &addr, sizeof(int)) == -1) {
> +    if (write(fd, &size, sizeof(int)) == -1) {
>          perror("writing initrd.addr (zero) ");

           perror("writing initrd.addrsize (size) ");

And while you're at it, please also make the other three error messages
before this one meaningful, i.e. use the sequence
zero, addr, zero, size
in the parentheses to tell which part could not be written.

>          return 6;
>      }

Steffen

Linux on System z Development

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]