Skip to content

Commit

Permalink
NOMERGE make namespace order verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
yabberyabber committed Nov 27, 2024
1 parent e113f22 commit e647354
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <sched.h>
#include <stdlib.h>
Expand Down Expand Up @@ -104,13 +105,21 @@ static int is_setns(const struct nsid *ns)
are entered via unshare (or not changed at all). */
static int cmp_nsids(const void *lhs, const void *rhs)
{
const struct nsid *lns = lhs;
const struct nsid *rns = rhs;
printf("\tcomparing lhs=%d (is_setns=%d) with rhs=%d (is_setns=%d): ",
lns->ns, is_setns(lhs),
rns->ns, is_setns(rhs));
int diff = is_setns(rhs) - is_setns(lhs);
if (diff != 0) {
printf("%d via setns diff\n", diff);
return diff;
}
/* Both namespaces are the same kind -- keep ordering intact by comparing
pointer values. */
return (int) ((intptr_t) lhs - (intptr_t) rhs);
diff = (int) ((intptr_t) lhs - (intptr_t) rhs);
printf("%d via pointer comparison\n", diff);
return diff;
}

static void ns_enter_one(struct nsid *ns)
Expand Down Expand Up @@ -157,10 +166,19 @@ void ns_enter_prefork(struct nsid *namespaces, size_t *len)
if (capable(BST_CAP_SYS_ADMIN)) {
qsort(namespaces, *len, sizeof (namespaces[0]),
cmp_nsids);
}
printf("performed sort: ");
} else {
printf("skipped sort: ");
}
struct nsid *ns = &namespaces[0];
printf("POST SORT: ");
for (; ns < namespaces + *len; ++ns) {
printf("%d (%d), ", ns->ns, ns->action);
}
printf("\n");

struct nsid *first_postfork = NULL;
struct nsid *ns = &namespaces[0];
ns = &namespaces[0];
for (; ns < namespaces + *len; ++ns) {
if (ns->action != NSACTION_SHARE_WITH_PARENT && is_postfork_ns(ns)) {
first_postfork = ns;
Expand Down

0 comments on commit e647354

Please sign in to comment.