Logs program name that locks serial ports
This commit is contained in:
@@ -10,13 +10,15 @@ COMMON_SRCS = clcomm.c client.c crc.c semafore.c signame.c charset.c remask.c \
|
||||
batchrd.c ftn.c pktname.c mangle.c sectest.c proglock.c magic.c \
|
||||
dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.c \
|
||||
execute.c expipe.c getheader.c noderecord.c rfcaddr.c strutil.c \
|
||||
faddr.c gmtoffset.c packet.c rfcdate.c term.c endian.c timers.c
|
||||
faddr.c gmtoffset.c packet.c rfcdate.c term.c endian.c timers.c \
|
||||
pidinfo.c
|
||||
COMMON_OBJS = clcomm.o client.o crc.o semafore.o signame.o charset.o remask.o \
|
||||
ftscprod.o attach.o falists.o hdr.o parsedate.o rfcmsg.o unpacker.o \
|
||||
batchrd.o ftn.o pktname.o mangle.o sectest.o proglock.o rearc.o \
|
||||
dostran.o ftnmsg.o mbfile.o nodelock.o rawio.o strcasestr.o magic.o \
|
||||
execute.o expipe.o getheader.o noderecord.o rfcaddr.o strutil.o \
|
||||
faddr.o gmtoffset.o packet.o rfcdate.o term.o endian.o timers.o
|
||||
faddr.o gmtoffset.o packet.o rfcdate.o term.o endian.o timers.o \
|
||||
pidinfo.o
|
||||
COMMON_HDRS = mbselib.h
|
||||
NODELIST_SRCS = nodelist.c
|
||||
NODELIST_OBJS = nodelist.o
|
||||
@@ -166,6 +168,7 @@ rfcdate.o: ../config.h mbselib.h
|
||||
term.o: ../config.h mbselib.h users.h
|
||||
endian.o: ../config.h mbselib.h
|
||||
timers.o: ../config.h mbselib.h
|
||||
pidinfo.o: ../config.h mbselib.h
|
||||
dbcfg.o: ../config.h mbselib.h mbse.h users.h mbsedb.h
|
||||
dbdupe.o: ../config.h mbselib.h mbse.h users.h mbsedb.h
|
||||
dbftn.o: ../config.h mbselib.h users.h mbsedb.h
|
||||
|
@@ -2549,7 +2549,13 @@ int magic_check(char *, char *); /* Check if magic alias exists */
|
||||
|
||||
|
||||
|
||||
/************************************************************************
|
||||
/*
|
||||
* pidinfo.c
|
||||
*/
|
||||
int pid2prog(pid_t, char *, size_t); /* Find progrname for a pid */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
*
|
||||
* Charset mapping
|
||||
*/
|
||||
|
119
lib/pidinfo.c
Normal file
119
lib/pidinfo.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id$
|
||||
* Purpose ...............: Pid utilities
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2005
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
* 1971 BV IJmuiden
|
||||
* the Netherlands
|
||||
*
|
||||
* This file is part of MBSE BBS.
|
||||
*
|
||||
* This BBS is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* MBSE BBS is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../config.h"
|
||||
#include "mbselib.h"
|
||||
|
||||
|
||||
/*
|
||||
* Find the program name for a given pid. The progname buffer
|
||||
* has te be allocated with size byte.
|
||||
*/
|
||||
int pid2prog(pid_t pid, char *progname, size_t size)
|
||||
{
|
||||
#if defined(__OpenBSD__)
|
||||
#define ARG_SIZE 60
|
||||
static char **s, buf[ARG_SIZE];
|
||||
size_t siz = 100;
|
||||
char **p;
|
||||
int mib[4];
|
||||
#elif defined(__NetBSD__)
|
||||
#define ARG_SIZE 60
|
||||
static char **s;
|
||||
size_t siz = 100;
|
||||
int mib[4];
|
||||
#else
|
||||
char temp[PATH_MAX];
|
||||
FILE *fp;
|
||||
#endif
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
/*
|
||||
* Systems that use sysctl to get process information
|
||||
*/
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = pid;
|
||||
mib[3] = KERN_PROC_ARGV;
|
||||
if ((s = realloc(s, siz)) == NULL) {
|
||||
WriteError("pid2prog(): no memory");
|
||||
return -1;
|
||||
}
|
||||
if (sysctl(mib, 4, s, &siz, NULL, 0) == -1) {
|
||||
WriteError("$pid2prog() sysctl call failed");
|
||||
return -1;
|
||||
}
|
||||
buf[0] = '\0';
|
||||
for (p = s; *p != NULL; p++) {
|
||||
if (p != s)
|
||||
strlcat(buf, " ", sizeof(buf));
|
||||
strlcat(buf, *p, sizeof(buf));
|
||||
}
|
||||
strncpy(progname, buf, size);
|
||||
return 0;
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
/*
|
||||
* Systems that use sysctl to get process information
|
||||
*/
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = pid;
|
||||
mib[3] = KERN_PROC_ARGV;
|
||||
if ((s = realloc(s, siz)) == NULL) {
|
||||
WriteError("pid2prog(): no memory");
|
||||
return -1;
|
||||
}
|
||||
if (sysctl(mib, 4, s, &siz, NULL, 0) == -1) {
|
||||
WriteError("$pid2prog() sysctl call failed");
|
||||
return -1;
|
||||
}
|
||||
// parent = xstrcpy((char *)s);
|
||||
strncpy(progname, (char *)s, size);
|
||||
return 0;
|
||||
|
||||
#else
|
||||
/*
|
||||
* Systems with /proc filesystem like Linux, FreeBSD
|
||||
*/
|
||||
snprintf(temp, PATH_MAX, "/proc/%d/cmdline", pid);
|
||||
if ((fp = fopen(temp, "r")) == NULL) {
|
||||
WriteError("$Can't read %s", temp);
|
||||
return -1;
|
||||
}
|
||||
fgets(temp, PATH_MAX-1, fp);
|
||||
fclose(fp);
|
||||
strncpy(progname, temp, size);
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user