diff --git a/winsup/utils/Makefile.in b/winsup/utils/Makefile.in index 7ab7edb12..8526069bd 100644 --- a/winsup/utils/Makefile.in +++ b/winsup/utils/Makefile.in @@ -65,7 +65,7 @@ MINGW_DEP_LDLIBS:=${ALL_DEP_LDLIBS} ${MINGW_LIB} ALL_LDFLAGS:=-B$(newlib_build)/libc/ -B$(newlib_build)/libm/ -B$(w32api_lib)/ \ $(LDFLAGS) $(ALL_LDLIBS) MINGW_LDFLAGS:=$(ALL_LDFLAGS) $(MINGW_LIB) -DUMPER_LDFLAGS:=$(ALL_LDFLAGS) $(DUMPER_LIB) +DUMPER_LDFLAGS:=$(ALL_LDFLAGS) $(DUMPER_LIB) PROGS:=mount$(EXEEXT) umount$(EXEEXT) ps$(EXEEXT) kill$(EXEEXT) \ mkpasswd$(EXEEXT) mkgroup$(EXEEXT) cygpath$(EXEEXT) cygcheck$(EXEEXT) \ diff --git a/winsup/utils/configure.in b/winsup/utils/configure.in index a38e00807..fc9cd160d 100644 --- a/winsup/utils/configure.in +++ b/winsup/utils/configure.in @@ -1,8 +1,8 @@ dnl Autoconf configure script for Cygwin utilities. -dnl Copyright 1996, 1997 Cygnus Solutions. +dnl Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions. dnl dnl This file is part of Cygwin. -dnl +dnl dnl This software is a copyrighted work licensed under the terms of the dnl Cygwin license. Please consult the file "CYGWIN_LICENSE" for dnl details. diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc index f3f3c1019..94734c98e 100644 --- a/winsup/utils/cygcheck.cc +++ b/winsup/utils/cygcheck.cc @@ -29,8 +29,7 @@ typedef long long longlong; typedef __int64 longlong; #endif -const char *known_env_vars[] = -{ +const char *known_env_vars[] = { "c_include_path", "compiler_path", "cxx_include_path", @@ -55,21 +54,45 @@ const char *known_env_vars[] = 0 }; -struct { +struct +{ const char *name; int missing_is_good; -} common_apps[] = { - { "bash", 0 }, - { "cat", 0 }, - { "cpp", 1 }, - { "find", 0 }, - { "gcc", 0 }, - { "gdb", 0 }, - { "ld", 0 }, - { "ls", 0 }, - { "make", 0 }, - { "sh", 0 }, - { 0, 0 } +} +common_apps[] = +{ + { + "bash", 0} + , + { + "cat", 0} + , + { + "cpp", 1} + , + { + "find", 0} + , + { + "gcc", 0} + , + { + "gdb", 0} + , + { + "ld", 0} + , + { + "ls", 0} + , + { + "make", 0} + , + { + "sh", 0} + , + { + 0, 0} }; int num_paths = 0, max_paths = 0; @@ -102,8 +125,8 @@ void init_paths () { char tmp[4000], *sl; - add_path ((char *) ".", 1); /* to be replaced later */ - add_path ((char *) ".", 1); /* the current directory */ + add_path ((char *) ".", 1); /* to be replaced later */ + add_path ((char *) ".", 1); /* the current directory */ GetSystemDirectory (tmp, 4000); add_path (tmp, strlen (tmp)); sl = strrchr (tmp, '\\'); @@ -148,7 +171,7 @@ find_on_path (char *file, char *default_extension, return file; if (strchr (file, '.')) - default_extension = (char *)""; + default_extension = (char *) ""; for (int i = 0; i < num_paths; i++) { @@ -263,13 +286,13 @@ struct ExpDirectory }; struct ImpDirectory - { - unsigned characteristics; - unsigned timestamp; - unsigned forwarder_chain; - unsigned name_rva; - unsigned iat_rva; - }; +{ + unsigned characteristics; + unsigned timestamp; + unsigned forwarder_chain; + unsigned name_rva; + unsigned iat_rva; +}; void track_down (char *file, char *suffix, int lvl); @@ -299,9 +322,9 @@ cygwin_info (HANDLE h) major = minor = NULL; while (buf < bufend) if ((buf = (char *) memchr (buf, '%', bufend - buf)) == NULL) - break; + break; else if (strncmp ("%%% Cygwin ", buf, CYGPREFIX) != 0) - buf++; + buf++; else { char *p = strchr (buf += CYGPREFIX, '\n'); @@ -339,8 +362,10 @@ dll_info (const char *path, HANDLE fh, int lvl, int recurse) int nsections = get_word (fh, pe_header_offset + 4 + 2); char *sections = (char *) malloc (nsections * 40); - SetFilePointer (fh, pe_header_offset + 4 + 20 + get_word (fh, pe_header_offset + 4 + 16), - 0, FILE_BEGIN); + SetFilePointer (fh, + pe_header_offset + 4 + 20 + get_word (fh, + pe_header_offset + 4 + + 16), 0, FILE_BEGIN); ReadFile (fh, sections, nsections * 40, &junk, 0); if (verbose && num_entries >= 1 && export_size > 0) @@ -436,8 +461,9 @@ track_down (char *file, char *suffix, int lvl) printf ("%s", path); - HANDLE fh = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE fh = + CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (fh == INVALID_HANDLE_VALUE) { printf (" - Cannot open\n"); @@ -462,8 +488,7 @@ ls (char *f) FileTimeToSystemTime (&info.ftLastWriteTime, &systime); printf ("%5dk %04d/%02d/%02d %s", (((int) info.nFileSizeLow) + 512) / 1024, - systime.wYear, systime.wMonth, systime.wDay, - f); + systime.wYear, systime.wMonth, systime.wDay, f); dll_info (f, h, 16, 0); CloseHandle (h); @@ -498,11 +523,11 @@ cygcheck (char *app) extern char **environ; struct RegInfo - { - RegInfo *prev; - char *name; - HKEY key; - }; +{ + RegInfo *prev; + char *name; + HKEY key; +}; void show_reg (RegInfo * ri, int nest) @@ -538,8 +563,7 @@ scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus) #if 0 char tmp[400]; FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (), - MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp, - 400, 0); + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp, 400, 0); printf ("RegQueryInfoKey: %s\n", tmp); #endif return; @@ -574,16 +598,6 @@ scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus) break; } } -#if 0 - else - { - char tmp[400]; - FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (), - MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp, - 400, 0); - printf ("RegEnumValue: %s\n", tmp); - } -#endif } free (value_name); free (value_data); @@ -592,7 +606,8 @@ scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus) char *subkey_name = (char *) malloc (max_subkey_len + 1); for (i = 0; i < num_subkeys; i++) { - if (RegEnumKey (hKey, i, subkey_name, max_subkey_len + 1) == ERROR_SUCCESS) + if (RegEnumKey (hKey, i, subkey_name, max_subkey_len + 1) == + ERROR_SUCCESS) { HKEY sKey; if (RegOpenKeyEx (hKey, subkey_name, 0, KEY_ALL_ACCESS, &sKey) @@ -746,13 +761,14 @@ dump_sysinfo () printf ("Listing available drives...\n"); printf ("Drv Type Size Free Flags Name\n"); } - int prev_mode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + int prev_mode = + SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); int drivemask = GetLogicalDrives (); HINSTANCE k32 = LoadLibrary ("kernel32.dll"); - BOOL (WINAPI *gdfse) (LPCSTR, long long *, long long *, long long *) = + BOOL (WINAPI * gdfse) (LPCSTR, long long *, long long *, long long *) = (BOOL (WINAPI *) (LPCSTR, long long *, long long *, long long *)) - GetProcAddress (k32, "GetDiskFreeSpaceExA"); + GetProcAddress (k32, "GetDiskFreeSpaceExA"); for (i = 0; i < 26; i++) { @@ -790,8 +806,7 @@ dump_sysinfo () int percent_full = -1; long long free_me = 0ULL, free_bytes = 0ULL, total_bytes = 1ULL; - if (gdfse != NULL - && gdfse (drive, & free_me, & total_bytes, & free_bytes)) + if (gdfse != NULL && gdfse (drive, &free_me, &total_bytes, &free_bytes)) { capacity_mb = total_bytes / (1024L * 1024L); percent_full = 100 - (int) ((100.0 * free_me) / total_bytes); @@ -834,7 +849,8 @@ dump_sysinfo () { printf ("fd=floppy, hd=hard drive, cd=CD-ROM, net=Network Share\n"); printf ("CP=Case Preserving, CS=Case Sensitive, UN=Unicode\n"); - printf ("PA=Persistent ACLS, FC=File Compression, VC=Volume Compression\n"); + printf + ("PA=Persistent ACLS, FC=File Compression, VC=Volume Compression\n"); } printf ("\n"); @@ -842,10 +858,9 @@ dump_sysinfo () if (givehelp) { - printf ("Mount entries: these map POSIX directories to your NT drives.\n"); - printf ("%-*s %-*s %-*s %s\n", - ml_fsname, "-NT-", - ml_dir, "-POSIX-", + printf + ("Mount entries: these map POSIX directories to your NT drives.\n"); + printf ("%-*s %-*s %-*s %s\n", ml_fsname, "-NT-", ml_dir, "-POSIX-", ml_type, "-Type-", "-Flags-"); } @@ -856,24 +871,23 @@ dump_sysinfo () { printf ("%-*s %-*s %-*s %s\n", ml_fsname, mnt->mnt_fsname, - ml_dir, mnt->mnt_dir, - ml_type, mnt->mnt_type, - mnt->mnt_opts); + ml_dir, mnt->mnt_dir, ml_type, mnt->mnt_type, mnt->mnt_opts); } printf ("\n"); add_path ((char *) "\\bin", 4); /* just in case */ if (givehelp) - printf ("Looking to see where common programs can be found, if at all...\n"); + printf + ("Looking to see where common programs can be found, if at all...\n"); for (i = 0; common_apps[i].name; i++) if (!find_on_path ((char *) common_apps[i].name, (char *) ".exe", 1, 0)) - { - if (common_apps[i].missing_is_good) - printf ("Not Found: %s (good!)\n", common_apps[i].name); - else - printf ("Not Found: %s\n", common_apps[i].name); - } + { + if (common_apps[i].missing_is_good) + printf ("Not Found: %s (good!)\n", common_apps[i].name); + else + printf ("Not Found: %s\n", common_apps[i].name); + } printf ("\n"); if (givehelp) @@ -922,8 +936,8 @@ int check_keys () { HANDLE h = CreateFileA ("CONIN$", GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE || h == NULL) return keyeprint ("Opening CONIN$"); @@ -936,7 +950,7 @@ check_keys () { mode &= ~ENABLE_PROCESSED_INPUT; if (!SetConsoleMode (h, mode)) - keyeprint ("GetConsoleMode"); + keyeprint ("GetConsoleMode"); } fputs ("\nThis key check works only in a console window,", stderr); @@ -955,70 +969,74 @@ check_keys () { prev_in = in; if (!ReadConsoleInput (h, &in, 1, &mode)) - keyeprint ("ReadConsoleInput"); + keyeprint ("ReadConsoleInput"); if (!memcmp (&in, &prev_in, sizeof in)) - continue; + continue; switch (in.EventType) - { - case KEY_EVENT: - printf ("%s %ux VK: 0x%02x VS: 0x%02x A: 0x%02x CTRL: ", - in.Event.KeyEvent.bKeyDown ? "Pressed " : "Released", - in.Event.KeyEvent.wRepeatCount, - in.Event.KeyEvent.wVirtualKeyCode, - in.Event.KeyEvent.wVirtualScanCode, - (unsigned char) in.Event.KeyEvent.uChar.AsciiChar); - fputs (in.Event.KeyEvent.dwControlKeyState & CAPSLOCK_ON ? - "CL " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY ? - "EK " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED ? - "LA " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_CTRL_PRESSED ? - "LC " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & NUMLOCK_ON ? - "NL " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED ? - "RA " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED ? - "RC " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & SCROLLLOCK_ON ? - "SL " : "-- ", stdout); - fputs (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED ? - "SH " : "-- ", stdout); - fputc ('\n', stdout); - break; + { + case KEY_EVENT: + printf ("%s %ux VK: 0x%02x VS: 0x%02x A: 0x%02x CTRL: ", + in.Event.KeyEvent.bKeyDown ? "Pressed " : "Released", + in.Event.KeyEvent.wRepeatCount, + in.Event.KeyEvent.wVirtualKeyCode, + in.Event.KeyEvent.wVirtualScanCode, + (unsigned char) in.Event.KeyEvent.uChar.AsciiChar); + fputs (in.Event.KeyEvent.dwControlKeyState & CAPSLOCK_ON ? + "CL " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY ? + "EK " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED ? + "LA " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_CTRL_PRESSED ? + "LC " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & NUMLOCK_ON ? + "NL " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED ? + "RA " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED ? + "RC " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & SCROLLLOCK_ON ? + "SL " : "-- ", stdout); + fputs (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED ? + "SH " : "-- ", stdout); + fputc ('\n', stdout); + break; - } + } } while (in.EventType != KEY_EVENT || - in.Event.KeyEvent.bKeyDown != FALSE || - in.Event.KeyEvent.uChar.AsciiChar != 'q'); + in.Event.KeyEvent.bKeyDown != FALSE || + in.Event.KeyEvent.uChar.AsciiChar != 'q'); CloseHandle (h); return 0; } + void usage () { fprintf (stderr, "Usage: cygcheck [OPTIONS] [program ...]\n"); fprintf (stderr, " -s, --sysinfo = system information (not with -k)\n"); - fprintf (stderr, " -v, --verbose = verbose output (indented) (for -s or programs)\n"); + fprintf (stderr, + " -v, --verbose = verbose output (indented) (for -s or programs)\n"); fprintf (stderr, " -r, --registry = registry search (requires -s)\n"); - fprintf (stderr, " -k, --keycheck = perform a keyboard check session (not with -s)\n"); + fprintf (stderr, + " -k, --keycheck = perform a keyboard check session (not with -s)\n"); fprintf (stderr, " -h, --help = give help about the info\n"); - fprintf (stderr, "You must at least give either -s or -k or a program name\n"); + fprintf (stderr, + "You must at least give either -s or -k or a program name\n"); exit (1); } struct option longopts[] = { - { "sysinfo", no_argument, NULL, 's' }, - { "registry", no_argument, NULL, 'r' }, - { "verbose", no_argument, NULL, 'v' }, - { "keycheck", no_argument, NULL, 'k' }, - { "help", no_argument, NULL, 'h' }, - { 0, no_argument, NULL, 0 } + {"sysinfo", no_argument, NULL, 's'}, + {"registry", no_argument, NULL, 'r'}, + {"verbose", no_argument, NULL, 'v'}, + {"keycheck", no_argument, NULL, 'k'}, + {"help", no_argument, NULL, 'h'}, + {0, no_argument, NULL, 0} }; char *opts = "srvkh"; @@ -1031,24 +1049,23 @@ main (int argc, char **argv) switch (i) { case 's': - sysinfo = 1; - break; + sysinfo = 1; + break; case 'r': - registry = 1; - break; + registry = 1; + break; case 'v': - verbose = 1; - break; + verbose = 1; + break; case 'k': - keycheck = 1; - break; + keycheck = 1; + break; case 'h': - givehelp = 1; - break; + givehelp = 1; + break; default: - usage (); - /*NOTREACHED*/ - } + usage (); + /*NOTREACHED*/} argc -= optind; argv += optind; @@ -1059,7 +1076,7 @@ main (int argc, char **argv) usage (); if (keycheck) - return check_keys(); + return check_keys (); init_paths (); @@ -1067,12 +1084,14 @@ main (int argc, char **argv) { if (argc == 1) { - printf ("Here is where the OS will find your program, and which dlls\n"); + printf + ("Here is where the OS will find your program, and which dlls\n"); printf ("will be used for it. Use -v to see DLL version info\n"); } else { - printf ("Here is where the OS will find your programs, and which dlls\n"); + printf + ("Here is where the OS will find your programs, and which dlls\n"); printf ("will be used for them. Use -v to see DLL version info\n"); } diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc index d16132f55..8e2aa1d89 100644 --- a/winsup/utils/cygpath.cc +++ b/winsup/utils/cygpath.cc @@ -52,13 +52,13 @@ Usage: %s [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) filename\n\ -a|--absolute output absolute path\n\ -c|--close handle close handle (for use in captured process)\n\ -f|--file file read file for path information\n\ - -u|--unix print Unix form of filename\n\ - -w|--windows print Windows form of filename\n\ + -u|--unix print Unix form of filename\n\ + -w|--windows print Windows form of filename\n\ -s|--short-name print Windows short form of filename\n\ - -W|--windir print `Windows' directory\n\ - -S|--sysdir print `system' directory\n\ - -p|--path filename argument is a path\n\ - -i|--ignore ignore missing argument\n", + -W|--windir print `Windows' directory\n\ + -S|--sysdir print `system' directory\n\ + -p|--path filename argument is a path\n\ + -i|--ignore ignore missing argument\n", prog_name); exit (ignore_flag ? 0 : status); } diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc index 6ccf2f1c9..df3f14640 100644 --- a/winsup/utils/dumper.cc +++ b/winsup/utils/dumper.cc @@ -4,11 +4,11 @@ Written by Egor Duda -This file is part of Cygwin. + This file is part of Cygwin. -This software is a copyrighted work licensed under the terms of the -Cygwin license. Please consult the file "CYGWIN_LICENSE" for -details. */ + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ #include #include @@ -27,35 +27,36 @@ details. */ #define NOTE_NAME_SIZE 16 typedef struct _note_header -{ - Elf_External_Note elf_note_header; - char name [ NOTE_NAME_SIZE - 1 ]; /* external note contains first byte of data */ -} + { + Elf_External_Note elf_note_header; + char name[NOTE_NAME_SIZE - 1]; /* external note contains first byte of data */ + } #ifdef __GNUC__ - __attribute__ ((packed)) +__attribute__ ((packed)) #endif -note_header ; + note_header; -BOOL verbose = FALSE; + BOOL verbose = FALSE; -int deb_printf ( const char* format, ... ) + int deb_printf (const char *format,...) { - if ( !verbose ) return 0; + if (!verbose) + return 0; va_list va; - va_start ( va, format ); - int ret_val = vprintf ( format, va ); - va_end ( va ); + va_start (va, format); + int ret_val = vprintf (format, va); + va_end (va); return ret_val; } -dumper::dumper ( DWORD pid, DWORD tid, const char* file_name ) +dumper::dumper (DWORD pid, DWORD tid, const char *file_name) { - this->file_name = strdup ( file_name ); + this->file_name = strdup (file_name); this->pid = pid; this->tid = tid; core_bfd = NULL; - excl_list = new exclusion ( 20 ); + excl_list = new exclusion (20); list = last = NULL; @@ -63,39 +64,43 @@ dumper::dumper ( DWORD pid, DWORD tid, const char* file_name ) memory_num = module_num = thread_num = 0; - hProcess = OpenProcess ( PROCESS_ALL_ACCESS, - FALSE, /* no inheritance */ - pid ); - if ( !hProcess ) + hProcess = OpenProcess (PROCESS_ALL_ACCESS, + FALSE, /* no inheritance */ + pid); + if (!hProcess) { - fprintf ( stderr, "Failed to open process #%lu\n", pid ); + fprintf (stderr, "Failed to open process #%lu\n", pid); return; } init_core_dump (); - if ( ! sane () ) dumper_abort (); + if (!sane ()) + dumper_abort (); } -dumper::~dumper () +dumper: :~dumper () { close (); - free ( file_name ); + free (file_name); } void dumper::dumper_abort () { close (); - unlink ( file_name ); + unlink (file_name); } void dumper::close () { - if ( core_bfd ) bfd_close ( core_bfd ); - if ( excl_list ) delete excl_list; - if ( hProcess ) CloseHandle ( hProcess ); + if (core_bfd) + bfd_close (core_bfd); + if (excl_list) + delete excl_list; + if (hProcess) + CloseHandle (hProcess); core_bfd = NULL; hProcess = NULL; excl_list = NULL; @@ -104,20 +109,23 @@ dumper::close () int dumper::sane () { - if ( hProcess == NULL || core_bfd == NULL || excl_list == NULL ) return 0; + if (hProcess == NULL || core_bfd == NULL || excl_list == NULL) + return 0; return 1; } -process_entity* -dumper::add_process_entity_to_list ( process_entity_type type ) +process_entity * +dumper::add_process_entity_to_list (process_entity_type type) { - if ( ! sane () ) return NULL; + if (!sane ()) + return NULL; - process_entity* new_entity = ( process_entity* ) malloc ( sizeof ( process_entity ) ); - if ( new_entity == NULL ) return NULL; + process_entity *new_entity = (process_entity *) malloc (sizeof (process_entity)); + if (new_entity == NULL) + return NULL; new_entity->next = NULL; new_entity->section = NULL; - if ( last == NULL ) + if (last == NULL) list = new_entity; else last->next = new_entity; @@ -126,101 +134,111 @@ dumper::add_process_entity_to_list ( process_entity_type type ) } int -dumper::add_thread ( DWORD tid, HANDLE hThread ) +dumper::add_thread (DWORD tid, HANDLE hThread) { - if ( ! sane () ) return 0 ; + if (!sane ()) + return 0; - CONTEXT* pcontext; + CONTEXT *pcontext; - process_entity* new_entity = add_process_entity_to_list ( pr_ent_thread ); - if ( new_entity == NULL ) return 0; + process_entity *new_entity = add_process_entity_to_list (pr_ent_thread); + if (new_entity == NULL) + return 0; new_entity->type = pr_ent_thread; thread_num++; new_entity->u.thread.tid = tid; new_entity->u.thread.hThread = hThread; - pcontext = &( new_entity->u.thread.context ); + pcontext = &(new_entity->u.thread.context); pcontext->ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT; - if ( ! GetThreadContext ( hThread, pcontext ) ) return 0; + if (!GetThreadContext (hThread, pcontext)) + return 0; - deb_printf ( "added thread %u\n", tid ); + deb_printf ("added thread %u\n", tid); return 1; } int -dumper::add_mem_region ( LPBYTE base, DWORD size ) +dumper::add_mem_region (LPBYTE base, DWORD size) { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - if ( base == NULL || size == 0 ) return 1; // just ignore empty regions + if (base == NULL || size == 0) + return 1; // just ignore empty regions - process_entity* new_entity = add_process_entity_to_list ( pr_ent_memory ); - if ( new_entity == NULL ) return 0; + process_entity *new_entity = add_process_entity_to_list (pr_ent_memory); + if (new_entity == NULL) + return 0; new_entity->type = pr_ent_memory; memory_num++; new_entity->u.memory.base = base; new_entity->u.memory.size = size; - deb_printf ( "added memory region %08x-%08x\n", (DWORD)base, (DWORD)base + size ); + deb_printf ("added memory region %08x-%08x\n", (DWORD) base, (DWORD) base + size); return 1; } -/* - * split_add_mem_region scans list of regions to be excluded from dumping process - * (excl_list) and removes all "excluded" parts from given region - */ +/* split_add_mem_region scans list of regions to be excluded from dumping process + (excl_list) and removes all "excluded" parts from given region. */ int -dumper::split_add_mem_region ( LPBYTE base, DWORD size ) +dumper::split_add_mem_region (LPBYTE base, DWORD size) { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - if ( base == NULL || size == 0 ) return 1; // just ignore empty regions + if (base == NULL || size == 0) + return 1; // just ignore empty regions LPBYTE last_base = base; - for ( process_mem_region* p = excl_list->region; - p < excl_list->region + excl_list->last; - p++ ) + for (process_mem_region * p = excl_list->region; + p < excl_list->region + excl_list->last; + p++) { - if ( p->base >= base + size || p->base + p->size <= base ) continue; + if (p->base >= base + size || p->base + p->size <= base) + continue; - if ( p->base <= base ) - { - last_base = p->base + p->size; - continue ; - } + if (p->base <= base) + { + last_base = p->base + p->size; + continue; + } - add_mem_region ( last_base, p->base - last_base ); + add_mem_region (last_base, p->base - last_base); last_base = p->base + p->size; } - if ( last_base < base + size ) - add_mem_region ( last_base, base + size - last_base ); + if (last_base < base + size) + add_mem_region (last_base, base + size - last_base); return 1; } int -dumper::add_module ( LPVOID base_address ) +dumper::add_module (LPVOID base_address) { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - char* module_name = psapi_get_module_name ( hProcess, (DWORD) base_address ); - if ( module_name == NULL ) return 1; + char *module_name = psapi_get_module_name (hProcess, (DWORD) base_address); + if (module_name == NULL) + return 1; - process_entity* new_entity = add_process_entity_to_list ( pr_ent_module ); - if ( new_entity == NULL ) return 0; + process_entity *new_entity = add_process_entity_to_list (pr_ent_module); + if (new_entity == NULL) + return 0; new_entity->type = pr_ent_module; module_num++; new_entity->u.module.base_address = base_address; new_entity->u.module.name = module_name; - parse_pe ( module_name, excl_list ); + parse_pe (module_name, excl_list); - deb_printf ( "added module %08x %s\n", base_address, module_name ); + deb_printf ("added module %08x %s\n", base_address, module_name); return 1; } @@ -229,89 +247,94 @@ dumper::add_module ( LPVOID base_address ) int dumper::collect_memory_sections () { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; LPBYTE current_page_address; LPBYTE last_base = (LPBYTE) 0xFFFFFFFF; DWORD last_size = 0; DWORD done; - char mem_buf [ PAGE_BUFFER_SIZE ]; + char mem_buf[PAGE_BUFFER_SIZE]; MEMORY_BASIC_INFORMATION mbi; - if ( hProcess == NULL ) return 0; + if (hProcess == NULL) + return 0; - for ( current_page_address = 0; current_page_address < (LPBYTE) 0xFFFF0000; ) + for (current_page_address = 0; current_page_address < (LPBYTE) 0xFFFF0000;) { - if ( ! VirtualQueryEx ( hProcess, current_page_address, &mbi, sizeof ( mbi ) ) ) - break ; + if (!VirtualQueryEx (hProcess, current_page_address, &mbi, sizeof (mbi))) + break; int skip_region_p = 0; - if ( mbi.Protect & ( PAGE_NOACCESS | PAGE_GUARD ) || - mbi.State != MEM_COMMIT ) skip_region_p = 1; + if (mbi.Protect & (PAGE_NOACCESS | PAGE_GUARD) || + mbi.State != MEM_COMMIT) + skip_region_p = 1; - if ( ! skip_region_p ) - { - /* just to make sure that later we'll be able to read it. - According to MS docs either region is all-readable or - all-nonreadable */ - if ( ! ReadProcessMemory ( hProcess, current_page_address, mem_buf, sizeof ( mem_buf ), &done ) ) - { - const char* pt[10] ; - pt[0] = ( mbi.Protect & PAGE_READONLY ) ? "RO " : ""; - pt[1] = ( mbi.Protect & PAGE_READWRITE ) ? "RW " : ""; - pt[2] = ( mbi.Protect & PAGE_WRITECOPY ) ? "WC " : ""; - pt[3] = ( mbi.Protect & PAGE_EXECUTE ) ? "EX " : ""; - pt[4] = ( mbi.Protect & PAGE_EXECUTE_READ ) ? "EXRO " : ""; - pt[5] = ( mbi.Protect & PAGE_EXECUTE_READWRITE ) ? "EXRW " : ""; - pt[6] = ( mbi.Protect & PAGE_EXECUTE_WRITECOPY ) ? "EXWC " : ""; - pt[7] = ( mbi.Protect & PAGE_GUARD ) ? "GRD " : ""; - pt[8] = ( mbi.Protect & PAGE_NOACCESS ) ? "NA " : ""; - pt[9] = ( mbi.Protect & PAGE_NOCACHE ) ? "NC " : ""; - char buf [ 10*6 ] ; - buf [ 0 ] = '\0'; - for ( int i = 0 ; i < 10 ; i++ ) strcat ( buf, pt[i] ); + if (!skip_region_p) + { + /* just to make sure that later we'll be able to read it. + According to MS docs either region is all-readable or + all-nonreadable */ + if (!ReadProcessMemory (hProcess, current_page_address, mem_buf, sizeof (mem_buf), &done)) + { + const char *pt[10]; + pt[0] = (mbi.Protect & PAGE_READONLY) ? "RO " : ""; + pt[1] = (mbi.Protect & PAGE_READWRITE) ? "RW " : ""; + pt[2] = (mbi.Protect & PAGE_WRITECOPY) ? "WC " : ""; + pt[3] = (mbi.Protect & PAGE_EXECUTE) ? "EX " : ""; + pt[4] = (mbi.Protect & PAGE_EXECUTE_READ) ? "EXRO " : ""; + pt[5] = (mbi.Protect & PAGE_EXECUTE_READWRITE) ? "EXRW " : ""; + pt[6] = (mbi.Protect & PAGE_EXECUTE_WRITECOPY) ? "EXWC " : ""; + pt[7] = (mbi.Protect & PAGE_GUARD) ? "GRD " : ""; + pt[8] = (mbi.Protect & PAGE_NOACCESS) ? "NA " : ""; + pt[9] = (mbi.Protect & PAGE_NOCACHE) ? "NC " : ""; + char buf[10 * 6]; + buf[0] = '\0'; + for (int i = 0; i < 10; i++) + strcat (buf, pt[i]); - deb_printf ( "warning: failed to read memory at %08x-%08x. protect = %s\n", - (DWORD)current_page_address, - (DWORD)current_page_address + mbi.RegionSize, - buf ); + deb_printf ("warning: failed to read memory at %08x-%08x. protect = %s\n", + (DWORD) current_page_address, + (DWORD) current_page_address + mbi.RegionSize, + buf); skip_region_p = 1; - } - } + } + } - if ( ! skip_region_p ) - { - if ( last_base + last_size == current_page_address ) - last_size += mbi.RegionSize; - else - { - split_add_mem_region ( last_base, last_size ); - last_base = (LPBYTE) mbi.BaseAddress; - last_size = mbi.RegionSize; - } - } + if (!skip_region_p) + { + if (last_base + last_size == current_page_address) + last_size += mbi.RegionSize; + else + { + split_add_mem_region (last_base, last_size); + last_base = (LPBYTE) mbi.BaseAddress; + last_size = mbi.RegionSize; + } + } else - { - split_add_mem_region ( last_base, last_size ); + { + split_add_mem_region (last_base, last_size); last_base = NULL; - last_size = 0; - } + last_size = 0; + } current_page_address += mbi.RegionSize; } /* dump last sections, if any */ - split_add_mem_region ( last_base, last_size ); + split_add_mem_region (last_base, last_size); return 1; }; int -dumper::dump_memory_region ( asection* to, process_mem_region* memory ) +dumper::dump_memory_region (asection * to, process_mem_region * memory) { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; DWORD size = memory->size; DWORD todo; @@ -319,126 +342,132 @@ dumper::dump_memory_region ( asection* to, process_mem_region* memory ) LPBYTE pos = memory->base; DWORD sect_pos = 0; - if ( to == NULL || memory == NULL ) return 0; + if (to == NULL || memory == NULL) + return 0; - char mem_buf [ PAGE_BUFFER_SIZE ]; + char mem_buf[PAGE_BUFFER_SIZE]; - while ( size > 0 ) + while (size > 0) { - todo = min ( size, PAGE_BUFFER_SIZE ); - if ( ! ReadProcessMemory ( hProcess, pos, mem_buf, todo, &done ) ) + todo = min (size, PAGE_BUFFER_SIZE); + if (!ReadProcessMemory (hProcess, pos, mem_buf, todo, &done)) { - deb_printf ( "Error reading process memory at %x(%x) %u\n", pos, todo, GetLastError () ); + deb_printf ("Error reading process memory at %x(%x) %u\n", pos, todo, GetLastError ()); return 0; } size -= done; pos += done; - if ( ! bfd_set_section_contents ( core_bfd, to, mem_buf, sect_pos, done ) ) - { - bfd_perror ( "writing memory region to bfd" ); - dumper_abort (); - return 0; - } ; + if (!bfd_set_section_contents (core_bfd, to, mem_buf, sect_pos, done)) + { + bfd_perror ("writing memory region to bfd"); + dumper_abort (); + return 0; + }; sect_pos += done; } return 1; } int -dumper::dump_thread ( asection* to, process_thread* thread ) +dumper::dump_thread (asection * to, process_thread * thread) { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - if ( to == NULL || thread == NULL ) return 0; + if (to == NULL || thread == NULL) + return 0; win32_pstatus thread_pstatus; note_header header; - bfd_putl32 ( NOTE_NAME_SIZE, header.elf_note_header.namesz ); - bfd_putl32 ( sizeof ( thread_pstatus ), header.elf_note_header.descsz ); - bfd_putl32 ( NT_WIN32PSTATUS, header.elf_note_header.type ); - strncpy ( (char*) & header.elf_note_header.name, "win32thread", NOTE_NAME_SIZE ); + bfd_putl32 (NOTE_NAME_SIZE, header.elf_note_header.namesz); + bfd_putl32 (sizeof (thread_pstatus), header.elf_note_header.descsz); + bfd_putl32 (NT_WIN32PSTATUS, header.elf_note_header.type); + strncpy ((char *) &header.elf_note_header.name, "win32thread", NOTE_NAME_SIZE); thread_pstatus.data_type = NOTE_INFO_THREAD; thread_pstatus.data.thread_info.tid = thread->tid; - if ( tid == 0 ) + if (tid == 0) { /* this is a special case. we don't know, which thread - was active when exception occured, so let's blame + was active when exception occured, so let's blame the first one */ - thread_pstatus.data.thread_info.is_active_thread = TRUE ; - tid = (DWORD) -1 ; + thread_pstatus.data.thread_info.is_active_thread = TRUE; + tid = (DWORD) - 1; } - else if ( tid > 0 && thread->tid == tid ) + else if (tid > 0 && thread->tid == tid) thread_pstatus.data.thread_info.is_active_thread = TRUE; else thread_pstatus.data.thread_info.is_active_thread = FALSE; - memcpy ( &(thread_pstatus.data.thread_info.thread_context), - &(thread->context), - sizeof ( thread->context ) ); + memcpy (&(thread_pstatus.data.thread_info.thread_context), + &(thread->context), + sizeof (thread->context)); - if ( ! bfd_set_section_contents ( core_bfd, to, &header, - 0, - sizeof ( header ) ) || - ! bfd_set_section_contents ( core_bfd, to, &thread_pstatus, - sizeof ( header ), - sizeof ( thread_pstatus ) ) ) + if (!bfd_set_section_contents (core_bfd, to, &header, + 0, + sizeof (header)) || + !bfd_set_section_contents (core_bfd, to, &thread_pstatus, + sizeof (header), + sizeof (thread_pstatus))) { - bfd_perror ( "writing thread info to bfd" ); + bfd_perror ("writing thread info to bfd"); dumper_abort (); return 0; - } ; + }; return 1; } int -dumper::dump_module ( asection* to, process_module* module ) +dumper::dump_module (asection * to, process_module * module) { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - if ( to == NULL || module == NULL ) return 0; + if (to == NULL || module == NULL) + return 0; - struct win32_pstatus* module_pstatus_ptr; + struct win32_pstatus *module_pstatus_ptr; - int note_length = sizeof ( struct win32_pstatus ) + strlen ( module->name ); + int note_length = sizeof (struct win32_pstatus) + strlen (module->name); - char* buf = (char*) malloc ( note_length ); + char *buf = (char *) malloc (note_length); - if ( ! buf ) + if (!buf) { - fprintf ( stderr, "Error alloating memory. Dumping aborted.\n" ); + fprintf (stderr, "Error alloating memory. Dumping aborted.\n"); goto out; - } ; + }; - module_pstatus_ptr = (struct win32_pstatus*) buf; + module_pstatus_ptr = (struct win32_pstatus *) buf; note_header header; - bfd_putl32 ( NOTE_NAME_SIZE, header.elf_note_header.namesz ); - bfd_putl32 ( note_length, header.elf_note_header.descsz ); - bfd_putl32 ( NT_WIN32PSTATUS, header.elf_note_header.type ); - strncpy ( (char*) & header.elf_note_header.name, "win32module", NOTE_NAME_SIZE ); + bfd_putl32 (NOTE_NAME_SIZE, header.elf_note_header.namesz); + bfd_putl32 (note_length, header.elf_note_header.descsz); + bfd_putl32 (NT_WIN32PSTATUS, header.elf_note_header.type); + strncpy ((char *) &header.elf_note_header.name, "win32module", NOTE_NAME_SIZE); module_pstatus_ptr->data_type = NOTE_INFO_MODULE; module_pstatus_ptr->data.module_info.base_address = module->base_address; - module_pstatus_ptr->data.module_info.module_name_size = strlen ( module->name ) + 1; - strcpy ( module_pstatus_ptr->data.module_info.module_name, module->name ); + module_pstatus_ptr->data.module_info.module_name_size = strlen (module->name) + 1; + strcpy (module_pstatus_ptr->data.module_info.module_name, module->name); - if ( ! bfd_set_section_contents ( core_bfd, to, &header, - 0, - sizeof ( header ) ) || - ! bfd_set_section_contents ( core_bfd, to, module_pstatus_ptr, - sizeof ( header ), - note_length ) ) + if (!bfd_set_section_contents (core_bfd, to, &header, + 0, + sizeof (header)) || + !bfd_set_section_contents (core_bfd, to, module_pstatus_ptr, + sizeof (header), + note_length)) { - bfd_perror ( "writing module info to bfd" ); + bfd_perror ("writing module info to bfd"); goto out; }; return 1; out: - if ( buf ) free ( buf ); + if (buf) + free (buf); dumper_abort (); return 0; @@ -447,49 +476,51 @@ out: int dumper::collect_process_information () { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - if ( ! DebugActiveProcess ( pid ) ) + if (!DebugActiveProcess (pid)) { - fprintf ( stderr, "Cannot attach to process #%lu", pid ); + fprintf (stderr, "Cannot attach to process #%lu", pid); return 0; } - char event_name [ sizeof ( "cygwin_error_start_event" ) + 20 ]; - sprintf ( event_name, "cygwin_error_start_event%16lx", pid ); - HANDLE sync_with_debugee = OpenEvent ( EVENT_MODIFY_STATE, FALSE, event_name ); + char event_name[sizeof ("cygwin_error_start_event") + 20]; + sprintf (event_name, "cygwin_error_start_event%16lx", pid); + HANDLE sync_with_debugee = OpenEvent (EVENT_MODIFY_STATE, FALSE, event_name); DEBUG_EVENT current_event; while (1) { - if ( ! WaitForDebugEvent ( ¤t_event, 20000 ) ) return 0; + if (!WaitForDebugEvent (¤t_event, 20000)) + return 0; switch (current_event.dwDebugEventCode) { case CREATE_THREAD_DEBUG_EVENT: - if ( ! add_thread ( current_event.dwThreadId, - current_event.u.CreateThread.hThread ) ) + if (!add_thread (current_event.dwThreadId, + current_event.u.CreateThread.hThread)) goto failed; break; case CREATE_PROCESS_DEBUG_EVENT: - if ( ! add_module ( current_event.u.CreateProcessInfo.lpBaseOfImage ) || - ! add_thread ( current_event.dwThreadId, - current_event.u.CreateProcessInfo.hThread ) ) - goto failed; + if (!add_module (current_event.u.CreateProcessInfo.lpBaseOfImage) || + !add_thread (current_event.dwThreadId, + current_event.u.CreateProcessInfo.hThread)) + goto failed; break; case EXIT_PROCESS_DEBUG_EVENT: - deb_printf ( "debugee quits" ); - ContinueDebugEvent ( current_event.dwProcessId, - current_event.dwThreadId, - DBG_CONTINUE ); + deb_printf ("debugee quits"); + ContinueDebugEvent (current_event.dwProcessId, + current_event.dwThreadId, + DBG_CONTINUE); return 1; @@ -497,31 +528,32 @@ dumper::collect_process_information () case LOAD_DLL_DEBUG_EVENT: - if ( ! add_module ( current_event.u.LoadDll.lpBaseOfDll ) ) - goto failed; + if (!add_module (current_event.u.LoadDll.lpBaseOfDll)) + goto failed; break; case EXCEPTION_DEBUG_EVENT: - collect_memory_sections (); + collect_memory_sections (); - /* got all info. time to dump */ + /* got all info. time to dump */ - if ( ! prepare_core_dump () ) + if (!prepare_core_dump ()) { - fprintf ( stderr, "Failed to prepare core dump\n" ); + fprintf (stderr, "Failed to prepare core dump\n"); goto failed; }; - if ( ! write_core_dump () ) + if (!write_core_dump ()) { - fprintf ( stderr, "Failed to write core dump\n" ); + fprintf (stderr, "Failed to write core dump\n"); goto failed; }; - /* signal a debugee that we've finished */ - if ( sync_with_debugee ) SetEvent ( sync_with_debugee ); + /* signal a debugee that we've finished */ + if (sync_with_debugee) + SetEvent (sync_with_debugee); break; @@ -531,13 +563,14 @@ dumper::collect_process_information () } - ContinueDebugEvent ( current_event.dwProcessId, - current_event.dwThreadId, - DBG_CONTINUE ); + ContinueDebugEvent (current_event.dwProcessId, + current_event.dwThreadId, + DBG_CONTINUE); } failed: /* set debugee free */ - if ( sync_with_debugee ) SetEvent ( sync_with_debugee ); + if (sync_with_debugee) + SetEvent (sync_with_debugee); return 0; } @@ -547,16 +580,16 @@ dumper::init_core_dump () { bfd_init (); - core_bfd = bfd_openw ( file_name, "elf32-i386" ); - if ( core_bfd == NULL ) + core_bfd = bfd_openw (file_name, "elf32-i386"); + if (core_bfd == NULL) { - bfd_perror ( "opening bfd" ); + bfd_perror ("opening bfd"); goto failed; } - if ( ! bfd_set_format ( core_bfd, bfd_core ) ) + if (!bfd_set_format (core_bfd, bfd_core)) { - bfd_perror ( "setting bfd format" ); + bfd_perror ("setting bfd format"); goto failed; } @@ -571,73 +604,74 @@ failed: int dumper::prepare_core_dump () { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; int sect_no = 0; - char sect_name [ 50 ]; + char sect_name[50]; flagword sect_flags; DWORD sect_size; bfd_vma sect_vma; - asection* new_section; + asection *new_section; - for ( process_entity* p = list; p != NULL; p = p->next ) + for (process_entity * p = list; p != NULL; p = p->next) { sect_no++; - switch ( p->type ) - { - case pr_ent_memory: - sprintf ( sect_name, ".mem/%u", sect_no ); - sect_flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD; - sect_size = p->u.memory.size; - sect_vma = (bfd_vma)(p->u.memory.base); + switch (p->type) + { + case pr_ent_memory: + sprintf (sect_name, ".mem/%u", sect_no); + sect_flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD; + sect_size = p->u.memory.size; + sect_vma = (bfd_vma) (p->u.memory.base); - break; - - case pr_ent_thread: - sprintf ( sect_name, ".note/%u", sect_no ); - sect_flags = SEC_HAS_CONTENTS | SEC_LOAD; - sect_size = sizeof ( note_header ) + sizeof ( struct win32_pstatus ); - sect_vma = 0; break; - case pr_ent_module: - sprintf ( sect_name, ".note/%u", sect_no ); - sect_flags = SEC_HAS_CONTENTS | SEC_LOAD; - sect_size = sizeof ( note_header ) + sizeof ( struct win32_pstatus ) + - (bfd_size_type)( strlen (p->u.module.name) ); - sect_vma = 0; - break; + case pr_ent_thread: + sprintf (sect_name, ".note/%u", sect_no); + sect_flags = SEC_HAS_CONTENTS | SEC_LOAD; + sect_size = sizeof (note_header) + sizeof (struct win32_pstatus); + sect_vma = 0; + break; - default: + case pr_ent_module: + sprintf (sect_name, ".note/%u", sect_no); + sect_flags = SEC_HAS_CONTENTS | SEC_LOAD; + sect_size = sizeof (note_header) + sizeof (struct win32_pstatus) + + (bfd_size_type) (strlen (p->u.module.name)); + sect_vma = 0; + break; + + default: continue; - } + } - if ( p->type == pr_ent_module && status_section != NULL ) - { - if ( ! bfd_set_section_size ( core_bfd, - status_section, - status_section->_raw_size + sect_size ) ) + if (p->type == pr_ent_module && status_section != NULL) + { + if (!bfd_set_section_size (core_bfd, + status_section, + status_section->_raw_size + sect_size)) { - bfd_perror ( "resizing status section" ); + bfd_perror ("resizing status section"); goto failed; }; - continue; - } + continue; + } - deb_printf ( "creating section (type%u) %s(%u), flags=%08x\n", - p->type, sect_name, sect_size, sect_flags ); + deb_printf ("creating section (type%u) %s(%u), flags=%08x\n", + p->type, sect_name, sect_size, sect_flags); - char* buf = strdup ( sect_name ); - new_section = bfd_make_section ( core_bfd, buf ); + char *buf = strdup (sect_name); + new_section = bfd_make_section (core_bfd, buf); - if ( new_section == NULL || - ! bfd_set_section_flags ( core_bfd, new_section, sect_flags ) || - ! bfd_set_section_size ( core_bfd, new_section, sect_size ) ) + if (new_section == NULL || + !bfd_set_section_flags (core_bfd, new_section, sect_flags) || + !bfd_set_section_size (core_bfd, new_section, sect_size)) { - bfd_perror ( "creating section" ); + bfd_perror ("creating section"); goto failed; }; @@ -657,36 +691,38 @@ failed: int dumper::write_core_dump () { - if ( ! sane () ) return 0; + if (!sane ()) + return 0; - for ( process_entity* p = list; p != NULL; p = p->next ) + for (process_entity * p = list; p != NULL; p = p->next) { - if ( p->section == NULL ) continue; + if (p->section == NULL) + continue; - deb_printf ( "writing section type=%u base=%08x size=%08x flags=%08x\n", - p->type, - p->section->vma, - p->section->_raw_size, - p->section->flags ); + deb_printf ("writing section type=%u base=%08x size=%08x flags=%08x\n", + p->type, + p->section->vma, + p->section->_raw_size, + p->section->flags); - switch ( p->type ) - { - case pr_ent_memory: - dump_memory_region ( p->section, &(p->u.memory) ); - break; - - case pr_ent_thread: - dump_thread ( p->section, &(p->u.thread) ); + switch (p->type) + { + case pr_ent_memory: + dump_memory_region (p->section, &(p->u.memory)); break; - case pr_ent_module: - dump_module ( p->section, &(p->u.module) ); - break; + case pr_ent_thread: + dump_thread (p->section, &(p->u.thread)); + break; - default: + case pr_ent_module: + dump_module (p->section, &(p->u.module)); + break; + + default: continue; - } + } } return 1; } @@ -694,17 +730,17 @@ dumper::write_core_dump () static void usage () { - fprintf ( stderr, "Usage: dumper [-v] [-c filename] pid\n" ); - fprintf ( stderr, "-c filename -- dump core to filename.core\n" ); - fprintf ( stderr, "-d -- print some debugging info while dumping\n" ); - fprintf ( stderr, "pid -- win32-pid of process to dump\n" ); + fprintf (stderr, "Usage: dumper [-v] [-c filename] pid\n"); + fprintf (stderr, "-c filename -- dump core to filename.core\n"); + fprintf (stderr, "-d -- print some debugging info while dumping\n"); + fprintf (stderr, "pid -- win32-pid of process to dump\n"); } int -main( int argc, char** argv ) +main (int argc, char **argv) { int opt; - char* p = ""; + char *p = ""; DWORD pid; while ((opt = getopt (argc, argv, "dc:")) != EOF) @@ -714,25 +750,25 @@ main( int argc, char** argv ) verbose = TRUE; break; case 'c': - char win32_name [ MAX_PATH ]; - cygwin_conv_to_win32_path ( optarg, win32_name ); - if ( ( p = strrchr ( win32_name, '\\' ) ) ) + char win32_name[MAX_PATH]; + cygwin_conv_to_win32_path (optarg, win32_name); + if ((p = strrchr (win32_name, '\\'))) p++; else p = win32_name; break; } - char* core_file = (char*) malloc ( strlen ( p ) + sizeof ( ".core" ) ); - if ( ! core_file ) + char *core_file = (char *) malloc (strlen (p) + sizeof (".core")); + if (!core_file) { - fprintf ( stderr, "error allocating memory\n" ); + fprintf (stderr, "error allocating memory\n"); return -1; } - sprintf ( core_file, "%s.core", p ); + sprintf (core_file, "%s.core", p); - if ( argv && *(argv+optind) ) - pid = atoi ( *(argv+optind) ); + if (argv && *(argv + optind)) + pid = atoi (*(argv + optind)); else { usage (); @@ -741,14 +777,14 @@ main( int argc, char** argv ) DWORD tid = 0; - if ( verbose ) - printf ( "dumping process #%lu to %s\n", pid, core_file ); + if (verbose) + printf ("dumping process #%lu to %s\n", pid, core_file); - dumper d ( pid, tid, core_file ); - if ( ! d.sane () ) + dumper d (pid, tid, core_file); + if (!d.sane ()) return -1; d.collect_process_information (); - free ( core_file ); + free (core_file); return 0; }; diff --git a/winsup/utils/getfacl.c b/winsup/utils/getfacl.c index 9bf7122db..482bc0c7b 100644 --- a/winsup/utils/getfacl.c +++ b/winsup/utils/getfacl.c @@ -8,7 +8,8 @@ #include #include -char *permstr (mode_t perm) +char * +permstr (mode_t perm) { static char pbuf[4]; @@ -20,7 +21,8 @@ char *permstr (mode_t perm) } #if 0 -char *username (uid_t uid) +char * +username (uid_t uid) { static char ubuf[256]; struct passwd *pw; @@ -31,7 +33,8 @@ char *username (uid_t uid) strcpy (ubuf, ""); } -char *groupname (gid_t gid) +char * +groupname (gid_t gid) { static char gbuf[256]; struct group *gr; @@ -58,67 +61,66 @@ main (int argc, char **argv) switch (c) { case 'a': - aopt = 1; - break; + aopt = 1; + break; case 'd': - dopt = 1; - break; + dopt = 1; + break; default: - fprintf (stderr, "usage: %s [-ad] file...\n", argv[0]); - return 1; + fprintf (stderr, "usage: %s [-ad] file...\n", argv[0]); + return 1; } while ((c = optind++) < argc) { if (stat (argv[c], &st)) - { - perror (argv[0]); - continue; - } - if (! first) - putchar ('\n'); + { + perror (argv[0]); + continue; + } + if (!first) + putchar ('\n'); first = 0; printf ("# file: %s\n", argv[c]); printf ("# owner: %d\n", st.st_uid); printf ("# group: %d\n", st.st_gid); if ((c = acl (argv[c], GETACL, MAX_ACL_ENTRIES, acls)) < 0) - { - perror (argv[0]); - continue; - } + { + perror (argv[0]); + continue; + } for (i = 0; i < c; ++i) - { - if (acls[i].a_type & ACL_DEFAULT) - { - if (aopt) - continue; - printf ("default:"); - } - else if (dopt) - continue; - switch (acls[i].a_type & ~ACL_DEFAULT) - { - case USER_OBJ: - printf ("user::"); - break; - case USER: - printf ("user:%d:", acls[i].a_id); - break; - case GROUP_OBJ: - printf ("group::"); - break; - case GROUP: - printf ("group:%d:", acls[i].a_id); - break; - case CLASS_OBJ: - printf ("mask::"); - break; - case OTHER_OBJ: - printf ("other::"); - break; - } - printf ("%s\n", permstr (acls[i].a_perm)); - } + { + if (acls[i].a_type & ACL_DEFAULT) + { + if (aopt) + continue; + printf ("default:"); + } + else if (dopt) + continue; + switch (acls[i].a_type & ~ACL_DEFAULT) + { + case USER_OBJ: + printf ("user::"); + break; + case USER: + printf ("user:%d:", acls[i].a_id); + break; + case GROUP_OBJ: + printf ("group::"); + break; + case GROUP: + printf ("group:%d:", acls[i].a_id); + break; + case CLASS_OBJ: + printf ("mask::"); + break; + case OTHER_OBJ: + printf ("other::"); + break; + } + printf ("%s\n", permstr (acls[i].a_perm)); + } } return 0; } - diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c index 91c7cb294..2f32206a9 100644 --- a/winsup/utils/mkpasswd.c +++ b/winsup/utils/mkpasswd.c @@ -42,7 +42,7 @@ put_sid (PSID sid) return s; } -void +void psx_dir (char *in, char *out) { if (isalpha (in[0]) && in[1] == ':') @@ -65,7 +65,7 @@ psx_dir (char *in, char *out) *out = '\0'; } -void +void uni2ansi (LPWSTR wcs, char *mbs) { if (wcs) @@ -75,7 +75,7 @@ uni2ansi (LPWSTR wcs, char *mbs) *mbs = '\0'; } -int +int enum_users (LPWSTR servername, int print_sids, int print_cygpath) { USER_INFO_3 *buffer; @@ -191,7 +191,7 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath) return 0; } -int +int enum_local_groups (int print_sids) { LOCALGROUP_INFO_0 *buffer; @@ -277,7 +277,7 @@ enum_local_groups (int print_sids) return 0; } -void +void usage () { fprintf (stderr, "\n"); @@ -296,7 +296,7 @@ usage () exit (1); } -int +int main (int argc, char **argv) { LPWSTR servername = NULL; diff --git a/winsup/utils/module_info.cc b/winsup/utils/module_info.cc index a48d7105c..249f089d6 100644 --- a/winsup/utils/module_info.cc +++ b/winsup/utils/module_info.cc @@ -17,94 +17,96 @@ details. */ static int psapi_loaded = 0; static HMODULE psapi_module_handle = NULL; -typedef BOOL WINAPI (tf_EnumProcessModules ) ( HANDLE, HMODULE*, DWORD, LPDWORD ); -typedef BOOL WINAPI (tf_GetModuleInformation) ( HANDLE, HMODULE, LPMODULEINFO, DWORD ); -typedef DWORD WINAPI (tf_GetModuleFileNameExA) ( HANDLE, HMODULE, LPSTR, DWORD ); +typedef BOOL WINAPI (tf_EnumProcessModules) (HANDLE, HMODULE *, DWORD, + LPDWORD); +typedef BOOL WINAPI (tf_GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, + DWORD); +typedef DWORD WINAPI (tf_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, + DWORD); static tf_EnumProcessModules *psapi_EnumProcessModules = NULL; static tf_GetModuleInformation *psapi_GetModuleInformation = NULL; static tf_GetModuleFileNameExA *psapi_GetModuleFileNameExA = NULL; -/* - * Returns full name of Dll, which is loaded by hProcess at BaseAddress - * Uses psapi.dll - */ +/* Returns full name of Dll, which is loaded by hProcess at BaseAddress. + Uses psapi.dll. */ -char* -psapi_get_module_name ( HANDLE hProcess, DWORD BaseAddress ) +char * +psapi_get_module_name (HANDLE hProcess, DWORD BaseAddress) { DWORD len; MODULEINFO mi; unsigned int i; - HMODULE dh_buf [ 1 ]; - HMODULE* DllHandle = dh_buf; + HMODULE dh_buf[1]; + HMODULE *DllHandle = dh_buf; DWORD cbNeeded; BOOL ok; - char name_buf [ MAX_PATH + 1 ]; + char name_buf[MAX_PATH + 1]; - if ( !psapi_loaded || - psapi_EnumProcessModules == NULL || - psapi_GetModuleInformation == NULL || - psapi_GetModuleFileNameExA == NULL ) + if (!psapi_loaded || + psapi_EnumProcessModules == NULL || + psapi_GetModuleInformation == NULL || + psapi_GetModuleFileNameExA == NULL) { - if ( psapi_loaded ) goto failed; + if (psapi_loaded) + goto failed; psapi_loaded = 1; - psapi_module_handle = LoadLibrary ( "psapi.dll" ); - if ( ! psapi_module_handle ) - goto failed; - psapi_EnumProcessModules = (tf_EnumProcessModules *) GetProcAddress ( psapi_module_handle, "EnumProcessModules" ); - psapi_GetModuleInformation = (tf_GetModuleInformation *) GetProcAddress ( psapi_module_handle, "GetModuleInformation" ); - psapi_GetModuleFileNameExA = (tf_GetModuleFileNameExA*) GetProcAddress ( psapi_module_handle, "GetModuleFileNameExA" ); - if ( psapi_EnumProcessModules == NULL || - psapi_GetModuleInformation == NULL || - psapi_GetModuleFileNameExA == NULL ) goto failed; + psapi_module_handle = LoadLibrary ("psapi.dll"); + if (!psapi_module_handle) + goto failed; + psapi_EnumProcessModules = + (tf_EnumProcessModules *) GetProcAddress (psapi_module_handle, + "EnumProcessModules"); + psapi_GetModuleInformation = + (tf_GetModuleInformation *) GetProcAddress (psapi_module_handle, + "GetModuleInformation"); + psapi_GetModuleFileNameExA = + (tf_GetModuleFileNameExA *) GetProcAddress (psapi_module_handle, + "GetModuleFileNameExA"); + if (psapi_EnumProcessModules == NULL + || psapi_GetModuleInformation == NULL + || psapi_GetModuleFileNameExA == NULL) + goto failed; } - ok = (*psapi_EnumProcessModules) ( hProcess, - DllHandle, - sizeof ( HMODULE ), - &cbNeeded ); + ok = (*psapi_EnumProcessModules) (hProcess, + DllHandle, sizeof (HMODULE), &cbNeeded); - if ( !ok || !cbNeeded ) goto failed; - DllHandle = (HMODULE*) malloc ( cbNeeded ); - if ( ! DllHandle ) goto failed; - ok = (*psapi_EnumProcessModules) ( hProcess, - DllHandle, - cbNeeded, - &cbNeeded ); - if ( ! ok ) + if (!ok || !cbNeeded) + goto failed; + DllHandle = (HMODULE *) malloc (cbNeeded); + if (!DllHandle) + goto failed; + ok = (*psapi_EnumProcessModules) (hProcess, DllHandle, cbNeeded, &cbNeeded); + if (!ok) { - free ( DllHandle ); + free (DllHandle); goto failed; } - for ( i = 0; i < cbNeeded / sizeof ( HMODULE ); i++ ) + for (i = 0; i < cbNeeded / sizeof (HMODULE); i++) { - if ( ! (*psapi_GetModuleInformation) ( hProcess, - DllHandle [ i ], - &mi, - sizeof ( mi ) ) ) - { - free ( DllHandle ); - goto failed; - } + if (!(*psapi_GetModuleInformation) (hProcess, + DllHandle[i], &mi, sizeof (mi))) + { + free (DllHandle); + goto failed; + } - len = (*psapi_GetModuleFileNameExA) ( hProcess, - DllHandle [ i ], - name_buf, - MAX_PATH ); - if ( len == 0 ) - { - free ( DllHandle ); - goto failed; - } + len = (*psapi_GetModuleFileNameExA) (hProcess, + DllHandle[i], name_buf, MAX_PATH); + if (len == 0) + { + free (DllHandle); + goto failed; + } - if ( (DWORD) (mi.lpBaseOfDll) == BaseAddress ) - { - free ( DllHandle ); - return strdup ( name_buf ); - } + if ((DWORD) (mi.lpBaseOfDll) == BaseAddress) + { + free (DllHandle); + return strdup (name_buf); + } } failed: diff --git a/winsup/utils/mount.cc b/winsup/utils/mount.cc index 2d1125f91..bf86d02fc 100644 --- a/winsup/utils/mount.cc +++ b/winsup/utils/mount.cc @@ -79,7 +79,7 @@ do_mount (const char *dev, const char *where, int flags) { if (force == FALSE) fprintf (stderr, "%s: warning: %s is not a directory.\n", progname, where); - } + } exit (0); } @@ -167,7 +167,7 @@ main (int argc, const char **argv) else usage (); } - + if ((i + 2) != argc) usage (); @@ -259,7 +259,7 @@ change_cygdrive_prefix (const char *new_prefix, int flags) if (mount (NULL, new_prefix, flags)) error (new_prefix); - + exit (0); } diff --git a/winsup/utils/parse_pe.cc b/winsup/utils/parse_pe.cc index 00aeb5502..b43957279 100644 --- a/winsup/utils/parse_pe.cc +++ b/winsup/utils/parse_pe.cc @@ -4,11 +4,11 @@ Written by Egor Duda -This file is part of Cygwin. + This file is part of Cygwin. -This software is a copyrighted work licensed under the terms of the -Cygwin license. Please consult the file "CYGWIN_LICENSE" for -details. */ + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ #include #include @@ -17,22 +17,25 @@ details. */ #include "dumper.h" int -exclusion::add ( LPBYTE mem_base, DWORD mem_size ) +exclusion::add (LPBYTE mem_base, DWORD mem_size) { - while ( last >= size ) size += step; - region = (process_mem_region*) realloc ( region, size * sizeof ( process_mem_region ) ); - if ( region == NULL ) return 0; - region [ last ].base = mem_base; - region [ last ].size = mem_size; + while (last >= size) + size += step; + region = (process_mem_region *) realloc (region, size * sizeof (process_mem_region)); + if (region == NULL) + return 0; + region[last].base = mem_base; + region[last].size = mem_size; last++; return 1; }; -int cmp_regions ( const void* r1, const void* r2 ) +int +cmp_regions (const void *r1, const void *r2) { - if ( ((process_mem_region*) r1)->base < ((process_mem_region*) r2)->base ) + if (((process_mem_region *) r1)->base < ((process_mem_region *) r2)->base) return -1; - if ( ((process_mem_region*) r1)->base > ((process_mem_region*) r2)->base ) + if (((process_mem_region *) r1)->base > ((process_mem_region *) r2)->base) return 1; return 0; } @@ -40,49 +43,49 @@ int cmp_regions ( const void* r1, const void* r2 ) int exclusion::sort_and_check () { - qsort ( region, last, sizeof ( process_mem_region ), &cmp_regions ); - for ( process_mem_region* p = region; p < region + last - 1; p++ ) + qsort (region, last, sizeof (process_mem_region), &cmp_regions); + for (process_mem_region * p = region; p < region + last - 1; p++) { - process_mem_region* q = p + 1; - if ( p->base + size > q->base ) - { - fprintf ( stderr, "region error @ %08x", p->base ); - return 0; - } + process_mem_region *q = p + 1; + if (p->base + size > q->base) + { + fprintf (stderr, "region error @ %08x", p->base); + return 0; + } } return 1; } static void -select_data_section ( bfd *abfd, asection *sect, PTR obj ) +select_data_section (bfd * abfd, asection * sect, PTR obj) { - exclusion* excl_list = (exclusion*) obj; + exclusion *excl_list = (exclusion *) obj; - if ( ( sect->flags & ( SEC_CODE | SEC_DEBUGGING ) ) && - sect->vma && sect->_raw_size ) + if ((sect->flags & (SEC_CODE | SEC_DEBUGGING)) && + sect->vma && sect->_raw_size) { - excl_list->add ( (LPBYTE)sect->vma, (DWORD)sect->_raw_size ); - deb_printf ( "excluding section: %20s %08lx\n", sect->name, sect->_raw_size); + excl_list->add ((LPBYTE) sect->vma, (DWORD) sect->_raw_size); + deb_printf ("excluding section: %20s %08lx\n", sect->name, sect->_raw_size); } } int -parse_pe ( const char* file_name, exclusion* excl_list ) +parse_pe (const char *file_name, exclusion * excl_list) { - if ( file_name == NULL || excl_list == NULL ) return 0; + if (file_name == NULL || excl_list == NULL) + return 0; - bfd* abfd = bfd_openr ( file_name, "pei-i386" ); - if ( abfd == NULL ) + bfd *abfd = bfd_openr (file_name, "pei-i386"); + if (abfd == NULL) { - bfd_perror ( "failed to open file" ); + bfd_perror ("failed to open file"); return 0; } - bfd_check_format ( abfd, bfd_object ); - bfd_map_over_sections ( abfd, &select_data_section, (PTR)excl_list ); + bfd_check_format (abfd, bfd_object); + bfd_map_over_sections (abfd, &select_data_section, (PTR) excl_list); excl_list->sort_and_check (); - bfd_close ( abfd ); + bfd_close (abfd); return 1; } - diff --git a/winsup/utils/ssp.c b/winsup/utils/ssp.c index 114ff3a57..1abde5394 100644 --- a/winsup/utils/ssp.c +++ b/winsup/utils/ssp.c @@ -498,7 +498,7 @@ run_program (char *cmdline) if (++qq % 100 == 0) fprintf (stderr, " %08x %d %d \r", pc, ncalls, opcode_count); - + if (sp == last_sp-4) { ncalls++; @@ -598,7 +598,7 @@ run_program (char *cmdline) if (verbose) printf ("load dll %08x:", (int)event.u.LoadDll.lpBaseOfDll); - + dll_ptr = (char *)"( u n k n o w n ) \0\0"; if (event.u.LoadDll.lpImageName) { diff --git a/winsup/utils/ssp.txt b/winsup/utils/ssp.txt index 513767f45..e73880e90 100644 --- a/winsup/utils/ssp.txt +++ b/winsup/utils/ssp.txt @@ -19,7 +19,7 @@ section. Let's say we're profiling cygwin1.dll. Make sure you've built it with debug symbols (else gprof won't run) and run objdump like this: - objdump -h cygwin1.dll + objdump -h cygwin1.dll It will print a report like this: @@ -63,8 +63,8 @@ the first part of the report reports the amount of time spent in each function, like this: Each sample counts as 0.01 seconds. - % cumulative self self total - time seconds seconds calls ms/call ms/call name + % cumulative self self total + time seconds seconds calls ms/call ms/call name 10.02 231.22 72.43 46 1574.57 1574.57 strcspn 7.95 288.70 57.48 130 442.15 442.15 strncasematch diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc index 334a148d5..b9eb82a77 100644 --- a/winsup/utils/strace.cc +++ b/winsup/utils/strace.cc @@ -30,17 +30,19 @@ static BOOL close_handle (HANDLE h, DWORD ok); #define CloseHandle(h) close_handle(h, 0) struct child_list +{ + DWORD id; + HANDLE hproc; + int saw_stars; + char nfields; + long long start_time; + DWORD last_usecs; + struct child_list *next; + child_list ():id (0), hproc (NULL), saw_stars (0), nfields (0), + start_time (0), last_usecs (0), next (NULL) { - DWORD id; - HANDLE hproc; - int saw_stars; - char nfields; - long long start_time; - DWORD last_usecs; - struct child_list *next; - child_list () : id (0), hproc (NULL), saw_stars (0), nfields (0), - start_time (0), last_usecs (0), next (NULL) {} - }; + } +}; child_list children; @@ -85,7 +87,7 @@ DWORD lastid = 0; HANDLE lasth; #define PROCFLAGS \ - PROCESS_ALL_ACCESS /*(PROCESS_DUP_HANDLE | PROCESS_TERMINATE | PROCESS_VM_READ | PROCESS_VM_WRITE)*/ + PROCESS_ALL_ACCESS /*(PROCESS_DUP_HANDLE | PROCESS_TERMINATE | PROCESS_VM_READ | PROCESS_VM_WRITE) */ static void add_child (DWORD id, HANDLE hproc) { @@ -101,7 +103,7 @@ static child_list * get_child (DWORD id) { child_list *c; - for (c = &children; (c = c->next) != NULL; ) + for (c = &children; (c = c->next) != NULL;) if (c->id == id) return c; @@ -132,7 +134,7 @@ class linebuf { size_t alloc; public: - size_t ix; + size_t ix; char *buf; linebuf () { @@ -140,9 +142,16 @@ public: alloc = 0; buf = NULL; } - ~linebuf () {if (buf) free (buf);} + ~linebuf () + { + if (buf) + free (buf); + } void add (const char *what, int len); - void add (const char *what) {add (what, strlen (what));} + void add (const char *what) + { + add (what, strlen (what)); + } void prepend (const char *what, int len); }; @@ -172,15 +181,15 @@ linebuf::prepend (const char *what, int len) buf[ix] = '\0'; } if ((buflen = strlen (buf))) - memmove (buf + len, buf, buflen + 1); + memmove (buf + len, buf, buflen + 1); else - buf[newix] = '\0'; + buf[newix] = '\0'; memcpy (buf, what, len); ix = newix; } static void -make_command_line (linebuf& one_line, char **argv) +make_command_line (linebuf & one_line, char **argv) { for (; *argv; argv++) { @@ -240,26 +249,25 @@ create_child (char **argv) memset (&si, 0, sizeof (si)); si.cb = sizeof (si); - /* cygwin32_conv_to_win32_path (exec_file, real_path);*/ + /* cygwin32_conv_to_win32_path (exec_file, real_path); */ flags = forkdebug ? 0 : DEBUG_ONLY_THIS_PROCESS; - flags |= /*CREATE_NEW_PROCESS_GROUP | */CREATE_DEFAULT_ERROR_MODE | DEBUG_PROCESS; + flags |= + /*CREATE_NEW_PROCESS_GROUP | */ CREATE_DEFAULT_ERROR_MODE | DEBUG_PROCESS; make_command_line (one_line, argv); SetConsoleCtrlHandler (NULL, 0); - ret = CreateProcess (0, - one_line.buf,/* command line */ + ret = CreateProcess (0, one_line.buf, /* command line */ NULL, /* Security */ NULL, /* thread */ TRUE, /* inherit handles */ flags, /* start flags */ - NULL, - NULL, /* current directory */ - &si, - &pi); + NULL, NULL, /* current directory */ + &si, &pi); if (!ret) - error (0, "error creating process %s, (error %d)", *argv, GetLastError()); + error (0, "error creating process %s, (error %d)", *argv, + GetLastError ()); CloseHandle (pi.hThread); CloseHandle (pi.hProcess); @@ -294,9 +302,7 @@ output_winerror (FILE *ofile, char *s) NULL, errnum, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) buf, - sizeof (buf), - NULL)) + (LPTSTR) buf, sizeof (buf), NULL)) return 0; /* Get rid the trailing CR/NL pair. */ @@ -331,7 +337,7 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) DWORD nbytes; child_list *child = get_child (id); HANDLE hchild = child->hproc; - #define INTROLEN (sizeof (alen) - 1) +#define INTROLEN (sizeof (alen) - 1) if (id == lastid && hchild != lasth) warn (0, "%p != %p", hchild, lasth); @@ -341,7 +347,8 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) #ifndef DEBUGGING return; #else - error (0, "couldn't get message length from subprocess %d<%p>, windows error %d", + error (0, + "couldn't get message length from subprocess %d<%p>, windows error %d", id, hchild, GetLastError ()); #endif @@ -378,8 +385,9 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) { DWORD new_flag = 1; if (!WriteProcessMemory (hchild, (LPVOID) n, &new_flag, - sizeof (new_flag), &nbytes)) - error (0, "couldn't write strace flag to subprocess, windows error %d", + sizeof (new_flag), &nbytes)) + error (0, + "couldn't write strace flag to subprocess, windows error %d", GetLastError ()); return; } @@ -387,9 +395,9 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) char *origs = s; if (mask & n) - /* got it */; + /* got it */ ; else if (!(mask & _STRACE_ALL) || (n & _STRACE_NOTALL)) - return; /* This should not be included in "all" output */ + return; /* This should not be included in "all" output */ DWORD dusecs, usecs; char *ptusec, *ptrest; @@ -447,7 +455,7 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) { for (i = 0; i < child->nfields; i++) if ((news = strchr (news, ' ')) == NULL) - break; // Should never happen + break; // Should never happen else news++; @@ -459,8 +467,10 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) if (*s == '*') { SYSTEMTIME *st = syst (child->start_time); - fprintf (ofile, "Date/Time: %d-%02d-%02d %02d:%02d:%02d\n", - st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond); + fprintf (ofile, + "Date/Time: %d-%02d-%02d %02d:%02d:%02d\n", + st->wYear, st->wMonth, st->wDay, st->wHour, + st->wMinute, st->wSecond); child->saw_stars++; } } @@ -471,7 +481,7 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) char intbuf[40]; if (child->saw_stars < 2 || s != origs) - /* Nothing */; + /* Nothing */ ; else if (hhmmss) { s = ptrest - 9; @@ -537,7 +547,8 @@ proc_child (unsigned mask, FILE *ofile) remove_child (ev.dwProcessId); break; case EXCEPTION_DEBUG_EVENT: - if (ev.u.Exception.ExceptionRecord.ExceptionCode != STATUS_BREAKPOINT) + if (ev.u.Exception.ExceptionRecord.ExceptionCode != + STATUS_BREAKPOINT) { status = DBG_EXCEPTION_NOT_HANDLED; #if 0 @@ -566,7 +577,7 @@ dostrace (unsigned mask, FILE *ofile, char **argv) } int -main(int argc, char **argv) +main (int argc, char **argv) { unsigned mask = 0; FILE *ofile = NULL; @@ -627,7 +638,7 @@ static BOOL close_handle (HANDLE h, DWORD ok) { child_list *c; - for (c = &children; (c = c->next) != NULL; ) + for (c = &children; (c = c->next) != NULL;) if (c->hproc == h && c->id != ok) error (0, "Closing child handle %p", h); return CloseHandle (h); diff --git a/winsup/utils/umount.cc b/winsup/utils/umount.cc index d79aaca33..3c1e5f35f 100644 --- a/winsup/utils/umount.cc +++ b/winsup/utils/umount.cc @@ -27,13 +27,18 @@ static void usage (void) { fprintf (stderr, "Usage %s [-s] \n", progname); - fprintf (stderr, "-s = remove mount point from system-wide registry location\n"); + fprintf (stderr, + "-s = remove mount point from system-wide registry location\n"); fprintf (stderr, "\n"); fprintf (stderr, "--remove-all-mounts = remove all mounts\n"); - fprintf (stderr, "--remove-auto-mounts = remove all automatically mounted mounts\n"); - fprintf (stderr, "--remove-user-mounts = remove all mounts in the current user mount registry area, including auto mounts\n"); - fprintf (stderr, "--remove-system-mounts = remove all mounts in the system-wide mount registry area\n"); - fprintf (stderr, "[-s] --remove-cygdrive-prefix = remove cygdrive path prefix\n"); + fprintf (stderr, + "--remove-auto-mounts = remove all automatically mounted mounts\n"); + fprintf (stderr, + "--remove-user-mounts = remove all mounts in the current user mount registry area, including auto mounts\n"); + fprintf (stderr, + "--remove-system-mounts = remove all mounts in the system-wide mount registry area\n"); + fprintf (stderr, + "[-s] --remove-cygdrive-prefix = remove cygdrive path prefix\n"); exit (1); } @@ -57,7 +62,7 @@ main (int argc, char **argv) for (i = 1; i < argc; ++i) { if (argv[i][0] != '-') - break; + break; if (strcmp (argv[i], "-s") == 0) { @@ -194,7 +199,7 @@ remove_all_system_mounts () static void remove_cygdrive_prefix (int flags) { - int res = cygwin_umount(NULL, flags | MOUNT_AUTO); + int res = cygwin_umount (NULL, flags | MOUNT_AUTO); if (res) error ("remove_cygdrive_prefix"); } diff --git a/winsup/utils/utils.sgml b/winsup/utils/utils.sgml index fbf6686ce..6eadafe43 100644 --- a/winsup/utils/utils.sgml +++ b/winsup/utils/utils.sgml @@ -269,7 +269,7 @@ local machine or the default (or given) domain. Usage passwd [name] - passwd [-x max] [-n min] [-i inact] [-L len] + passwd [-x max] [-n min] [-i inact] [-L len] passwd {-l|-u|-S} name -x max set max age of passwords -n min set min age of passwords @@ -303,12 +303,12 @@ at this time. If not, passwd refuses to change the password and exits. Password expiry and length: The password aging information may be -changed by the administrators with the -x, --n and -i options. The +changed by the administrators with the -x, +-n and -i options. The -x option is used to set the maximum number of days a password remains valid. After max days, the password is required to be changed. The -n option is -used to set the minimum number of days before a password may be changed. +used to set the minimum number of days before a password may be changed. The user will not be permitted to change the password until min days have elapsed. The -i option is used to disable an account after the password has been expired @@ -321,8 +321,8 @@ for users, which doesn't belong to the administrators group, to password length are 0 to 14. In any of the above cases, a value of 0 means `no restrictions'. -Account maintenance: User accounts may be locked and unlocked with the --l and -u flags. The +Account maintenance: User accounts may be locked and unlocked with the +-l and -u flags. The -l option disables an account. The -u option re-enables an account. @@ -383,9 +383,9 @@ to the current user. The mount utility is also the mechanism for adding new mounts to the mount table. The following example -demonstrates how to mount the directory +demonstrates how to mount the directory C:\cygnus\cygwin-b20\H-i586-cygwin32\bin -to /bin and the network directory +to /bin and the network directory \\pollux\home\joe\data to /data. /bin is assumed to already exist. @@ -423,7 +423,7 @@ instead of the user-specific one. System-wide mounts are displayed by mount as being of the "system" type, as is the case for the / partition in the last example. Under Windows NT, only those users with Administrator priviledges are -permitted to modify the system-wide mount table. +permitted to modify the system-wide mount table. Note that a given POSIX path may only exist once in the user table and once in the global, system-wide table. Attempts to replace