//doors/serverintr4.c
#include	"unpipc.h"

void
servproc_cleanup(void *arg)
{
	printf("servproc cancelled, thread id %ld\n", pr_thread_id(NULL));
}

void
servproc(void *cookie, char *dataptr, size_t datasize,
		 door_desc_t *descptr, size_t ndesc)
{
	int		oldstate, junk;
	long	arg, result;
	
	Pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
	pthread_cleanup_push(servproc_cleanup, NULL);
	sleep(6);
	arg = *((long *) dataptr);
	result = arg * arg;
	pthread_cleanup_pop(0);
	Pthread_setcancelstate(oldstate, &junk);
	Door_return((char *) &result, sizeof(result), NULL, 0);
}
