setup.exe sucks

Christopher Faylor cgf-no-personal-reply-please@cygwin.com
Fri Dec 10 00:45:00 GMT 2004


On Thu, Dec 09, 2004 at 05:25:09PM -0700, Warren Young wrote:
>Warren Young wrote:
>>stop running services before starting the upgrade.
>
>Thinking more about it, couldn't you just call LoadLibrary() on the
>full path to cygwin.dll, and if that succeeds, get the process list
>from it and send out kill signals?

Time for another sigh:  Sigh.

You can't use LoadLibrary with cygwin and I really wasn't suggesting that
we modify the DLL or introduce new functionality to accommodate setup.

That said, however, you could iterate over all of the running processes
and find out which was using cygwin1.dll.  You don't need cygwin for
that.

In fact, I was just playing around with some source code to do this
yesterday.  It is attached, for the curious.

cgf
-------------- next part --------------
#include <windows.h>
#include <ntdll.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <psapi.h>

static void snap (DWORD pid)
{
  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, pid);
  MODULEENTRY32 m;
  printf ("+PID %u\n", pid);
  m.dwSize = sizeof (m);
  while (Module32Next (h, &m)) {
      printf ("%s\n", m.szExePath);
  }
  CloseHandle (h);
}

static void nt (DWORD pid)
{
  HMODULE hMods[1024];
  DWORD cb;
  HANDLE h = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
			  FALSE, pid);
  printf ("-PID %u\n", pid);
  if (EnumProcessModules(h, hMods, sizeof (hMods), &cb)) {
      for (int i = 0; i < (cb / sizeof (hMods[0])); i++) {
	char path[MAX_PATH+1];
	if (GetModuleFileNameEx (h, hMods[i], path, sizeof(path)))
	  puts (path);
      }
  }
  CloseHandle (h);
}

int
main (int argc, char **argv)
{
  bool alt = 0;
  if (*argv[1] == '-') {
      alt = 1;
      argv++;
  }
  while (*++argv) {
      DWORD pid = atoi (*argv);
      if (!alt)
	snap (pid);
      else
	nt (pid);
  }
  exit (0);
}


More information about the Cygwin-apps mailing list