Skip to content

Commit

Permalink
Merge pull request #109 from chriskuehl/fixes-for-freebsd
Browse files Browse the repository at this point in the history
Fixes for FreeBSD kernel
  • Loading branch information
chriskuehl authored Aug 2, 2016
2 parents 3c141fe + f854583 commit 301eedd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
11 changes: 11 additions & 0 deletions dumb-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

// Signals we care about are numbered from 1 to 31, inclusive.
// (32 and above are real-time signals.)
// TODO: this is likely not portable outside of Linux, or on strange architectures
#define MAXSIG 31

// Indices are one-indexed (signal 1 is at index 1). Index zero is unused.
Expand Down Expand Up @@ -233,12 +234,22 @@ char **parse_command(int argc, char *argv[]) {
return &argv[optind];
}

// A dummy signal handler used for signals we care about.
// On the FreeBSD kernel, ignored signals cannot be waited on by `sigwait` (but
// they can be on Linux). We must provide a dummy handler.
// https://lists.freebsd.org/pipermail/freebsd-ports/2009-October/057340.html
void dummy(int signum) {}

int main(int argc, char *argv[]) {
char **cmd = parse_command(argc, argv);
sigset_t all_signals;
sigfillset(&all_signals);
sigprocmask(SIG_BLOCK, &all_signals, NULL);

int i = 0;
for (i = 1; i <= MAXSIG; i++)
signal(i, dummy);

child_pid = fork();
if (child_pid < 0) {
PRINTERR("Unable to fork. Exiting.\n");
Expand Down
18 changes: 11 additions & 7 deletions testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ def print_signals(args=()):

def child_pids(pid):
"""Return a list of direct child PIDs for the given PID."""
pid = str(pid)
tasks = LocalPath('/proc').join(pid, 'task').listdir()
return set(
int(child_pid)
for task in tasks
for child_pid in task.join('children').read().split()
)
children = set()
for p in LocalPath('/proc').listdir():
stat = p.join('stat')
if stat.isfile():
stat = stat.open().read()
m = re.match('^\d+ \([^\)]+\) [a-zA-Z] (\d+) ', stat)
assert m, stat
ppid = int(m.group(1))
if ppid == pid:
children.add(int(p.basename))
return children


def pid_tree(pid):
Expand Down
2 changes: 1 addition & 1 deletion tests/tty_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def readall(fd):
return result
else:
raise
if chunk == '':
if chunk == b'':
return result
else:
result += chunk
Expand Down

0 comments on commit 301eedd

Please sign in to comment.