Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Oct 2004 16:53:51 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-current@freebsd.org
Cc:        Sam <sah@softcardsystems.com>
Subject:   Re: fdisk buglet
Message-ID:  <200410191653.51979.jhb@FreeBSD.org>
In-Reply-To: <20041016064414.GC66090@ip.net.ua>
References:  <Pine.LNX.4.60.0410151632100.21014@athena> <20041016064414.GC66090@ip.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Saturday 16 October 2004 02:44 am, Ruslan Ermilov wrote:
> On Fri, Oct 15, 2004 at 04:34:11PM -0500, Sam wrote:
> > fivethree% fdisk /dev/ad1
> > fdisk: cannot open disk /dev//dev/ad1: No such file or directory
> >
> > One possible fix:
> >
> > fivethree% diff -upr src/sbin/fdisk src2/sbin/fdisk
> > diff -upr src/sbin/fdisk/fdisk.c src2/sbin/fdisk/fdisk.c
> > --- src/sbin/fdisk/fdisk.c      Mon Jun 14 03:21:19 2004
> > +++ src2/sbin/fdisk/fdisk.c     Fri Oct 15 16:35:28 2004
> > @@ -299,14 +299,16 @@ main(int argc, char *argv[])
> >         if (argc == 0) {
> >                 disk = get_rootdisk();
> >         } else {
> > -               if (stat(argv[0], &sb) == 0) {
> > +               disk = argv[0];
> > +               if (stat(disk, &sb) == 0) {
> >                         /* OK, full pathname given */
> > -                       disk = argv[0];
> >                 } else if (errno == ENOENT) {
> >                         /* Try prepending "/dev" */
> > -                       asprintf(&disk, "%s%s", _PATH_DEV, argv[0]);
> > -                       if (disk == NULL)
> > -                               errx(1, "out of memory");
> > +                       if (strncmp(disk, _PATH_DEV, strlen(_PATH_DEV)))
> > { +                               asprintf(&disk, "%s%s", _PATH_DEV,
> > argv[0]); +                               if (disk == NULL)
> > +                                       errx(1, "out of memory");
> > +                       }
> >                 } else {
> >                         /* other stat error, let it fail below */
> >                         disk = argv[0];
>
> Simpler:
>
> %%%
> Index: fdisk.c
> ===================================================================
> RCS file: /home/ncvs/src/sbin/fdisk/fdisk.c,v
> retrieving revision 1.74
> diff -u -r1.74 fdisk.c
> --- fdisk.c	14 Jun 2004 07:21:19 -0000	1.74
> +++ fdisk.c	16 Oct 2004 06:43:16 -0000
> @@ -302,7 +302,7 @@
>  		if (stat(argv[0], &sb) == 0) {
>  			/* OK, full pathname given */
>  			disk = argv[0];
> -		} else if (errno == ENOENT) {
> +		} else if (errno == ENOENT && argv[0][0] != '/') {
>  			/* Try prepending "/dev" */
>  			asprintf(&disk, "%s%s", _PATH_DEV, argv[0]);
>  			if (disk == NULL)
> %%%
>
>
> Cheers,

Looks good to me, are you going to commit it?

-- 

John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200410191653.51979.jhb>