On Tue, May 12, 2015 at 2:00 AM, Manuel Giraud <[email protected]> wrote:
> Philip Guenther <[email protected]> writes:
>
>> Can we suppress the device form if there's a matching DUID entry?
>
> Okay. The DUID/device dance is not that easy (at least for me). So here
> is a new patch that should work.
>
> For your issue, I choose to convert dumpdates entries to DUID (when
> possible) at read time so dump now has the following features/drawbacks:
>
>         - All dumpdates entries (of present devices) will be converted
>           to DUID at the next dump (even those that are not being dumped).
>         - Even a dump -w/W tries to opendev the device (in order to find
>           its UID).

Semantics were good, thanks!  There were a few resource leaks I took
care of before committing:

> +char *
> +getduid(char *path)
> +{
> +       int fd;
> +       struct disklabel lab;
> +       u_int64_t zero_uid = 0;
> +       char *duid;
> +
> +       if ((fd = opendev(path, O_RDONLY | O_NOFOLLOW, 0, NULL)) >= 0) {
> +               if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
> +                       close(fd);
> +                       warn("ioctl(DIOCGDINFO)");
> +                       return (NULL);
> +               }
> +
> +               if (memcmp(lab.d_uid, &zero_uid, sizeof(lab.d_uid)) != 0) {
> +                       if (asprintf(&duid,
> +                                    
> "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
> +                                    lab.d_uid[0], lab.d_uid[1], lab.d_uid[2],
> +                                    lab.d_uid[3], lab.d_uid[4], lab.d_uid[5],
> +                                    lab.d_uid[6], lab.d_uid[7],
> +                                    path[strlen(path)-1]) == -1) {
> +                               close(fd);
> +                               warn("Cannot malloc duid");
> +                               return (NULL);
> +                       }
> +                       return (duid);
> +               }
> +       }
> +
> +       return (NULL);
>  }

This failed to close fd in the success path; I moved the second
close() up to before the memcmp().


> @@ -347,6 +347,13 @@ fstabsearch(char *key)
>                 rn = rawname(fs->fs_spec);
>                 if (rn != NULL && strcmp(rn, key) == 0)
>                         return (fs);
> +               if (rn != NULL) {
> +                       uid = getduid(rn);
> +               } else {
> +                       uid = getduid(fs->fs_spec);
> +               }
> +               if (uid != NULL && strcmp(uid, key) == 0)
> +                       return (fs);

uid is malloced by getduid(), so it needed to be freed here.

Nothing big, thanks for doing the hard part!


Philip Guenther

Reply via email to