procctl.c revision 114601
131565Ssef/* 257373Sru * Copyright 1997 Sean Eric Fagan 331897Ssef * 431897Ssef * Redistribution and use in source and binary forms, with or without 531897Ssef * modification, are permitted provided that the following conditions 631897Ssef * are met: 731897Ssef * 1. Redistributions of source code must retain the above copyright 831897Ssef * notice, this list of conditions and the following disclaimer. 931897Ssef * 2. Redistributions in binary form must reproduce the above copyright 1031897Ssef * notice, this list of conditions and the following disclaimer in the 1131897Ssef * documentation and/or other materials provided with the distribution. 1231897Ssef * 3. All advertising materials mentioning features or use of this software 1331897Ssef * must display the following acknowledgement: 1431897Ssef * This product includes software developed by Sean Eric Fagan 1531897Ssef * 4. Neither the name of the author may be used to endorse or promote 1631897Ssef * products derived from this software without specific prior written 1731897Ssef * permission. 1831897Ssef * 1931897Ssef * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2031897Ssef * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2131897Ssef * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2231897Ssef * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2331897Ssef * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2431897Ssef * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2531897Ssef * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2631897Ssef * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2731897Ssef * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2831897Ssef * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2931897Ssef * SUCH DAMAGE. 3031897Ssef * 3131897Ssef */ 3231897Ssef 33114601Sobrien#include <sys/cdefs.h> 34114601Sobrien__FBSDID("$FreeBSD: head/usr.sbin/procctl/procctl.c 114601 2003-05-03 21:06:42Z obrien $"); 3532273Scharnier 3631897Ssef/* 3731565Ssef * procctl -- clear the event mask, and continue, any specified processes. 3831565Ssef * This is largely an example of how to use the procfs interface; however, 3931565Ssef * for now, it is also sometimes necessary, as a stopped process will not 4031565Ssef * otherwise continue. (This will be fixed in a later version of the 4131565Ssef * procfs code, almost certainly; however, this program will still be useful 4231565Ssef * for some annoying circumstances.) 4331565Ssef */ 4431565Ssef 4532273Scharnier#include <err.h> 4632273Scharnier#include <errno.h> 4732273Scharnier#include <fcntl.h> 4832273Scharnier#include <signal.h> 4931565Ssef#include <stdio.h> 5031565Ssef#include <stdlib.h> 5131565Ssef#include <string.h> 5232273Scharnier#include <unistd.h> 5331565Ssef#include <sys/ioctl.h> 5431565Ssef#include <sys/pioctl.h> 5531565Ssef 5632273Scharnierint 5731565Ssefmain(int ac, char **av) { 5831565Ssef int fd; 5931565Ssef int i; 6031565Ssef 6131565Ssef for (i = 1; i < ac; i++) { 6231565Ssef char buf[32]; 6331565Ssef 6457373Sru snprintf(buf, sizeof(buf), "/proc/%s/mem", av[i]); 6531565Ssef fd = open(buf, O_RDWR); 6631565Ssef if (fd == -1) { 6731565Ssef if (errno == ENOENT) 6831565Ssef continue; 6932273Scharnier warn("cannot open pid %s", av[i]); 7031565Ssef continue; 7131565Ssef } 7232273Scharnier if (ioctl(fd, PIOCBIC, ~0) == -1) 7332273Scharnier warn("cannot clear process %s's event mask", av[i]); 7432273Scharnier if (ioctl(fd, PIOCCONT, 0) == -1 && errno != EINVAL) 7532273Scharnier warn("cannot continue process %s", av[i]); 7631565Ssef close(fd); 7731565Ssef } 7831565Ssef return 0; 7931565Ssef} 80