forked from openshift/source-to-image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- enable use of cygwin to build and test s2i - simplify git and file downloaders - track posix file permissions on windows - remove unnecessary runtime.GOOS == "windows" checks - unit test fixes
- Loading branch information
Jim Minter
committed
Nov 29, 2016
1 parent
eb59eca
commit 251057d
Showing
46 changed files
with
1,125 additions
and
643 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
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
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,24 @@ | ||
Vagrant.configure("2") do |config| | ||
config.openshift.autoconfigure_aws = true | ||
|
||
config.vm.provider "aws" do |aws| | ||
aws.instance_type = "m4.large" | ||
aws.subnet_id = "subnet-cf57c596" | ||
end | ||
|
||
config.vm.define "rhel" do |rhel| | ||
rhel.vm.provider "aws" do |aws| | ||
aws.tags = {"Name" => "#{ENV['USER']}-rhel"} | ||
aws.ami = "rhel7:deps" | ||
end | ||
rhel.vm.provision "configure-docker-server-linux" | ||
end | ||
|
||
config.vm.define "windows" do |windows| | ||
windows.vm.provider "aws" do |aws| | ||
aws.tags = {"Name" => "#{ENV['USER']}-windows"} | ||
aws.ami = "windows2012r2:deps" | ||
end | ||
windows.vm.provision "configure-docker-client-windows" | ||
end | ||
end |
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,8 @@ | ||
CFLAGS=-Wall -Os -s | ||
|
||
sigintwrap: | ||
|
||
clean: | ||
@rm -f sigintwrap | ||
|
||
.PHONY: clean |
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,27 @@ | ||
sigintwrap is an executable wrapper used in the automated testing of s2i on | ||
Windows. In hack/test-stirunimage.sh it is verified that sending an interrupt | ||
to a running s2i process (i.e. sending a SIGINT on Linux, or specifically | ||
pressing CTRL C or CTRL BREAK on Windows) causes the process to clean up a | ||
running Docker container before exiting. | ||
|
||
Cygwin is used for Windows build and testing of s2i, but note that the s2i | ||
binary itself has no dependency on Cygwin (in general, Go and the executables it | ||
compiles have no knowledge or dependency on Cygwin). | ||
|
||
For the above test to be valid and succeed on Windows, it is necessary to bridge | ||
between receiving the SIGINT sent by the test framework (note: on Windows, | ||
POSIX-style signal handling is implemented only in Cygwin-compiled/-aware | ||
executables, in userspace) and Golang acting on a native CTRL C/CTRL BREAK | ||
event. | ||
|
||
sigintwrap is a Cygwin-compiled executable which spawns a named executable in a | ||
new Windows process group and waits until it exits. If before that time | ||
sigintwrap receives a SIGINT signal it sends a synthetic CTRL BREAK event to the | ||
process it started. | ||
|
||
This approach is used (rather than, say, simply using the | ||
GenerateConsoleCtrlEvent API directly to create a synthetic event) because there | ||
is no obvious and straightforward way to spawn a new process into a new Windows | ||
process group in Cygwin without resorting to C, nor is there an obvious free | ||
lightweight pre-existing utility which can be used to send a synthetic | ||
CTRL BREAK event to a given process. |
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,116 @@ | ||
// sigintwrap: wrapper for non-Cygwin executables, capturing Cygwin SIGINTs and | ||
// forwarding them as a CTRL BREAK events to the non-Cygwin executable. After | ||
// "Solution For Handling Signals In Non-Cygwin Apps With | ||
// SetConsoleCtrlHandler", Anthony DeRosa, | ||
// http://marc.info/?l=cygwin&m=111047278517873 | ||
|
||
|
||
#include <sys/cygwin.h> | ||
#include <pthread.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <windows.h> | ||
|
||
|
||
static PROCESS_INFORMATION pi; | ||
|
||
|
||
static void * | ||
wait_for_process(void *ptr) { | ||
WaitForSingleObject(pi.hProcess, INFINITE); | ||
return NULL; | ||
} | ||
|
||
|
||
static void | ||
sigint(int signal) { | ||
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId); | ||
} | ||
|
||
|
||
static int | ||
needs_path_conversion(const char *s) { | ||
// See winsup/cygwin/environ.cc. | ||
return !(strncmp(s, "HOME=", 5) && | ||
strncmp(s, "LD_LIBRARY_PATH=", 16) && | ||
strncmp(s, "PATH=", 5) && | ||
strncmp(s, "TEMP=", 5) && | ||
strncmp(s, "TMP=", 4) && | ||
strncmp(s, "TMPDIR=", 7)); | ||
} | ||
|
||
|
||
static char * | ||
prepare_env() { | ||
char **p; | ||
|
||
int len = 1; | ||
for(p = environ; *p; p ) | ||
if(needs_path_conversion(*p)) { | ||
char *eq = strchr(*p, '='); | ||
len = eq - *p 1; | ||
len = cygwin_conv_path_list(CCP_POSIX_TO_WIN_A, eq 1, NULL, 0); | ||
} else | ||
len = strlen(*p) 1; | ||
|
||
char *env = (char *)malloc(len); | ||
char *e = env; | ||
for(p = environ; *p; p ) | ||
if(needs_path_conversion(*p)) { | ||
char *eq = strchr(*p, '='); | ||
e = stpncpy(e, *p, eq - *p 1); | ||
cygwin_conv_path_list(CCP_POSIX_TO_WIN_A, eq 1, e, env len - e - 1); | ||
while(*e ); | ||
} else | ||
e = stpcpy(e, *p) 1; | ||
*e = '\0'; | ||
|
||
return env; | ||
} | ||
|
||
|
||
int | ||
main(int argc, char **argv) { | ||
if(argc != 2) { | ||
fprintf(stderr, "usage: %s 'c:\\path\\to\\command.exe [arg...]'\n", | ||
argv[0]); | ||
return 1; | ||
} | ||
|
||
STARTUPINFO si; | ||
ZeroMemory(&si, sizeof(si)); | ||
si.cb = sizeof(si); | ||
|
||
char *env = prepare_env(); | ||
|
||
if(!CreateProcess(NULL, argv[1], NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP, | ||
env, NULL, &si, &pi)) { | ||
LPTSTR msg; | ||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | | ||
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, | ||
(LPTSTR)&msg, 0, NULL); | ||
fputs(msg, stderr); | ||
LocalFree(msg); | ||
free(env); | ||
return 1; | ||
} | ||
|
||
free(env); | ||
|
||
signal(SIGINT, sigint); | ||
|
||
// We call WaitForSingleObject on another thread because it cannot be | ||
// interrupted by cygwin signals. pthread_join can be. | ||
pthread_t thread; | ||
pthread_create(&thread, NULL, wait_for_process, NULL); | ||
pthread_join(thread, NULL); | ||
|
||
DWORD exitcode; | ||
GetExitCodeProcess(pi.hProcess, &exitcode); | ||
|
||
CloseHandle(pi.hProcess); | ||
CloseHandle(pi.hThread); | ||
|
||
return exitcode; | ||
} |
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
Oops, something went wrong.