Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions nbd-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ static void netlink_disconnect(char *nbddev) {

int index = -1;
if (nbddev) {
if (sscanf(nbddev, "nbd%d", &index) != 1)
err("Invalid nbd device target\n");
if (sscanf(nbddev, "/dev/nbd%d", &index) != 1) {
if (sscanf(nbddev, "nbd%d", &index) != 1) {
err("Invalid nbd device target\n");
Copy link
Copy Markdown
Contributor

@RokerHRO RokerHRO Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why nested if instead of combine the conditions with && ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we have another case with nested if and I wanted to make things consistent. Happy to change this to concatenation... Actually that was my first idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an alternative approach in #190 ...

}
}
}
if (index < 0)
err("Invalid nbd device target\n");
Expand Down Expand Up @@ -1539,8 +1542,11 @@ int main(int argc, char *argv[]) {
if (netlink) {
int index = -1;
if (cur_client->dev) {
if (sscanf(cur_client->dev, "nbd%d", &index) != 1)
err("Invalid nbd device target\n");
if (sscanf(cur_client->dev, "/dev/nbd%d", &index) != 1) {
if (sscanf(cur_client->dev, "nbd%d", &index) != 1) {
err("Invalid nbd device target\n");
}
}
}
netlink_configure(index, sockfds, flags, identifier);

Expand Down