New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/snap-update-ns: add compare function for mount entries #2848
Conversation
This patch adds a simple function for comparing mount entries. This will be followed up with a simple routine that sorts two lists of mount entries qucikly. Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just one question about fields being NULL, which is only a blocker if it's got the wrong answer :-)
@@ -31,6 +31,16 @@ | |||
#include "../libsnap-confine-private/cleanup-funcs.h" | |||
|
|||
/** | |||
* Compare two mount entries (through indirect pointers). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a "(needed for using from qsort)" to the comment so people don't scratch their heads as I did
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is static and it will show up in the next branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, without further context the need for this is awkward indeed.
{ | ||
int result; | ||
if (a == NULL || b == NULL) { | ||
die("cannot compare NULL mount entry"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not even if they're both NULL :-p?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we never have NULL entries that mean anything. We only have an empty list that is expressed by an NULL entry. The sorting routine will not compare NULL pointers.
if (a == NULL || b == NULL) { | ||
die("cannot compare NULL mount entry"); | ||
} | ||
result = strcmp(a->entry.mnt_fsname, b->entry.mnt_fsname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how sure are we that all these fields are non-null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% sure, we copy those with an explicit check that converts NULL to ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of details for follow ups. Merging now nevertheless.
* | ||
* Returns 0 if both entries are equal, a number less than zero if the first | ||
* entry sorts before the second entry or a number greater than zero if the | ||
* second entry sorts before the second entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End of the sentence has two "second entry".
@@ -31,6 +31,16 @@ | |||
#include "../libsnap-confine-private/cleanup-funcs.h" | |||
|
|||
/** | |||
* Compare two mount entries (through indirect pointers). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, without further context the need for this is awkward indeed.
This patch adds a simple function for comparing mount entries. This will
be followed up with a simple routine that sorts two lists of mount
entries quickly.
Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com