Esempio n. 1
0
/*
 * Send a signal.
 *
 * The behavior is different for the pid value.
 *
 *  if (pid > 0)
 *    Send a signal to specific process.
 *
 *  if (pid == 0)
 *    Send a signal to all processes in same process group.
 *
 *  if (pid == -1)
 *    Send a signal to all processes except init.
 *
 *  if (pid < -1)
 *     Send a signal to the process group.
 *
 * Note: Need CAP_KILL capability to send a signal to the different
 * process/group.
 */
int
sys_kill(pid_t pid, int sig)
{
	struct proc *p;
	list_t n;
	int error = 0;

	DPRINTF(("proc: kill pid=%d sig=%d\n", pid, sig));

	switch (sig) {
	case SIGFPE:
	case SIGILL:
	case SIGSEGV:
		return EINVAL;
	}

	if (pid > 0) {
		if (pid != curproc->p_pid && !kill_capable()) {
			DPRINTF(("proc: EPERM\n"));
			return EPERM;
		}
		error = kill_one(pid, sig);
	}
	else if (pid == -1) {
		DPRINTF(("proc: kill? curproc=%x\n", curproc));
		if (!kill_capable())
			return EPERM;

		DPRINTF(("proc: kill all!\n"));
		for (n = list_first(&allproc); n != &allproc;
		     n = list_next(n)) {
			p = list_entry(n, struct proc, p_link);

			/*
			 * We don't send a signal to the following processes.
			 *
			 *  pid=0   - process server
			 *  pid=1   - init process
			 *  curproc - current process (sleeping in msg_send)
			 */
			if (p->p_pid != 0 && p->p_pid != 1 &&
			    p->p_pid != curproc->p_pid)
			{
				error = kill_one(p->p_pid, sig);
				if (error != 0)
					break;
			}
		}
	}
Esempio n. 2
0
int
panic(pink_easy_process_t *current)
{
	unsigned count;
	pink_easy_process_list_t *list = pink_easy_context_get_process_list(pandora->ctx);

	switch (pandora->config.panic_decision) {
	case PANIC_KILL:
		warning("panic! killing the guilty process");
		kill_one(current, UINT_TO_PTR(1));
		return PINK_EASY_CFLAG_DROP;
	case PANIC_CONT:
		warning("panic! resuming the guilty process");
		cont_one(current, UINT_TO_PTR(1));
		return PINK_EASY_CFLAG_DROP;
	case PANIC_CONTALL:
		warning("panic! resuming all processes");
		count = pink_easy_process_list_walk(list, cont_one, UINT_TO_PTR(1));
		warning("resumed %u process%s, exiting", count, count > 1 ? "es" : "");
		break;
	case PANIC_KILLALL:
		warning("panic! killing all processes");
		count = pink_easy_process_list_walk(list, kill_one, UINT_TO_PTR(1));
		warning("killed %u process%s, exiting", count, count > 1 ? "es" : "");
		break;
	default:
		abort();
	}

	/* exit */
	exit(pandora->config.panic_exit_code > 0 ? pandora->config.panic_exit_code : pandora->exit_code);
}
Esempio n. 3
0
static void
kill_dir(const char *dirname)
{
    struct entry *ents;
    int maxents;
    int curents = 0;
    DIR *dir;
    struct dirent *dp;
    int i;

    fprintf(verbose, "reading %s\n", dirname);

    dir = opendir(".");
    if (dir == NULL)
	err(1, "opendir %s", dirname);
    maxents = 10;
    ents = malloc(sizeof(*ents) * maxents);
    if (ents == NULL)
	err(1, "malloc");
    while ((dp = readdir(dir)) != NULL) {
	if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
	    continue;

	if (curents >= maxents) {
	    maxents *= 2;
	    ents = realloc(ents, sizeof(*ents) * maxents);
	    if (ents == NULL)
		err(1, "realloc");
	}
	ents[curents].name = strdup(dp->d_name);
	ents[curents].status = 1;
	++curents;
	fprintf(verbose, "  adding %s\n", dp->d_name);
    }
    closedir(dir);
    dir = opendir(".");
    if (dir == NULL)
	err(1, "opendir %s", dirname);
    i = 0;
    while ((dp = readdir(dir)) != NULL) {
	if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
	    continue;

	if (strcmp(ents[i].name, dp->d_name) != 0) {
	    errx(1, "%s != %s", ents[i].name, dp->d_name);
	}
	fprintf(verbose, "  deleting %s\n", ents[i].name);
	kill_one(ents, i, curents);
	++i;
    }
    if (i != curents)
	errx(1, "missing %d entries in %s", curents - i, dirname);
    closedir(dir);
    free(ents);
    fprintf(verbose, "end of %s\n", dirname);
}
Esempio n. 4
0
File: kill.c Progetto: AndrewD/prex
/*
 * Send a signal.
 *
 * The behavior is different for the pid value.
 *
 *  if (pid > 0)
 *    Send a signal to specific process.
 *
 *  if (pid == 0)
 *    Send a signal to all processes in same process group.
 *
 *  if (pid == -1)
 *    Send a signal to all processes except init.
 *
 *  if (pid < -1)
 *     Send a signal to the process group.
 *
 * Note: Need CAP_KILL capability to send a signal to the different
 * process/group.
 */
int
proc_kill(struct msg *msg)
{
	pid_t pid;
	struct proc *p;
	list_t n;
	int sig, capable = 0;
	int err = 0;

	pid = (pid_t)msg->data[0];
	sig = msg->data[1];

	DPRINTF(("proc: kill pid=%d sig=%d\n", pid, sig));

	switch (sig) {
	case SIGFPE:
	case SIGILL:
	case SIGSEGV:
		return EINVAL;
	}

	if (curproc->p_cap & CAP_KILL)
		capable = 1;

	if (pid > 0) {
		if (pid != curproc->p_pid && !capable)
			return EPERM;
		err = kill_one(pid, sig);
	}
	else if (pid == -1) {
		if (!capable)
			return EPERM;
		for (n = list_first(&allproc); n != &allproc;
		     n = list_next(n)) {
			p = list_entry(n, struct proc, p_link);
			if (p->p_pid != 0 && p->p_pid != 1) {
				err = kill_one(p->p_pid, sig);
				if (err != 0)
					break;
			}
		}
	}
	else if (pid == 0) {
Esempio n. 5
0
void PlayerTank::fire()
{
    // 向pool关送命令

    PlayerBullet *bullet = new PlayerBullet();
    bullet->setRotation(this->rotation());
    bullet->setPos(mapToScene(0,
                              0 + boundingRect().height()
                              )
                   );
    bullet->setTeam(getTeam());
    QObject::connect(bullet, SIGNAL(signal_bullet_kill_one()), this, SLOT(kill_one()));
    this->scene()->addItem(bullet);


}
Esempio n. 6
0
static void
kill_dir(const char *dirname)
{
    DIR *dir;
    struct dirent *dp;

    dir = opendir(".");
    if (dir == NULL)
	err(1, "opendir %s", dirname);
    while ((dp = readdir(dir)) != NULL) {
	if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
	    continue;

	kill_one(dp->d_name);
    }
    closedir(dir);
}
Esempio n. 7
0
int
violation(pink_easy_process_t *current, const char *fmt, ...)
{
	unsigned count;
	va_list ap;
	pink_easy_process_list_t *list = pink_easy_context_get_process_list(pandora->ctx);

	pandora->violation = true;

	va_start(ap, fmt);
	report(current, fmt, ap);
	va_end(ap);

	switch (pandora->config.violation_decision) {
	case VIOLATION_DENY:
		return 0; /* Let the caller handle this */
	case VIOLATION_KILL:
		warning("killing the guilty process");
		kill_one(current, UINT_TO_PTR(1));
		return PINK_EASY_CFLAG_DROP;
	case VIOLATION_CONT:
		warning("resuming the guilty process");
		cont_one(current, UINT_TO_PTR(1));
		return PINK_EASY_CFLAG_DROP;
	case VIOLATION_CONTALL:
		warning("resuming all processes");
		count = pink_easy_process_list_walk(list, cont_one, UINT_TO_PTR(1));
		warning("resumed %u processes, exiting", count);
		break;
	case VIOLATION_KILLALL:
		warning("killing all processes");
		count = pink_easy_process_list_walk(list, kill_one, UINT_TO_PTR(1));
		warning("killed %u processes, exiting", count);
		break;
	default:
		abort();
	}

	/* exit */
	if (pandora->config.violation_exit_code > 0)
		exit(pandora->config.violation_exit_code);
	else if (!pandora->config.violation_exit_code)
		exit(128 + pandora->config.violation_exit_code);
	exit(pandora->exit_code);
}
Esempio n. 8
0
static void
kill_dir(const char *dirname)
{
    struct entry *ents;
    int maxents;
    int curents = 0;
    DIR *dir;
    struct dirent *dp;
    int i;

    dir = opendir(".");
    if (dir == NULL)
	err(1, "opendir %s", dirname);
    maxents = 10;
    ents = malloc(sizeof(*ents) * maxents);
    if (ents == NULL)
	err(1, "malloc");
    while ((dp = readdir(dir)) != NULL) {
	if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
	    continue;

	if (curents >= maxents) {
	    maxents *= 2;
	    ents = realloc(ents, sizeof(*ents) * maxents);
	    if (ents == NULL)
		err(1, "realloc");
	}
	ents[curents].name = strdup(dp->d_name);
	ents[curents].status = 1;
	++curents;
    }
    closedir(dir);
    for (i = 0; i < curents; ++i)
	kill_one(ents, i, curents);
    free(ents);
}