DragonFly BSD
DragonFly bugs List (threaded) for 2005-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: waitpid() with WUNTRACED flag? (was Re: Hang on ctrl+Z after the MPSAFE tsleep/wakeup commit)

From: YONETANI Tomokazu <qhwt+dfly@xxxxxxxxxx>
Date: Tue, 27 Dec 2005 09:28:24 +0900

On Tue, Dec 27, 2005 at 09:15:54AM +0900, YONETANI Tomokazu wrote:
> By the way, here's the code I forgot attaching in the previous message.
#include <sys/types.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

	const char *editor = "/usr/bin/vi";
	const char *name;
	pid_t pid, caught;
	int sig;
	int st;

	if (getenv("EDITOR") != NULL)
		editor = getenv("EDITOR");
	if ((name = strrchr(editor, '/')) != NULL)
		name = editor;
	if ((pid = fork()) < 0)
		err(1, "fork");
	if (pid == 0)
		return execlp(editor, name, NULL);
#if 0
	killpg(getpgrp(), SIGSTOP);
	for (;;) {
		caught = waitpid(pid, &st, WUNTRACED);
		warnx("waitpid returned %d\n", caught);
		errno = WEXITSTATUS(st);
		if (caught == -1)
			return 1;
		else if (WIFSTOPPED(st)) {
			sig = WSTOPSIG(st);
			warnx("WSTOPSIG(%d) = %d\n", st, sig);
			sig = SIGSTOP;
			warnx("after raise(%d)\n", sig);
		else if (WIFEXITED(st))
			return errno;
			return 1;
	return 0;

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]