procctl.c revision 31897
118334Speter/* 290075Sobrien * Copryight 1997 Sean Eric Fagan 3169689Skan * 418334Speter * Redistribution and use in source and binary forms, with or without 590075Sobrien * modification, are permitted provided that the following conditions 618334Speter * are met: 790075Sobrien * 1. Redistributions of source code must retain the above copyright 890075Sobrien * notice, this list of conditions and the following disclaimer. 990075Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1090075Sobrien * notice, this list of conditions and the following disclaimer in the 1118334Speter * documentation and/or other materials provided with the distribution. 1290075Sobrien * 3. All advertising materials mentioning features or use of this software 1390075Sobrien * must display the following acknowledgement: 1490075Sobrien * This product includes software developed by Sean Eric Fagan 1590075Sobrien * 4. Neither the name of the author may be used to endorse or promote 1618334Speter * products derived from this software without specific prior written 1718334Speter * permission. 1890075Sobrien * 19169689Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20169689Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2118334Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2218334Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2318334Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2450397Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25132718Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26132718Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2718334Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2850397Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29117395Skan * SUCH DAMAGE. 30117395Skan * 3190075Sobrien */ 3290075Sobrien 33169689Skan/* 34132718Skan * procctl -- clear the event mask, and continue, any specified processes. 35169689Skan * This is largely an example of how to use the procfs interface; however, 36169689Skan * for now, it is also sometimes necessary, as a stopped process will not 3718334Speter * otherwise continue. (This will be fixed in a later version of the 38132718Skan * procfs code, almost certainly; however, this program will still be useful 39132718Skan * for some annoying circumstances.) 40169689Skan */ 41169689Skan/* 4218334Speter * $Id: procctl.c,v 1.2 1997/12/13 03:13:49 sef Exp $ 4390075Sobrien */ 4490075Sobrien 4590075Sobrien#include <stdio.h> 46117395Skan#include <stdlib.h> 4750397Sobrien#include <string.h> 48169689Skan#include <errno.h> 4990075Sobrien#include <err.h> 5090075Sobrien#include <signal.h> 51117395Skan#include <fcntl.h> 52117395Skan#include <sys/ioctl.h> 53117395Skan#include <sys/pioctl.h> 54117395Skan 55169689Skanmain(int ac, char **av) { 56117395Skan int fd; 57169689Skan int i; 58117395Skan unsigned int mask; 59117395Skan char **command; 60117395Skan struct procfs_status pfs; 61117395Skan 62117395Skan for (i = 1; i < ac; i++) { 63117395Skan char buf[32]; 64117395Skan 65117395Skan sprintf(buf, "/proc/%s/mem", av[i]); 66117395Skan fd = open(buf, O_RDWR); 67117395Skan if (fd == -1) { 68117395Skan if (errno == ENOENT) 69117395Skan continue; 70117395Skan fprintf(stderr, "%s: cannot open pid %s: %s\n", 71117395Skan av[0], av[i], strerror(errno)); 72117395Skan continue; 73117395Skan } 74117395Skan if (ioctl(fd, PIOCBIC, ~0) == -1) { 75117395Skan fprintf(stderr, "%s: cannot clear process %s's event mask: %s\n", 76117395Skan av[0], av[i], strerror(errno)); 77117395Skan } 78117395Skan if (ioctl(fd, PIOCCONT, 0) == -1 && errno != EINVAL) { 79117395Skan fprintf(stderr, "%s: cannot continue process %s: %s\n", 80117395Skan av[0], av[i], strerror(errno)); 81117395Skan } 82117395Skan close(fd); 83117395Skan } 84117395Skan return 0; 85117395Skan} 86169689Skan