procctl.c revision 57373
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 3332273Scharnier#ifndef lint 3432273Scharnierstatic const char rcsid[] = 3550479Speter "$FreeBSD: head/usr.sbin/procctl/procctl.c 57373 2000-02-21 10:22:39Z ru $"; 3632273Scharnier#endif /* not lint */ 3732273Scharnier 3831897Ssef/* 3931565Ssef * procctl -- clear the event mask, and continue, any specified processes. 4031565Ssef * This is largely an example of how to use the procfs interface; however, 4131565Ssef * for now, it is also sometimes necessary, as a stopped process will not 4231565Ssef * otherwise continue. (This will be fixed in a later version of the 4331565Ssef * procfs code, almost certainly; however, this program will still be useful 4431565Ssef * for some annoying circumstances.) 4531565Ssef */ 4631565Ssef 4732273Scharnier#include <err.h> 4832273Scharnier#include <errno.h> 4932273Scharnier#include <fcntl.h> 5032273Scharnier#include <signal.h> 5131565Ssef#include <stdio.h> 5231565Ssef#include <stdlib.h> 5331565Ssef#include <string.h> 5432273Scharnier#include <unistd.h> 5531565Ssef#include <sys/ioctl.h> 5631565Ssef#include <sys/pioctl.h> 5731565Ssef 5832273Scharnierint 5931565Ssefmain(int ac, char **av) { 6031565Ssef int fd; 6131565Ssef int i; 6231565Ssef 6331565Ssef for (i = 1; i < ac; i++) { 6431565Ssef char buf[32]; 6531565Ssef 6657373Sru snprintf(buf, sizeof(buf), "/proc/%s/mem", av[i]); 6731565Ssef fd = open(buf, O_RDWR); 6831565Ssef if (fd == -1) { 6931565Ssef if (errno == ENOENT) 7031565Ssef continue; 7132273Scharnier warn("cannot open pid %s", av[i]); 7231565Ssef continue; 7331565Ssef } 7432273Scharnier if (ioctl(fd, PIOCBIC, ~0) == -1) 7532273Scharnier warn("cannot clear process %s's event mask", av[i]); 7632273Scharnier if (ioctl(fd, PIOCCONT, 0) == -1 && errno != EINVAL) 7732273Scharnier warn("cannot continue process %s", av[i]); 7831565Ssef close(fd); 7931565Ssef } 8031565Ssef return 0; 8131565Ssef} 82