SCDNotifierInformViaSignal.c [plain text]
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <SystemConfiguration/SCD.h>
#include "config.h"
#include "SCDPrivate.h"
SCDStatus
SCDNotifierInformViaSignal(SCDSessionRef session, pid_t pid, int sig)
{
SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)session;
kern_return_t status;
SCDStatus scd_status;
task_t task;
SCDLog(LOG_DEBUG, CFSTR("SCDNotifierInformViaSignal:"));
SCDLog(LOG_DEBUG, CFSTR(" pid = %d"), pid);
SCDLog(LOG_DEBUG, CFSTR(" sig = %d"), sig);
if ((session == NULL) || (sessionPrivate->server == MACH_PORT_NULL)) {
return SCD_NOSESSION;
}
if (SCDOptionGet(NULL, kSCDOptionIsServer)) {
return SCD_FAILED;
}
if (sessionPrivate->notifyStatus != NotifierNotRegistered) {
return SCD_NOTIFIERACTIVE;
}
if ((sig <= 0) || (sig > NSIG)) {
return SCD_INVALIDARGUMENT;
}
status = task_for_pid(mach_task_self(), pid, &task);
if (status != KERN_SUCCESS) {
SCDLog(LOG_DEBUG, CFSTR("task_for_pid(): %s"), mach_error_string(status));
return SCD_FAILED;
}
status = notifyviasignal(sessionPrivate->server, task, sig, (int *)&scd_status);
if (status != KERN_SUCCESS) {
if (status != MACH_SEND_INVALID_DEST)
SCDLog(LOG_DEBUG, CFSTR("notifyviasignal(): %s"), mach_error_string(status));
(void) mach_port_destroy(mach_task_self(), sessionPrivate->server);
sessionPrivate->server = MACH_PORT_NULL;
return SCD_NOSERVER;
}
sessionPrivate->notifyStatus = Using_NotifierInformViaSignal;
return scd_status;
}