Skip to content
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

FreeBSD Support - Fix syscall(SYS__pthread_chdir) failed to set current directory #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/nuprocess/internal/LibC.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static native int posix_spawnp(IntByReference restrict_pid, String restri
// We can't use JNA direct mapping for syscall(), since it takes varargs.
public interface SyscallLibrary extends Library
{
public static final int SYS___pthread_chdir = 348;
public static final int SYS___pthread_chdir = System.getProperty("os.name").toLowerCase().contains("freebsd") ? 12 : 348;

int syscall(int syscall_number, Object... args);
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/zaxxer/nuprocess/osx/LibKevent.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static class Kevent extends Structure
public int fflags;
public NativeLong data;
public Pointer udata;
public long[] ext = new long[4];

public Kevent() {
super();
Expand All @@ -72,7 +73,12 @@ public Kevent(Pointer p) {
@Override
protected List getFieldOrder()
{
return Arrays.asList("ident", "filter", "flags", "fflags", "data", "udata");
String osname = System.getProperty("os.name").toLowerCase();
if(osname.contains("freebsd")){
return Arrays.asList("ident", "filter", "flags", "fflags", "data", "udata", "ext");
} else {
return Arrays.asList("ident", "filter", "flags", "fflags", "data", "udata");
}
}

Kevent EV_SET(long ident, int filter, int flags, int fflags, long data, Pointer udata)
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/com/zaxxer/nuprocess/osx/ProcessKqueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package com.zaxxer.nuprocess.osx;

import static com.zaxxer.nuprocess.internal.LibC.WEXITSTATUS;
import static com.zaxxer.nuprocess.internal.LibC.WIFEXITED;
import static com.zaxxer.nuprocess.internal.LibC.WIFSIGNALED;
import static com.zaxxer.nuprocess.internal.LibC.WTERMSIG;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.zaxxer.nuprocess.internal.BaseEventProcessor;
import com.zaxxer.nuprocess.internal.LibC;
import com.zaxxer.nuprocess.osx.LibKevent.Kevent;
import com.zaxxer.nuprocess.osx.LibKevent.TimeSpec;

import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -28,13 +31,7 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.zaxxer.nuprocess.internal.BaseEventProcessor;
import com.zaxxer.nuprocess.internal.LibC;
import com.zaxxer.nuprocess.osx.LibKevent.Kevent;
import com.zaxxer.nuprocess.osx.LibKevent.TimeSpec;
import static com.zaxxer.nuprocess.internal.LibC.*;

/**
* @author Brett Wooldridge
Expand Down Expand Up @@ -115,14 +112,14 @@ public void registerProcess(OsxProcess process)
// We don't use the processEvents array here, since this method is not
// called on the event processor thread.
Kevent[] events = (Kevent[]) new Kevent().toArray(4);
// Listen for process exit (one-shot event)
events[0].EV_SET((long) pid, Kevent.EVFILT_PROC, Kevent.EV_ADD | Kevent.EV_RECEIPT | Kevent.EV_ONESHOT,
Kevent.NOTE_EXIT | Kevent.NOTE_EXITSTATUS | Kevent.NOTE_REAP, 0L, pidPointer);
// Listen for stdout and stderr data availability (events deleted automatically when file descriptors closed)
events[1].EV_SET(stdoutFd, Kevent.EVFILT_READ, Kevent.EV_ADD | Kevent.EV_RECEIPT, 0, 0L, pidPointer);
events[2].EV_SET(stderrFd, Kevent.EVFILT_READ, Kevent.EV_ADD | Kevent.EV_RECEIPT, 0, 0L, pidPointer);
events[0].EV_SET(stdoutFd, Kevent.EVFILT_READ, Kevent.EV_ADD | Kevent.EV_RECEIPT, 0, 0L, pidPointer);
events[1].EV_SET(stderrFd, Kevent.EVFILT_READ, Kevent.EV_ADD | Kevent.EV_RECEIPT, 0, 0L, pidPointer);
// Listen for stdin data availability (initially disabled until user wants read, deleted automatically when file descriptor closed)
events[3].EV_SET(stdinFd, Kevent.EVFILT_WRITE, Kevent.EV_ADD | Kevent.EV_DISABLE | Kevent.EV_RECEIPT, 0, 0L, pidPointer);
events[2].EV_SET(stdinFd, Kevent.EVFILT_WRITE, Kevent.EV_ADD | Kevent.EV_DISABLE | Kevent.EV_RECEIPT, 0, 0L, pidPointer);
// Listen for process exit (one-shot event)
events[3].EV_SET((long) pid, Kevent.EVFILT_PROC, Kevent.EV_ADD | Kevent.EV_RECEIPT | Kevent.EV_ONESHOT,
Kevent.NOTE_EXIT | Kevent.NOTE_EXITSTATUS | Kevent.NOTE_REAP, 0L, pidPointer);

registerEvents(events, 4);
} finally {
Expand Down