#include <u.h>
#include <libc.h>
#define NODEFINE
#include <9pm/u.h>
#include <9pm/libc.h>
#include <9pm/ns.h>

static void (*pm_notifyf)(void*, char*);

static void
pm_notifier(void *a, char *b)
{
	Proc *p;

	p = pm_getproc();
	/* save and clear error stack */
	memmove(p->sigerrjmp, p->errjmp, sizeof p->sigerrjmp);
	p->nsigerrjmp = p->nerrjmp;
	p->nerrjmp = 0;
	if(pm_notifyf)
		pm_notifyf(a, b);
	else
		pm_noted(NDFLT);
}

int
pm_notify(void (*f)(void*, char*))
{
	pm_notifyf = f;
	return notify(pm_notifier);
}
