--- postinstall.cc-orig 2002-05-18 23:07:52.000000000 -0400 +++ postinstall.cc 2002-10-16 19:40:07.000000000 -0400 @@ -33,7 +33,7 @@ public: RunFindVisitor (){} virtual void visitFile(String const &basePath, const WIN32_FIND_DATA *theFile) { - run_script ("/etc/postinstall/", theFile->cFileName); + run_script ("/etc/postinstall/", theFile->cFileName, "/var/log/setup.log.postinstall"); } virtual ~ RunFindVisitor () {} protected: --- ./script.cc-orig 2002-02-18 08:53:08.000000000 -0500 +++ ./script.cc 2002-10-16 19:01:18.000000000 -0400 @@ -30,6 +30,8 @@ static const char *cvsid = #include "filemanip.h" #include "mount.h" #include "io_stream.h" +#include +#include "script.h" static String sh = String(); static const char *cmd = 0; @@ -79,12 +81,16 @@ init_run_script () } static void -run (const char *sh, const char *args, const char *file) +run (const char *sh, const char *args, const char *file, const char *lname) { BOOL b; char cmdline[_MAX_PATH]; STARTUPINFO si; PROCESS_INFORMATION pi; + HANDLE file_out = INVALID_HANDLE_VALUE; + DWORD dwCPFlags = CREATE_NEW_CONSOLE; + BOOL bInheritHandles = FALSE; + DWORD nout; sprintf (cmdline, "%s %s %s", sh, args, file); memset (&pi, 0, sizeof (pi)); @@ -93,15 +99,59 @@ run (const char *sh, const char *args, c si.lpTitle = (char *) "Cygwin Setup Post-Install Script"; si.dwFlags = STARTF_USEPOSITION; - b = CreateProcess (0, cmdline, 0, 0, 0, - CREATE_NEW_CONSOLE, 0, get_root_dir ().cstr_oneuse(), &si, &pi); + if (lname) + { + SECURITY_ATTRIBUTES sa; + memset (&sa, 0, sizeof (sa)); + sa.nLength = sizeof (sa); + sa.bInheritHandle = TRUE; + sa.lpSecurityDescriptor = NULL; + file_out = CreateFile (backslash (cygpath (lname)).cstr_oneuse(), + FILE_APPEND_DATA, FILE_SHARE_WRITE, &sa, OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + if (file_out != INVALID_HANDLE_VALUE) + { + time_t now; time(&now); + char buf[100]; + struct tm *tm = localtime (&now); + strftime (buf, 1000, "%Y/%m/%d %H:%M:%S ", tm); + String msg = String (buf) + "Running: " + cmdline + "\n"; + DWORD msgl = (DWORD) msg.size(); + if (WriteFile (file_out, msg.cstr_oneuse(), msgl, &nout, NULL) && + nout == msgl) + { + bInheritHandles = TRUE; + si.dwFlags = STARTF_USESTDHANDLES; + si.hStdOutput = file_out; + si.hStdError = file_out; + dwCPFlags = 0; + } + } + } + + b = CreateProcess (0, cmdline, 0, 0, bInheritHandles, + dwCPFlags, 0, get_root_dir ().cstr_oneuse(), &si, &pi); if (b) WaitForSingleObject (pi.hProcess, INFINITE); + + if (lname) + { + if (file_out != INVALID_HANDLE_VALUE) + { + time_t now; time(&now); + char buf[100]; + struct tm *tm = localtime (&now); + strftime (buf, 1000, "%Y/%m/%d %H:%M:%S ", tm); + String msg = String (buf) + "Done: " + cmdline + "\n"; + WriteFile (file_out, msg.cstr_oneuse(), msg.size(), &nout, NULL); + CloseHandle(file_out); + } + } } void -run_script (String const &dir, String const &fname) +run_script (String const &dir, String const &fname, String const &lname) { char *ext = strrchr (fname.cstr_oneuse(), '.'); if (!ext) @@ -111,13 +161,13 @@ run_script (String const &dir, String co { String f2 = dir + fname; log (LOG_PLAIN, String ("running: ") + sh + " -c " + f2); - run (sh.cstr_oneuse(), "-c", f2.cstr_oneuse()); + run (sh.cstr_oneuse(), "-c", f2.cstr_oneuse(), lname.cstr_oneuse()); } else if (cmd && strcmp (ext, ".bat") == 0) { String f2 = backslash (cygpath (dir + fname)); log (LOG_PLAIN, String ("running: ") + cmd + " /c " + f2); - run (cmd, "/c", f2.cstr_oneuse()); + run (cmd, "/c", f2.cstr_oneuse(), lname.cstr_oneuse()); } else return; --- ./script.h-orig 2002-02-18 07:35:24.000000000 -0500 +++ ./script.h 2002-10-16 18:55:55.000000000 -0400 @@ -21,7 +21,7 @@ we have a Bourne shell, execute it using sh. Otherwise, if fname has suffix .bat, execute using cmd */ -void run_script (String const &dir, String const &fname); +void run_script (String const &dir, String const &fname, String const &lname = ""); /* Initialisation stuff for run_script: sh, cmd, CYGWINROOT and PATH */ void init_run_script ();