Re: enhancing Force Quit or improving user-driven diagnostics

John Hawkinson <jhawk-DPNOqEs/[email protected]> Mon, 16 Jan 2012 16:56:53 -0500
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
--mpb+VUhBqKoEsre9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Thanks for the inspiration, Kevin.

> (Certainly a solution that works for all apps is more along the lines
> of what I am looking for than a solution that works for just one. But
> I suppose an LD_PRELOAD -- err, I mean DYLD_INSERT_LIBRARIES -- of a
> signal handler is a possibility if the more general solution doesn't
> pan out).

Actually, an easier answer is to interpose loginwindow's call to kill(),
because it doesn't seem to call kill() very often.
As a first cut, the attached seems to work. Tested under 10.6.8.

I vaguely wonder how hard it would be to add a button next to Force
Quit (easy: just edit the nib), wired up the same way, and then have
the interposition handler determine which button was pressed (I really
have no idea on that one).

In this implementation, loginwindow sends SIGTERM which gets converted
to SIGABRT, and then since writing core dumps takes awhile, it sends
a SIGKILL as well. But that's OK, because once the kernel has started
writing the core dump, SIGKILL does no harm.

[email protected]
  John Hawkinson

--mpb+VUhBqKoEsre9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="forceabrt.c"

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

typedef struct interpose_s
{
  void *new_func;
  void *orig_func;
} interpose_t;

int kill_abrt(pid_t pid, int sig);

static const interpose_t interposers[]
__attribute__ ((section("__DATA, __interpose"))) = 
{
  { (void *)kill_abrt,  (void *)kill  },
};

int kill_abrt(pid_t pid, int sig) {
  fprintf(stderr, "Interposing kill(%d, %d)\n", pid, sig);
  if (sig==SIGTERM) {
    sig = SIGABRT;
    fprintf(stderr, "  -> Converting SIGTERM to SIGABRT\n");
  }
  return kill(pid, sig);
}

--mpb+VUhBqKoEsre9
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
MacOSX-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-dev

--mpb+VUhBqKoEsre9--