Beispiel #1
0
int
sigsend(idtype_t idtype, id_t id, int sig)
{
	procset_t set;
	setprocset(&set, POP_AND, idtype, id, P_ALL, P_MYID);
	return (sigsendset(&set, sig));
}
Beispiel #2
0
static int
sigqkill(pid_t pid, sigsend_t *sigsend)
{
	proc_t *p;
	int error;

	if ((uint_t)sigsend->sig >= NSIG)
		return (EINVAL);

	if (pid == -1) {
		procset_t set;

		setprocset(&set, POP_AND, P_ALL, P_MYID, P_ALL, P_MYID);
		error = sigsendset(&set, sigsend);
	} else if (pid > 0) {
		mutex_enter(&pidlock);
		if ((p = prfind(pid)) == NULL || p->p_stat == SIDL)
			error = ESRCH;
		else {
			error = sigsendproc(p, sigsend);
			if (error == 0 && sigsend->perm == 0)
				error = EPERM;
		}
		mutex_exit(&pidlock);
	} else {
		int nfound = 0;
		pid_t pgid;

		if (pid == 0)
			pgid = ttoproc(curthread)->p_pgrp;
		else
			pgid = -pid;

		error = 0;
		mutex_enter(&pidlock);
		for (p = pgfind(pgid); p && !error; p = p->p_pglink) {
			if (p->p_stat != SIDL) {
				nfound++;
				error = sigsendproc(p, sigsend);
			}
		}
		mutex_exit(&pidlock);
		if (nfound == 0)
			error = ESRCH;
		else if (error == 0 && sigsend->perm == 0)
			error = EPERM;
	}

	return (error);
}
static int
set_proc_info(pid_t pid, const char *path, core_content_t content)
{
	proc_t *p;
	counter_t counter;
	int error = 0;

	counter.cc_count = 0;
	/*
	 * Only one of the core file path or content can be set at a time.
	 */
	if (path != NULL) {
		counter.cc_path = corectl_path_alloc(path);
		counter.cc_content = NULL;
	} else {
		counter.cc_path = NULL;
		counter.cc_content = corectl_content_alloc(content);
	}

	if (pid == -1) {
		procset_t set;

		setprocset(&set, POP_AND, P_ALL, P_MYID, P_ALL, P_MYID);
		error = dotoprocs(&set, set_one_proc_info, (char *)&counter);
		if (error == 0 && counter.cc_count == 0)
			error = EPERM;
	} else if (pid > 0) {
		mutex_enter(&pidlock);
		if ((p = prfind(pid)) == NULL || p->p_stat == SIDL) {
			error = ESRCH;
		} else {
			(void) set_one_proc_info(p, &counter);
			if (counter.cc_count == 0)
				error = EPERM;
		}
		mutex_exit(&pidlock);
	} else {
		int nfound = 0;
		pid_t pgid;

		if (pid == 0)
			pgid = curproc->p_pgrp;
		else
			pgid = -pid;

		mutex_enter(&pidlock);
		for (p = pgfind(pgid); p != NULL; p = p->p_pglink) {
			if (p->p_stat != SIDL) {
				nfound++;
				(void) set_one_proc_info(p, &counter);
			}
		}
		mutex_exit(&pidlock);
		if (nfound == 0)
			error = ESRCH;
		else if (counter.cc_count == 0)
			error = EPERM;
	}

	if (path != NULL)
		corectl_path_rele(counter.cc_path);
	else
		corectl_content_rele(counter.cc_content);

	if (error)
		return (set_errno(error));
	return (0);
}