>>> Jim Ramsay <jim_ram...@dell.com> schrieb am 03.10.2012 um 15:57 in Nachricht
<1349272663-18322-1-git-send-email-jim_ram...@dell.com>:
> If there is a file in the CWD named '1' and you were trying to run
> 'iscsiadm -m session -r 1 ...', the command would fail with "1 is not a
> directory".
> 
> Root cause: The code that parses the -r option's argument tries lstat(2)
> first, falling back to atoi(3) only if lstat fails.
> 
> This change inverts the order of checks, first with strtol(3) to see if
> the argument given is a positive integer, then falling back to lstat(2)
> only if it is not.
> 
> Signed-off-by: Jim Ramsay <jim_ram...@dell.com>
> ---
>  usr/iscsi_sysfs.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
> index 123dde3..4015b35 100644
> --- a/usr/iscsi_sysfs.c
> +++ b/usr/iscsi_sysfs.c
[...]
> @@ -748,15 +748,16 @@ int iscsi_sysfs_get_sid_from_path(char *session)
>       struct sysfs_device *dev_parent, *dev;
>       struct stat statb;
>       char devpath[PATH_SIZE];
> +     char *end;
> +     int sid;
> +
> +     sid = strtol(session, &end, 10);
> +     if (sid > 0 && *session != '\0' && *end == '\0')

Hi!

I think the "*session != '\0'" is redundant as compared to "sid > 0".

Regards,
Ulrich

> +             return sid;
>  
>       if (lstat(session, &statb)) {
> -             log_debug(1, "Could not stat %s failed with %d",
> -                       session, errno);
> -             if (index(session, '/')) {
> -                     log_error("%s is an invalid session path\n", session);
> -                     exit(1);
> -             }
> -             return atoi(session);
> +             log_error("%s is an invalid session ID or path\n", session);
> +             exit(1);
>       }
>  
>       if (!S_ISDIR(statb.st_mode) && !S_ISLNK(statb.st_mode)) {



 

-- 
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?hl=en.

Reply via email to