Commits

winebarrel  committed d335bf6

  • Participants
  • Parent commits 1e5d5e4

Comments (0)

Files changed (3)

File ext/extconf.rb

   Dir.chdir('libtar')
 
   begin
-    system('sh configure') and system('make')
+    return false unless system('sh configure')
+
+    if have_func('sigaction')
+      open('config.h', 'a') do |fout|
+        fout << "\n#define HAVE_SIGACTION 1\n"
+      end
+    end
+
+    system('make')
   ensure
     Dir.chdir('..')
   end

File ext/libtar/lib/wrapper.c

 # include <string.h>
 #endif
 
+#ifdef HAVE_SIGACTION
+#include <signal.h>
+#endif
+
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
+static int __tarruby_interrupted__ = 0;
+#endif
+
 #ifdef _WIN32
-static int __tarruby_interrupted__ = 0;
-
 static BOOL WINAPI interrupted_handler(DWORD CtrlType) {
 	if (CTRL_C_EVENT == CtrlType) {
 		__tarruby_interrupted__ = 1;
 }
 #endif
 
+#ifdef HAVE_SIGACTION
+static void interrupted_handler(int no) {
+	__tarruby_interrupted__ = 1;
+}
+
+void tarruby_interrupted() {
+	char buff[256];
+	int ret;
+	struct sigaction sa;
+
+	memset(&sa, 0, sizeof(struct sigaction));
+	sa.sa_handler = interrupted_handler;
+	sa.sa_flags |= SA_RESTART;
+	sigaction(SIGINT, &sa, NULL);
+}
+#endif
+
 int
 tar_extract_glob(TAR *t, char *globname, char *prefix)
 {
 	char buf[MAXPATHLEN];
 	int i;
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
 	__tarruby_interrupted__ = 0;
 #endif
 
 	while ((i = th_read(t)) == 0)
 	{
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
 		if (__tarruby_interrupted__) {
 			errno = EINTR;
 			__tarruby_interrupted__ = 0;
 	char buf[MAXPATHLEN];
 	int i;
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
 	__tarruby_interrupted__ = 0;
 #endif
 
 #ifdef DEBUG
 		puts("    tar_extract_all(): calling th_get_pathname()");
 #endif
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
 		if (__tarruby_interrupted__) {
 			errno = EINTR;
 			__tarruby_interrupted__ = 0;
 	struct dirent *dent;
 	DIR *dp;
 	struct stat s;
-#ifdef _WIN32
-    int errorp = 0;
+#if defined(_WIN32)
+	int errorp = 0;
+#endif
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
 	__tarruby_interrupted__ = 0;
 #endif
 
 	}
 	while ((dent = readdir(dp)) != NULL)
 	{
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
 		if (__tarruby_interrupted__) {
 			errno = EINTR;
 			__tarruby_interrupted__ = 0;

File ext/tarruby.c

   rb_define_method(Tar, "fifo?", tarruby_is_fifo, 0);
   rb_define_method(Tar, "longname?", tarruby_is_longname, 0);
   rb_define_method(Tar, "longlink?", tarruby_is_longlink, 0);
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_SIGACTION)
   tarruby_interrupted();
 #endif
 }