Amanda-Users

patch: CygWin support in Amanda 2.4.3

2003-04-15 16:04:51
Subject: patch: CygWin support in Amanda 2.4.3
From: Brian White <bcwhite AT precidia DOT com>
To: Amanda Users <amanda-users AT amanda DOT org>
Date: Tue, 15 Apr 2003 14:10:47 -0400
After much experementation, I now have a complete patch for Amanda 2.4.3
to allow it to compile for the CygWin system.  Would it be possible to
incorporate this in to the upstream source?  The full diff is attached,
but here are the pieces and a description of what they do:


===============================================================================
This first patch is really the most important.  CygWin has a known problem
dealing with sockets when that socket is being written to by a child process
and the parent closes it's handle on the socket before the child exits.  This
patch moves the code that closes these paths from "start_backup" functions
to the main backup function.

I think this is a good patch in general since it's somewhat unusual for
a subroutine to close a path opened and otherwise managed by its caller.
Unlike the other changes, this one does not have "#ifdef __CYGWIN__" around
it since it applies equally well to all architectures.

Also included is a change to "sendbackup-gnutar" to not pass the
"--one-file-system" flag to gnutar (since it doesn't work under CygWin).
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/client-src/sendbackup-dump.c 
amanda-2.4.3/client-src/sendbackup-dump.c
--- amanda-2.4.3.orig/client-src/sendbackup-dump.c      2002-09-17 
11:32:43.000000000 -0400
+++ amanda-2.4.3/client-src/sendbackup-dump.c   2003-04-15 13:35:22.000000000 
-0400
@@ -371,10 +371,13 @@
 
     aclose(dumpin);
     aclose(dumpout);
+
+#if 0
     aclose(dataf);
     aclose(mesgf);
     if (options->createindex)
        aclose(indexf);
+#endif
 }
 
 static void end_backup(status)
diff -ru amanda-2.4.3.orig/client-src/sendbackup-gnutar.c 
amanda-2.4.3/client-src/sendbackup-gnutar.c
--- amanda-2.4.3.orig/client-src/sendbackup-gnutar.c    2002-05-27 
15:56:07.000000000 -0400
+++ amanda-2.4.3/client-src/sendbackup-gnutar.c 2003-04-10 09:45:59.000000000 
-0400
@@ -486,7 +486,9 @@
        my_argv[i++] = "-";
        my_argv[i++] = "--directory";
        my_argv[i++] = dirname;
+#ifndef __CYGWIN__
        my_argv[i++] = "--one-file-system";
+#endif
 #ifdef GNUTAR_LISTED_INCREMENTAL_DIR
        my_argv[i++] = "--listed-incremental";
        my_argv[i++] = incrname;
@@ -541,10 +543,13 @@
 
     aclose(dumpin);
     aclose(dumpout);
+
+#if 0
     aclose(dataf);
     aclose(mesgf);
     if (options->createindex)
        aclose(indexf);
+#endif
 }
 
 static void end_backup(goterror)
diff -ru amanda-2.4.3.orig/client-src/sendbackup.c 
amanda-2.4.3/client-src/sendbackup.c
--- amanda-2.4.3.orig/client-src/sendbackup.c   2002-05-27 15:56:07.000000000 
-0400
+++ amanda-2.4.3/client-src/sendbackup.c        2003-04-14 15:25:33.000000000 
-0400
@@ -457,8 +457,26 @@
 
     program->start_backup(g_options->hostname, disk, amdevice, level, dumpdate,
                          dataf, mesgpipe[1], indexf);
+
+    /* close our input to message pipe (external process is now writing to it) 
*/
+    aclose(mesgpipe[1]);
+
     parse_backup_messages(mesgpipe[0]);
 
+    /* close remaining paths */
+    aclose(dataf);
+    aclose(mesgf);
+    if (options->createindex) {
+      aclose(indexf);
+    }
+
     amfree(prog);
     amfree(disk);
     amfree(amdevice);
===============================================================================


===============================================================================
The Makefile does not include the defined extension in the list of executables
used when changing ownership and permissions during the install.  This is
not specific to CygWin.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/client-src/Makefile.in 
amanda-2.4.3/client-src/Makefile.in
--- amanda-2.4.3.orig/client-src/Makefile.in    2002-10-07 19:08:42.000000000 
-0400
+++ amanda-2.4.3/client-src/Makefile.in 2003-03-11 17:21:16.000000000 -0500
@@ -722,7 +722,7 @@
                echo chgrp $(SETUID_GROUP) $$pa; \
                chgrp $(SETUID_GROUP) $$pa; \
        done
-       @list="$(libexecdir)/calcsize $(libexecdir)/killpgrp 
$(libexecdir)/rundump $(libexecdir)/runtar"; \
+       @list="$(libexecdir)/calcsize$(EXEEXT) $(libexecdir)/killpgrp$(EXEEXT) 
$(libexecdir)/rundump$(EXEEXT) $(libexecdir)/runtar$(EXEEXT)"; \
        for p in $$list; do \
                if echo "$(sbin_SCRIPTS) $(libexec_PROGRAMS) 
$(libexec_SCRIPTS)" | grep `basename $$p` >/dev/null 2>&1; then \
                        pa=$(DESTDIR)`echo $$p|sed '$(transform)'`; \
===============================================================================


===============================================================================
CygWin needs to have the PATH exported to child programs.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/common-src/alloc.c amanda-2.4.3/common-src/alloc.c
--- amanda-2.4.3.orig/common-src/alloc.c        2002-03-24 15:31:25.000000000 
-0500
+++ amanda-2.4.3/common-src/alloc.c     2003-03-11 14:54:38.000000000 -0500
@@ -439,6 +439,9 @@
 {
     static char *safe_env_list[] = {
        "TZ",
+#ifdef __CYGWIN__
+       "PATH",
+#endif /* __CYGWIN__ */
        NULL
     };
===============================================================================


===============================================================================
CygWin requires that the userid be forced whether we're running as root or not.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/client-src/amandad.c 
amanda-2.4.3/client-src/amandad.c
--- amanda-2.4.3.orig/client-src/amandad.c      2002-04-17 16:08:14.000000000 
-0400
+++ amanda-2.4.3/client-src/amandad.c   2003-03-11 14:54:38.000000000 -0500
@@ -165,6 +165,9 @@
 #endif  /* KRB4_SECURITY */
     }
 #endif /* FORCE_USERID */
+#ifdef __CYGWIN__
+       setuid(client_uid);
+#endif /* __CYGWIN__ */
 
     /* initialize */
===============================================================================


===============================================================================
CygWin does not use support for filesystem mounts.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/client-src/getfsent.c 
amanda-2.4.3/client-src/getfsent.c
--- amanda-2.4.3.orig/client-src/getfsent.c     2002-09-30 14:40:37.000000000 
-0400
+++ amanda-2.4.3/client-src/getfsent.c  2003-03-11 15:14:10.000000000 -0500
@@ -155,6 +155,9 @@
 
 int open_fstab()
 {
+#ifdef __CYGWIN__
+return 0;
+#else
     close_fstab();
 #if defined(HAVE_SETMNTENT)
     fstabf1 = setmntent("/proc/mounts", "r");
@@ -170,6 +173,7 @@
 # endif
 #endif
     return (fstabf1 != NULL || fstabf2 != NULL || fstabf3 != NULL);
+#endif /* __CYGWIN__ */
 }
 
 void close_fstab()
===============================================================================


===============================================================================
CygWin sometimes has trouble with files owned by "root".  Remove the check.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/client-src/selfcheck.c 
amanda-2.4.3/client-src/selfcheck.c
--- amanda-2.4.3.orig/client-src/selfcheck.c    2002-04-25 20:45:38.000000000 
-0400
+++ amanda-2.4.3/client-src/selfcheck.c 2003-03-11 14:54:38.000000000 -0500
@@ -828,6 +828,9 @@
 char *filename;
 {
     struct stat stat_buf;
+#ifdef __CYGWIN__
+return;
+#else
     if(!stat(filename, &stat_buf)) {
        if(stat_buf.st_uid != 0 ) {
            printf("ERROR [%s is not owned by root]\n",filename);
@@ -839,4 +842,5 @@
     else {
        printf("ERROR [can not stat %s]\n",filename);
     }
+#endif /* __CYGWIN__ */
 }
===============================================================================


===============================================================================
The "--one-file-system" option is not supported by CygWin GnuTar.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/client-src/sendsize.c 
amanda-2.4.3/client-src/sendsize.c
--- amanda-2.4.3.orig/client-src/sendsize.c     2002-09-17 11:32:43.000000000 
-0400
+++ amanda-2.4.3/client-src/sendsize.c  2003-03-11 15:16:31.000000000 -0500
@@ -1423,7 +1423,9 @@
     my_argv[i++] = "/dev/null";
     my_argv[i++] = "--directory";
     my_argv[i++] = dirname;
+#ifndef __CYGWIN__
     my_argv[i++] = "--one-file-system";
+#endif
 #ifdef GNUTAR_LISTED_INCREMENTAL_DIR
     my_argv[i++] = "--listed-incremental";
     my_argv[i++] = incrname;
===============================================================================


===============================================================================
Remove necessity of having amrecover run as root under CygWin.
-------------------------------------------------------------------------------
diff -ru amanda-2.4.3.orig/recover-src/amrecover.c 
amanda-2.4.3/recover-src/amrecover.c
--- amanda-2.4.3.orig/recover-src/amrecover.c   2002-03-24 15:31:25.000000000 
-0500
+++ amanda-2.4.3/recover-src/amrecover.c        2003-03-11 14:54:38.000000000 
-0500
@@ -435,10 +435,12 @@
     set_pname("amrecover");
     dbopen();
 
+#ifndef __CYGWIN__
     if (geteuid() != 0) {
        erroutput_type |= ERR_SYSLOG;
        error("amrecover must be run by root");
     }
+#endif /* __CYGWIN__ */
 
     localhost = alloc(MAX_HOSTNAME_LENGTH+1);
     if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) {
===============================================================================


For those wanting to compile Amanada for CygWin, I'm placing everything on
a web page:  http://bcwhite.dhs.org/cygwin/amanda.html

                                          Brian
                                 ( bcwhite AT precidia DOT com )

-------------------------------------------------------------------------------
Seize the moment!  Live now.  Make "now" always the most important time. -- JLP
diff -ru amanda-2.4.3.orig/client-src/Makefile.in 
amanda-2.4.3/client-src/Makefile.in
--- amanda-2.4.3.orig/client-src/Makefile.in    2002-10-07 19:08:42.000000000 
-0400
+++ amanda-2.4.3/client-src/Makefile.in 2003-03-11 17:21:16.000000000 -0500
@@ -722,7 +722,7 @@
                echo chgrp $(SETUID_GROUP) $$pa; \
                chgrp $(SETUID_GROUP) $$pa; \
        done
-       @list="$(libexecdir)/calcsize $(libexecdir)/killpgrp 
$(libexecdir)/rundump $(libexecdir)/runtar"; \
+       @list="$(libexecdir)/calcsize$(EXEEXT) $(libexecdir)/killpgrp$(EXEEXT) 
$(libexecdir)/rundump$(EXEEXT) $(libexecdir)/runtar$(EXEEXT)"; \
        for p in $$list; do \
                if echo "$(sbin_SCRIPTS) $(libexec_PROGRAMS) 
$(libexec_SCRIPTS)" | grep `basename $$p` >/dev/null 2>&1; then \
                        pa=$(DESTDIR)`echo $$p|sed '$(transform)'`; \
diff -ru amanda-2.4.3.orig/client-src/amandad.c 
amanda-2.4.3/client-src/amandad.c
--- amanda-2.4.3.orig/client-src/amandad.c      2002-04-17 16:08:14.000000000 
-0400
+++ amanda-2.4.3/client-src/amandad.c   2003-03-11 14:54:38.000000000 -0500
@@ -165,6 +165,9 @@
 #endif  /* KRB4_SECURITY */
     }
 #endif /* FORCE_USERID */
+#ifdef __CYGWIN__
+       setuid(client_uid);
+#endif /* __CYGWIN__ */
 
     /* initialize */
 
diff -ru amanda-2.4.3.orig/client-src/getfsent.c 
amanda-2.4.3/client-src/getfsent.c
--- amanda-2.4.3.orig/client-src/getfsent.c     2002-09-30 14:40:37.000000000 
-0400
+++ amanda-2.4.3/client-src/getfsent.c  2003-03-11 15:14:10.000000000 -0500
@@ -155,6 +155,9 @@
 
 int open_fstab()
 {
+#ifdef __CYGWIN__
+return 0;
+#else
     close_fstab();
 #if defined(HAVE_SETMNTENT)
     fstabf1 = setmntent("/proc/mounts", "r");
@@ -170,6 +173,7 @@
 # endif
 #endif
     return (fstabf1 != NULL || fstabf2 != NULL || fstabf3 != NULL);
+#endif /* __CYGWIN__ */
 }
 
 void close_fstab()
diff -ru amanda-2.4.3.orig/client-src/selfcheck.c 
amanda-2.4.3/client-src/selfcheck.c
--- amanda-2.4.3.orig/client-src/selfcheck.c    2002-04-25 20:45:38.000000000 
-0400
+++ amanda-2.4.3/client-src/selfcheck.c 2003-03-11 14:54:38.000000000 -0500
@@ -828,6 +828,9 @@
 char *filename;
 {
     struct stat stat_buf;
+#ifdef __CYGWIN__
+return;
+#else
     if(!stat(filename, &stat_buf)) {
        if(stat_buf.st_uid != 0 ) {
            printf("ERROR [%s is not owned by root]\n",filename);
@@ -839,4 +842,5 @@
     else {
        printf("ERROR [can not stat %s]\n",filename);
     }
+#endif /* __CYGWIN__ */
 }
diff -ru amanda-2.4.3.orig/client-src/sendbackup-dump.c 
amanda-2.4.3/client-src/sendbackup-dump.c
--- amanda-2.4.3.orig/client-src/sendbackup-dump.c      2002-09-17 
11:32:43.000000000 -0400
+++ amanda-2.4.3/client-src/sendbackup-dump.c   2003-04-15 13:35:22.000000000 
-0400
@@ -371,10 +371,13 @@
 
     aclose(dumpin);
     aclose(dumpout);
+
+#if 0 /* we shouldn't close paths that were opened by our parent */
     aclose(dataf);
     aclose(mesgf);
     if (options->createindex)
        aclose(indexf);
+#endif
 }
 
 static void end_backup(status)
diff -ru amanda-2.4.3.orig/client-src/sendbackup-gnutar.c 
amanda-2.4.3/client-src/sendbackup-gnutar.c
--- amanda-2.4.3.orig/client-src/sendbackup-gnutar.c    2002-05-27 
15:56:07.000000000 -0400
+++ amanda-2.4.3/client-src/sendbackup-gnutar.c 2003-04-10 09:45:59.000000000 
-0400
@@ -486,7 +486,9 @@
        my_argv[i++] = "-";
        my_argv[i++] = "--directory";
        my_argv[i++] = dirname;
+#ifndef __CYGWIN__
        my_argv[i++] = "--one-file-system";
+#endif
 #ifdef GNUTAR_LISTED_INCREMENTAL_DIR
        my_argv[i++] = "--listed-incremental";
        my_argv[i++] = incrname;
@@ -541,10 +543,13 @@
 
     aclose(dumpin);
     aclose(dumpout);
+
+#if 0 /* we shouldn't close paths that were opened by our parent */
     aclose(dataf);
     aclose(mesgf);
     if (options->createindex)
        aclose(indexf);
+#endif
 }
 
 static void end_backup(goterror)
diff -ru amanda-2.4.3.orig/client-src/sendbackup.c 
amanda-2.4.3/client-src/sendbackup.c
--- amanda-2.4.3.orig/client-src/sendbackup.c   2002-05-27 15:56:07.000000000 
-0400
+++ amanda-2.4.3/client-src/sendbackup.c        2003-04-14 15:25:33.000000000 
-0400
@@ -457,8 +457,26 @@
 
     program->start_backup(g_options->hostname, disk, amdevice, level, dumpdate,
                          dataf, mesgpipe[1], indexf);
+
+    /* close our input to message pipe (external process is now writing to it) 
*/
+    aclose(mesgpipe[1]);
+
     parse_backup_messages(mesgpipe[0]);
 
+    /* close remaining paths */
+    aclose(dataf);
+    aclose(mesgf);
+    if (options->createindex) {
+      aclose(indexf);
+    }
+
     amfree(prog);
     amfree(disk);
     amfree(amdevice);
diff -ru amanda-2.4.3.orig/client-src/sendsize.c 
amanda-2.4.3/client-src/sendsize.c
--- amanda-2.4.3.orig/client-src/sendsize.c     2002-09-17 11:32:43.000000000 
-0400
+++ amanda-2.4.3/client-src/sendsize.c  2003-03-11 15:16:31.000000000 -0500
@@ -1423,7 +1423,9 @@
     my_argv[i++] = "/dev/null";
     my_argv[i++] = "--directory";
     my_argv[i++] = dirname;
+#ifndef __CYGWIN__
     my_argv[i++] = "--one-file-system";
+#endif
 #ifdef GNUTAR_LISTED_INCREMENTAL_DIR
     my_argv[i++] = "--listed-incremental";
     my_argv[i++] = incrname;
diff -ru amanda-2.4.3.orig/common-src/alloc.c amanda-2.4.3/common-src/alloc.c
--- amanda-2.4.3.orig/common-src/alloc.c        2002-03-24 15:31:25.000000000 
-0500
+++ amanda-2.4.3/common-src/alloc.c     2003-03-11 14:54:38.000000000 -0500
@@ -439,6 +439,9 @@
 {
     static char *safe_env_list[] = {
        "TZ",
+#ifdef __CYGWIN__
+"PATH",
+#endif \* __CYGWIN__ *\
        NULL
     };
 
diff -ru amanda-2.4.3.orig/recover-src/amrecover.c 
amanda-2.4.3/recover-src/amrecover.c
--- amanda-2.4.3.orig/recover-src/amrecover.c   2002-03-24 15:31:25.000000000 
-0500
+++ amanda-2.4.3/recover-src/amrecover.c        2003-03-11 14:54:38.000000000 
-0500
@@ -435,10 +435,12 @@
     set_pname("amrecover");
     dbopen();
 
+#ifndef __CYGWIN__
     if (geteuid() != 0) {
        erroutput_type |= ERR_SYSLOG;
        error("amrecover must be run by root");
     }
+#endif /* __CYGWIN__ */
 
     localhost = alloc(MAX_HOSTNAME_LENGTH+1);
     if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) {
<Prev in Thread] Current Thread [Next in Thread>
  • patch: CygWin support in Amanda 2.4.3, Brian White <=