cmd/snap-update-ns: add compare function for mount entries #2848

Merged
merged 1 commit into from Feb 23, 2017

Conversation

Projects
None yet
3 participants
Contributor

zyga commented Feb 14, 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

cmd/snap-update-ns: add compare function for mount entries
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>

@zyga zyga requested review from jdstrand and removed request for jdstrand Feb 17, 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

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

@zyga

zyga Feb 22, 2017

Contributor

This one is static and it will show up in the next branch.

@niemeyer

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");
@chipaca

chipaca Feb 21, 2017

Member

not even if they're both NULL :-p?

@zyga

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);
@chipaca

chipaca Feb 21, 2017

Member

how sure are we that all these fields are non-null?

@zyga

zyga Feb 21, 2017

Contributor

100% sure, we copy those with an explicit check that converts NULL to ""

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

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

@zyga

zyga Feb 22, 2017

Contributor

This one is static and it will show up in the next branch.

@niemeyer

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.
@niemeyer

niemeyer Feb 23, 2017

Contributor

End of the sentence has two "second entry".

@niemeyer niemeyer merged commit bc7549d into snapcore:master Feb 23, 2017

6 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-i386 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details

@zyga zyga deleted the zyga:mount-entry-compare branch Aug 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment