Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
cmd/snap-update-ns: add compare function for mount entries #2848
Conversation
zyga
requested review from
jdstrand
and removed request for
jdstrand
Feb 17, 2017
chipaca
approved these changes
Feb 21, 2017
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). |
chipaca
Feb 21, 2017
Member
maybe add a "(needed for using from qsort)" to the comment so people don't scratch their heads as I did
niemeyer
Feb 23, 2017
Contributor
Agreed, without further context the need for this is awkward indeed.
| +{ | ||
| + int result; | ||
| + if (a == NULL || b == NULL) { | ||
| + die("cannot compare NULL mount entry"); |
zyga
Feb 21, 2017
Contributor
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); |
zyga
Feb 21, 2017
Contributor
100% sure, we copy those with an explicit check that converts NULL to ""
niemeyer
approved these changes
Feb 23, 2017
Couple of details for follow ups. Merging now nevertheless.
| @@ -31,6 +31,16 @@ | ||
| #include "../libsnap-confine-private/cleanup-funcs.h" | ||
| /** | ||
| + * Compare two mount entries (through indirect pointers). |
chipaca
Feb 21, 2017
Member
maybe add a "(needed for using from qsort)" to the comment so people don't scratch their heads as I did
niemeyer
Feb 23, 2017
Contributor
Agreed, without further context the need for this is awkward indeed.
| + * | ||
| + * 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. |
zyga commentedFeb 14, 2017
•
Edited 1 time
-
zyga
Feb 15, 2017
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