Logs program name that locks serial ports
This commit is contained in:
@@ -6,13 +6,13 @@ include ../Makefile.global
|
||||
|
||||
SRCS = callstat.c scanout.c taskcomm.c taskinfo.c taskstat.c taskibc.c \
|
||||
mbtask.c outstat.c signame.c taskdisk.c taskregs.c taskutil.c \
|
||||
ports.c calllist.c ping.c taskchat.c crc.c
|
||||
ports.c calllist.c ping.c taskchat.c crc.c pidinfo.c
|
||||
HDRS = callstat.h mbtask.h outstat.h signame.h taskdisk.h taskregs.h taskutil.h \
|
||||
scanout.h taskcomm.h taskinfo.h taskstat.h taskibc.h \
|
||||
ports.h calllist.h ping.h taskchat.h
|
||||
OBJS = callstat.o scanout.o taskcomm.o taskinfo.o taskstat.o taskibc.o \
|
||||
mbtask.o outstat.o signame.o taskdisk.o taskregs.o taskutil.o \
|
||||
ports.o calllist.o ping.o taskchat.o crc.o
|
||||
ports.o calllist.o ping.o taskchat.o crc.o pidinfo.o
|
||||
SLIBS = ../lib/libnodelist.a
|
||||
OTHER = Makefile issue issue.netbsd
|
||||
|
||||
|
119
mbtask/pidinfo.c
Normal file
119
mbtask/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 "../lib/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
|
||||
}
|
||||
|
||||
|
@@ -183,7 +183,7 @@ void load_ports()
|
||||
void check_ports(void)
|
||||
{
|
||||
pp_list *tpl;
|
||||
char *lckname;
|
||||
char *lckname, *progname;
|
||||
FILE *lf;
|
||||
int tmppid, changed = FALSE;
|
||||
pid_t rempid = 0;
|
||||
@@ -215,7 +215,12 @@ void check_ports(void)
|
||||
if (!tpl->locked) {
|
||||
tpl->locked = rempid;
|
||||
tpl->locktime = 0;
|
||||
Syslog('+', "Port %s locked, pid %d", tpl->tty, rempid);
|
||||
progname = calloc(PATH_MAX, sizeof(char));
|
||||
if (pid2prog(rempid, progname, PATH_MAX) == 0)
|
||||
Syslog('+', "Port %s locked, pid %d (%s)", tpl->tty, rempid, progname);
|
||||
else
|
||||
Syslog('+', "Port %s locked, pid %d", tpl->tty, rempid);
|
||||
free(progname);
|
||||
} else {
|
||||
/*
|
||||
* Count locktime
|
||||
|
Reference in New Issue
Block a user