-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openbsd support based on recent freebsd one
- Loading branch information
jirib
committed
Feb 17, 2016
1 parent
1384223
commit f844d0e
Showing
5 changed files
with
269 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include Makefile_linux | ||
|
||
CC=cc | ||
LINUX=openbsd | ||
ARCH_FLAG_X86_64= | ||
ARCH_FLAG_X86=-m32 | ||
CFLAGS +=-shared -fPIC -fpic -D_REENTRANT -D_GNU_SOURCE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
/* | ||
* JPty - A small PTY interface for Java. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.pty4j.unix.openbsd; | ||
|
||
|
||
import com.pty4j.WinSize; | ||
import com.pty4j.unix.PtyHelpers; | ||
import com.sun.jna.Library; | ||
import com.sun.jna.Native; | ||
import com.sun.jna.NativeLong; | ||
import com.sun.jna.StringArray; | ||
import com.sun.jna.ptr.IntByReference; | ||
import jtermios.JTermios; | ||
|
||
|
||
/** | ||
* Provides a {@link PtyHelpers.OSFacade} implementation for OpenBSD. | ||
*/ | ||
public class OSFacadeImpl implements PtyHelpers.OSFacade { | ||
// INNER TYPES | ||
|
||
public interface OpenBSD_C_lib extends Library { | ||
int posix_openpt(int oflag); | ||
|
||
int execv(String command, StringArray argv); | ||
|
||
int execve(String command, StringArray argv, StringArray env); | ||
|
||
int ioctl(int fd, NativeLong cmd, PtyHelpers.winsize data); | ||
|
||
int kill(int pid, int signal); | ||
|
||
int waitpid(int pid, int[] stat, int options); | ||
|
||
int sigprocmask(int how, IntByReference set, IntByReference oldset); | ||
|
||
String strerror(int errno); | ||
|
||
int grantpt(int fdm); | ||
|
||
int unlockpt(int fdm); | ||
|
||
int close(int fd); | ||
|
||
String ptsname(int fd); | ||
|
||
int open(String pts_name, int o_rdwr); | ||
|
||
int killpg(int pid, int sig); | ||
|
||
int fork(); | ||
|
||
int setsid(); | ||
|
||
int getpid(); | ||
|
||
int setpgid(int pid, int pgid); | ||
|
||
void dup2(int fd, int fileno); | ||
|
||
int getppid(); | ||
|
||
void unsetenv(String s); | ||
|
||
int login_tty(int fd); | ||
|
||
void chdir(String dirpath); | ||
} | ||
|
||
public interface OpenBSD_Util_lib extends Library { | ||
int login_tty(int fd); | ||
} | ||
|
||
// CONSTANTS | ||
|
||
private static final long TIOCGWINSZ = 0x40087468L; | ||
private static final long TIOCSWINSZ = 0x80087467L; | ||
|
||
// VARIABLES | ||
|
||
private static OpenBSD_C_lib m_Clib = (OpenBSD_C_lib) Native.loadLibrary("c", OpenBSD_C_lib.class); | ||
private static OpenBSD_Util_lib m_Utillib = (OpenBSD_Util_lib)Native.loadLibrary("util", OpenBSD_Util_lib.class); | ||
|
||
// CONSTUCTORS | ||
|
||
/** | ||
* Creates a new {@link OSFacadeImpl} instance. | ||
*/ | ||
public OSFacadeImpl() { | ||
PtyHelpers.ONLCR = 0x02; | ||
|
||
PtyHelpers.VERASE = 3; | ||
PtyHelpers.VWERASE = 4; | ||
PtyHelpers.VKILL = 5; | ||
PtyHelpers.VREPRINT = 6; | ||
PtyHelpers.VINTR = 8; | ||
PtyHelpers.VQUIT = 9; | ||
PtyHelpers.VSUSP = 10; | ||
|
||
PtyHelpers.ECHOKE = 0x01; | ||
PtyHelpers.ECHOCTL = 0x40; | ||
} | ||
|
||
// METHODS | ||
|
||
@Override | ||
public int execve(String command, String[] argv, String[] env) { | ||
StringArray argvp = (argv == null) ? new StringArray(new String[]{command}) : new StringArray(argv); | ||
StringArray envp = (env == null) ? null : new StringArray(env); | ||
return m_Clib.execve(command, argvp, envp); | ||
} | ||
|
||
@Override | ||
public int getWinSize(int fd, WinSize winSize) { | ||
int r; | ||
|
||
PtyHelpers.winsize ws = new PtyHelpers.winsize(); | ||
if ((r = m_Clib.ioctl(fd, new NativeLong(TIOCGWINSZ), ws)) < 0) { | ||
return r; | ||
} | ||
ws.update(winSize); | ||
|
||
return r; | ||
} | ||
|
||
@Override | ||
public int kill(int pid, int signal) { | ||
return m_Clib.kill(pid, signal); | ||
} | ||
|
||
@Override | ||
public int setWinSize(int fd, WinSize winSize) { | ||
PtyHelpers.winsize ws = new PtyHelpers.winsize(winSize); | ||
return m_Clib.ioctl(fd, new NativeLong(TIOCSWINSZ), ws); | ||
} | ||
|
||
@Override | ||
public int waitpid(int pid, int[] stat, int options) { | ||
return m_Clib.waitpid(pid, stat, options); | ||
} | ||
|
||
@Override | ||
public int sigprocmask(int how, IntByReference set, IntByReference oldset) { | ||
return m_Clib.sigprocmask(how, set, oldset); | ||
} | ||
|
||
@Override | ||
public String strerror(int errno) { | ||
return m_Clib.strerror(errno); | ||
} | ||
|
||
@Override | ||
public int getpt() { | ||
return m_Clib.posix_openpt(JTermios.O_RDWR | JTermios.O_NOCTTY); | ||
} | ||
|
||
@Override | ||
public int grantpt(int fd) { | ||
return m_Clib.grantpt(fd); | ||
} | ||
|
||
@Override | ||
public int unlockpt(int fd) { | ||
return m_Clib.unlockpt(fd); | ||
} | ||
|
||
@Override | ||
public int close(int fd) { | ||
return m_Clib.close(fd); | ||
} | ||
|
||
@Override | ||
public String ptsname(int fd) { | ||
return m_Clib.ptsname(fd); | ||
} | ||
|
||
@Override | ||
public int killpg(int pid, int sig) { | ||
return m_Clib.killpg(pid, sig); | ||
} | ||
|
||
@Override | ||
public int fork() { | ||
return m_Clib.fork(); | ||
} | ||
|
||
@Override | ||
public int pipe(int[] pipe2) { | ||
return JTermios.pipe(pipe2); | ||
} | ||
|
||
@Override | ||
public int setsid() { | ||
return m_Clib.setsid(); | ||
} | ||
|
||
@Override | ||
public void execv(String path, String[] argv) { | ||
StringArray argvp = (argv == null) ? new StringArray(new String[]{path}) : new StringArray(argv); | ||
m_Clib.execv(path, argvp); | ||
} | ||
|
||
@Override | ||
public int getpid() { | ||
return m_Clib.getpid(); | ||
} | ||
|
||
@Override | ||
public int setpgid(int pid, int pgid) { | ||
return m_Clib.setpgid(pid, pgid); | ||
} | ||
|
||
@Override | ||
public void dup2(int fds, int fileno) { | ||
m_Clib.dup2(fds, fileno); | ||
} | ||
|
||
@Override | ||
public int getppid() { | ||
return m_Clib.getppid(); | ||
} | ||
|
||
@Override | ||
public void unsetenv(String s) { | ||
m_Clib.unsetenv(s); | ||
} | ||
|
||
@Override | ||
public int login_tty(int fd) { | ||
return m_Utillib.login_tty(fd); | ||
} | ||
|
||
@Override | ||
public void chdir(String dirpath) { | ||
m_Clib.chdir(dirpath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters