Mike Christie wrote:
> Hans de Goede wrote:
>> Yes it does the same thing, is this from the open-iscsi VCS ? and where do I 
>> find that ?
>>
> 
> Ok, I will merge up your code instead with the fixes in the thread. Thanks!
> 

Here is the rediffed patch. I used strncat here:
+       strncat(dev_dir, "/net", FILENAMESZ - strlen(dev_dir))

and am going to replace it with strlcat when I move some code.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/open-iscsi
-~----------~----~----~----~------~----~------~--~---

diff --git a/utils/fwparam_ibft/fwparam_ibft_sysfs.c 
b/utils/fwparam_ibft/fwparam_ibft_sysfs.c
index a79c1c6..3ce1b74 100644
--- a/utils/fwparam_ibft/fwparam_ibft_sysfs.c
+++ b/utils/fwparam_ibft/fwparam_ibft_sysfs.c
@@ -103,33 +103,6 @@ static int get_iface_from_device(char *id, struct 
boot_context *context)
                                rc = EINVAL;
                        rc = 0;
                        break;
-               } else if (!strncmp(dent->d_name, "net", 3)) {
-                       DIR *net_dirfd;
-                       struct dirent *net_dent;
-
-                       strncat(dev_dir, "/", FILENAMESZ);
-                       strncat(dev_dir, dent->d_name, FILENAMESZ);
-
-                       net_dirfd = opendir(dev_dir);
-                       if (!net_dirfd) {
-                               printf("Could not open net path %s.\n",
-                                      dev_dir);
-                               rc = errno;
-                               break;
-                       }
-
-                       while ((net_dent = readdir(net_dirfd))) {
-                               if (!strcmp(net_dent->d_name, ".") ||
-                                   !strcmp(net_dent->d_name, ".."))
-                                       continue;
-
-                               strncpy(context->iface, net_dent->d_name,
-                                       sizeof(context->iface));
-                               break;
-                       }
-                       closedir(net_dirfd);
-                       rc = 0;
-                       break;
                } else {
                        printf("Could not read ethernet to net link\n.");
                        rc = EOPNOTSUPP;
@@ -137,6 +110,40 @@ static int get_iface_from_device(char *id, struct 
boot_context *context)
                }
        }
 
+       closedir(dirfd);
+
+       if (rc != ENODEV)
+               return rc;
+
+       /* If not found try again with newer kernel networkdev sysfs layout */
+       strncat(dev_dir, "/net", FILENAMESZ - strlen(dev_dir));
+
+       if (!file_exist(dev_dir))
+               return rc;
+
+       dirfd = opendir(dev_dir);
+       if (!dirfd)
+               return errno;
+
+       while ((dent = readdir(dirfd))) {
+               if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
+                       continue;
+
+               /* Take the first "regular" directory entry */
+               if (strlen(dent->d_name) > (sizeof(context->iface) - 1)) {
+                       rc = EINVAL;
+                       printf("Net device %s too big for iface buffer.\n",
+                              dent->d_name);
+                       break;
+               }
+
+               strcpy(context->iface, dent->d_name);
+               rc = 0;
+               break;
+       }
+
+       closedir(dirfd);
+
        return rc;
 }
 

Reply via email to