Compare commits
16 Commits
pstack-1.3
...
master
Author | SHA1 | Date |
---|---|---|
Matteo Cypriani | 150a89bb40 | |
Thomas Preud'homme | 6dbd036eea | |
Thomas Preud'homme | f0aa8400b7 | |
Thomas Preud'homme | d75a8ea2a1 | |
Thomas Preud'homme | fe2590b471 | |
Thomas Preud'homme | 8ade3d5cb9 | |
Thomas Preud'homme | 8a440f169b | |
Thomas Preud'homme | a8f2e34c5f | |
Thomas Preud'homme | 1cede92011 | |
Thomas Preud'homme | c86ed77fb2 | |
Thomas Preud'homme | 3ec09496b9 | |
Thomas Preud'homme | 27599168da | |
Thomas Preud'homme | ee32fa3624 | |
Thomas Preud'homme | d0e37451f5 | |
Thomas Preud'homme | b455f99538 | |
Thomas Preud'homme | 6f25ab2494 |
|
@ -1 +0,0 @@
|
||||||
pstack
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
.gitignore export-ignore
|
||||||
|
.gitattributes export-ignore
|
40
Makefile
40
Makefile
|
@ -15,33 +15,37 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
VERSION = $(shell awk 'END { print $$1 }' VERSION)
|
VERSION = $(shell awk 'END { print $$1 }' VERSION)
|
||||||
CFLAGS = -Wall -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS)
|
CFLAGS ?= -Wall -Wextra -g -O2
|
||||||
|
CPPFLAGS += -DVERSION=\"$(VERSION)\"
|
||||||
|
|
||||||
|
# Note: assignments are ignored for variable overriden on command line VAR=value
|
||||||
|
# so DESTDIR is ignored for overriden variables
|
||||||
|
PREFIX ?= /usr
|
||||||
|
BINDIR ?= $(PREFIX)/bin
|
||||||
|
BINDIR := $(DESTDIR)$(BINDIR)
|
||||||
|
MANDIR ?= $(PREFIX)/share/man
|
||||||
|
MANDIR := $(DESTDIR)$(MANDIR)
|
||||||
|
|
||||||
ifeq ($(RPM_OPT_FLAGS),)
|
|
||||||
CFLAGS += -g
|
|
||||||
LDFLAGS += -g
|
|
||||||
endif
|
|
||||||
|
|
||||||
pstack : pstack.c
|
pstack : pstack.c
|
||||||
$(CC) $(CFLAGS) -o pstack pstack.c
|
$(CC) $(CPPFLAGS) $(CFLAGS) -o pstack $^ $(LDFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f pstack
|
rm -f pstack
|
||||||
|
|
||||||
install : pstack
|
install : pstack
|
||||||
mkdir -p $(BINDIR)
|
mkdir -p "$(BINDIR)"
|
||||||
install -m 755 pstack $(BINDIR)
|
install -m 755 pstack "$(BINDIR)"
|
||||||
mkdir -p $(MANDIR)/man1
|
mkdir -p "$(MANDIR)/man1"
|
||||||
install -m 644 man1/pstack.1 $(MANDIR)/man1
|
install -m 644 man1/pstack.1 "$(MANDIR)/man1"
|
||||||
|
|
||||||
cvstag:
|
gittag:
|
||||||
cvs tag -F $(CVSTAG) .
|
git tag -s pstack-$(VERSION)
|
||||||
|
|
||||||
archive: cvstag
|
archive: gittag
|
||||||
@rm -rf /tmp/pstack-$(VERSION) /tmp/pstack
|
@rm -rf /tmp/pstack-$(VERSION).tar.gz
|
||||||
@cd /tmp; cvs export -r$(CVSTAG) pstack; mv pstack pstack-$(VERSION)
|
@git archive -o /tmp/pstack-$(VERSION).tar --prefix=pstack-$(VERSION)/ pstack-$(VERSION)
|
||||||
@cd /tmp; tar czSpf pstack-$(VERSION).tar.gz pstack-$(VERSION)
|
@cd /tmp; gzip -9 pstack-$(VERSION).tar
|
||||||
@rm -rf /tmp/pstack-$(VERSION)
|
|
||||||
@cp /tmp/pstack-$(VERSION).tar.gz .
|
@cp /tmp/pstack-$(VERSION).tar.gz .
|
||||||
@echo " "
|
@echo ""
|
||||||
@echo "The final archive is ./pstack-$(VERSION).tar.gz."
|
@echo "The final archive is ./pstack-$(VERSION).tar.gz."
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pstack - print stack trace of running processes
|
# pstack - print stack trace of running processes
|
||||||
|
|
||||||
pstack dumps a stack trace for a process, given the pid of that
|
pstack dumps a stack trace for a process, given the pid of that
|
||||||
process. If the process named is part of a thread group, then all the threads
|
process. If the process named is part of a thread group, then all the threads
|
||||||
|
@ -6,8 +6,9 @@ inthe group are traced. See the man page for more information.
|
||||||
|
|
||||||
This program was inspired by the 'pstack' program available on Solaris.
|
This program was inspired by the 'pstack' program available on Solaris.
|
||||||
|
|
||||||
SUPPORTED PLATFORMS:
|
## Supported Platforms
|
||||||
This program runs on 32 bit x86 machines, using ELF binaries
|
|
||||||
|
This program runs on 32 bit x86 machines, using ELF binaries
|
||||||
generated from GNU compilers. If threads are being used, it depends
|
generated from GNU compilers. If threads are being used, it depends
|
||||||
on a debuggable version of the pthreads library to find the threads in
|
on a debuggable version of the pthreads library to find the threads in
|
||||||
the thread group. If anyone wants to port this to other
|
the thread group. If anyone wants to port this to other
|
||||||
|
@ -15,22 +16,20 @@ architectures, please let me know about questions you may have, or
|
||||||
achievements you have made. I'd like to incorporate such changes into
|
achievements you have made. I'd like to incorporate such changes into
|
||||||
my version of the code.
|
my version of the code.
|
||||||
|
|
||||||
FEATURES:
|
## Features
|
||||||
symbolic address dumping
|
|
||||||
thread group support
|
* symbolic address dumping
|
||||||
|
* thread group support
|
||||||
|
|
||||||
|
## Build, install, uninstall
|
||||||
|
|
||||||
BUILD:
|
|
||||||
make
|
make
|
||||||
|
|
||||||
INSTALL:
|
|
||||||
make install
|
make install
|
||||||
|
|
||||||
UNINSTALL:
|
|
||||||
make uninstall
|
make uninstall
|
||||||
|
|
||||||
NOTE: you must be root to [un]install. pstack will run fine from any
|
**Note:** you must be root to [un]install. pstack will run fine from any
|
||||||
directory, install just puts the binary and man page in 'normal'
|
directory, install just puts the binary and man page in 'normal'
|
||||||
places (/usr/local/...)
|
places (`/usr/local/...`)
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
pstack pid [...]
|
pstack pid [...]
|
1
VERSION
1
VERSION
|
@ -2,3 +2,4 @@
|
||||||
1.1 25/Feb/2002
|
1.1 25/Feb/2002
|
||||||
1.2 12/Nov/2003
|
1.2 12/Nov/2003
|
||||||
1.3 02/Oct/2011
|
1.3 02/Oct/2011
|
||||||
|
1.3.1 03/Oct/2011
|
||||||
|
|
15
changelog
15
changelog
|
@ -1,3 +1,17 @@
|
||||||
|
** pstack 1.3.1 **
|
||||||
|
|
||||||
|
Thomas Preud'homme (6):
|
||||||
|
Fix incorrect ptrace failure tests in crawl()
|
||||||
|
Add -Wextra flags to CFLAGS and fix warnings
|
||||||
|
Remove distribution specific variables in Makefile
|
||||||
|
Respect CFLAGS from the environment
|
||||||
|
Support DESTDIR and PREFIX variables in Makefile
|
||||||
|
Rewrite archive and cvstag make rules for git
|
||||||
|
Don't include .*ignore files in archives
|
||||||
|
Compile with -g -O2 by default
|
||||||
|
Make struct used by PTRACE_GETREGS arch-dependant
|
||||||
|
Error out if no object file header
|
||||||
|
|
||||||
** pstack 1.3 **
|
** pstack 1.3 **
|
||||||
|
|
||||||
Baruch Even (1):
|
Baruch Even (1):
|
||||||
|
@ -15,4 +29,3 @@ Thomas Preud'homme (12):
|
||||||
Add support for armel architecture
|
Add support for armel architecture
|
||||||
Include <endian.h> as fallback for endianness
|
Include <endian.h> as fallback for endianness
|
||||||
Do not call perror in crawl() if no ptrace error
|
Do not call perror in crawl() if no ptrace error
|
||||||
|
|
||||||
|
|
58
pstack.c
58
pstack.c
|
@ -66,6 +66,7 @@
|
||||||
#define ElfN_Addr Elf64_Addr
|
#define ElfN_Addr Elf64_Addr
|
||||||
#define ElfN_Sym Elf64_Sym
|
#define ElfN_Sym Elf64_Sym
|
||||||
#define ElfN_Dyn Elf64_Dyn
|
#define ElfN_Dyn Elf64_Dyn
|
||||||
|
#define ElfN_Off Elf64_Off
|
||||||
#define ELFCLASSN ELFCLASS64
|
#define ELFCLASSN ELFCLASS64
|
||||||
#define ELFN_ST_TYPE ELF64_ST_TYPE
|
#define ELFN_ST_TYPE ELF64_ST_TYPE
|
||||||
#define INT_RANGE_STR "64"
|
#define INT_RANGE_STR "64"
|
||||||
|
@ -76,6 +77,7 @@
|
||||||
#define ElfN_Addr Elf32_Addr
|
#define ElfN_Addr Elf32_Addr
|
||||||
#define ElfN_Sym Elf32_Sym
|
#define ElfN_Sym Elf32_Sym
|
||||||
#define ElfN_Dyn Elf32_Dyn
|
#define ElfN_Dyn Elf32_Dyn
|
||||||
|
#define ElfN_Off Elf32_Off
|
||||||
#define ELFCLASSN ELFCLASS32
|
#define ELFCLASSN ELFCLASS32
|
||||||
#define ELFN_ST_TYPE ELF32_ST_TYPE
|
#define ELFN_ST_TYPE ELF32_ST_TYPE
|
||||||
#define INT_RANGE_STR "32"
|
#define INT_RANGE_STR "32"
|
||||||
|
@ -112,12 +114,16 @@
|
||||||
#endif /* x86-{32,64} */
|
#endif /* x86-{32,64} */
|
||||||
#define NEXT_FRAME_POINTER_ADDR(fp) (fp)
|
#define NEXT_FRAME_POINTER_ADDR(fp) (fp)
|
||||||
#define NEXT_PROGRAM_COUNTER_ADDR(fp) ((fp) + __SIZEOF_POINTER__)
|
#define NEXT_PROGRAM_COUNTER_ADDR(fp) ((fp) + __SIZEOF_POINTER__)
|
||||||
|
#define DECLARE_REGS_STRUCT(regs) struct user_regs_struct regs
|
||||||
|
#define VDSO_NAME "linux-vdso.so.1"
|
||||||
#elif defined(__ARMEL__) /* armel */
|
#elif defined(__ARMEL__) /* armel */
|
||||||
#define ELF_MACHINE EM_ARM
|
#define ELF_MACHINE EM_ARM
|
||||||
#define PROGRAM_COUNTER(regs) (regs.ARM_pc)
|
#define PROGRAM_COUNTER(regs) (regs.ARM_pc)
|
||||||
#define FRAME_POINTER(regs) (regs.ARM_fp)
|
#define FRAME_POINTER(regs) (regs.ARM_fp)
|
||||||
#define NEXT_FRAME_POINTER_ADDR(fp) ((fp) - __SIZEOF_POINTER__)
|
#define NEXT_FRAME_POINTER_ADDR(fp) ((fp) - __SIZEOF_POINTER__)
|
||||||
#define NEXT_PROGRAM_COUNTER_ADDR(fp) (fp)
|
#define NEXT_PROGRAM_COUNTER_ADDR(fp) (fp)
|
||||||
|
#define DECLARE_REGS_STRUCT(regs) struct user_regs regs
|
||||||
|
#define VDSO_NAME ""
|
||||||
#elif defined(__ppc64__) || defined(__alpha__) || defined(__ia64__) || defined(s390x__)
|
#elif defined(__ppc64__) || defined(__alpha__) || defined(__ia64__) || defined(s390x__)
|
||||||
#error Not (yet) supported architecture, patches welcomes :-)
|
#error Not (yet) supported architecture, patches welcomes :-)
|
||||||
#else
|
#else
|
||||||
|
@ -280,7 +286,7 @@ static void findCodeAddress(ElfN_Addr addr, ElfN_Sym **ans,
|
||||||
{
|
{
|
||||||
ElfN_Sym *sym;
|
ElfN_Sym *sym;
|
||||||
Symbols tab;
|
Symbols tab;
|
||||||
uintN_t i;
|
int i;
|
||||||
|
|
||||||
for (tab = allSyms, *ans = 0, *symtab = 0; tab; tab = tab->next) {
|
for (tab = allSyms, *ans = 0, *symtab = 0; tab; tab = tab->next) {
|
||||||
if (addr < tab->baseAddr) continue;
|
if (addr < tab->baseAddr) continue;
|
||||||
|
@ -370,7 +376,7 @@ static void checkForThreads(Symbols syms, int pid)
|
||||||
if (!descr && i == 0)
|
if (!descr && i == 0)
|
||||||
/* The initial thread's descriptor was not initialized yet. */
|
/* The initial thread's descriptor was not initialized yet. */
|
||||||
*pptr++ = pid;
|
*pptr++ = pid;
|
||||||
else if (descr != -1 || !errno) {
|
else if (descr != (ElfN_Addr) -1 || !errno) {
|
||||||
tpid = ptrace(PTRACE_PEEKDATA, pid, descr + pidOff, 0);
|
tpid = ptrace(PTRACE_PEEKDATA, pid, descr + pidOff, 0);
|
||||||
if (tpid != -1 || !errno)
|
if (tpid != -1 || !errno)
|
||||||
*pptr++ = tpid;
|
*pptr++ = tpid;
|
||||||
|
@ -438,8 +444,8 @@ static int find_stables(ElfN_Ehdr *hdr, int fd, Symbols syms)
|
||||||
if (!(syms->symbols = (ElfN_Sym *) malloc(shdr.sh_size)))
|
if (!(syms->symbols = (ElfN_Sym *) malloc(shdr.sh_size)))
|
||||||
quit("Could not allocate symbol table.");
|
quit("Could not allocate symbol table.");
|
||||||
|
|
||||||
if (lseek(fd, shdr.sh_offset, SEEK_SET) != shdr.sh_offset ||
|
if ((ElfN_Off) lseek(fd, shdr.sh_offset, SEEK_SET) != shdr.sh_offset ||
|
||||||
read(fd, syms->symbols, shdr.sh_size) != shdr.sh_size)
|
(uintN_t) read(fd, syms->symbols, shdr.sh_size) != shdr.sh_size)
|
||||||
quit("Could not read symbol table.");
|
quit("Could not read symbol table.");
|
||||||
|
|
||||||
i = hdr->e_shoff + shdr.sh_link * hdr->e_shentsize;
|
i = hdr->e_shoff + shdr.sh_link * hdr->e_shentsize;
|
||||||
|
@ -449,8 +455,8 @@ static int find_stables(ElfN_Ehdr *hdr, int fd, Symbols syms)
|
||||||
quit("Could not read string table section header.");
|
quit("Could not read string table section header.");
|
||||||
if (!(syms->strings = malloc(shdr.sh_size)))
|
if (!(syms->strings = malloc(shdr.sh_size)))
|
||||||
quit("Could not allocate string table.");
|
quit("Could not allocate string table.");
|
||||||
if (lseek(fd, shdr.sh_offset, SEEK_SET) != shdr.sh_offset ||
|
if ((ElfN_Off) lseek(fd, shdr.sh_offset, SEEK_SET) != shdr.sh_offset ||
|
||||||
read(fd, syms->strings, shdr.sh_size) != shdr.sh_size)
|
(uintN_t) read(fd, syms->strings, shdr.sh_size) != shdr.sh_size)
|
||||||
quit("Could not read string table.");
|
quit("Could not read string table.");
|
||||||
lseek(fd, spot, SEEK_SET);
|
lseek(fd, spot, SEEK_SET);
|
||||||
break;
|
break;
|
||||||
|
@ -458,8 +464,8 @@ static int find_stables(ElfN_Ehdr *hdr, int fd, Symbols syms)
|
||||||
syms->ndyns = shdr.sh_size / sizeof(ElfN_Dyn);
|
syms->ndyns = shdr.sh_size / sizeof(ElfN_Dyn);
|
||||||
if (!(syms->dynamic = (ElfN_Dyn *) malloc(shdr.sh_size)))
|
if (!(syms->dynamic = (ElfN_Dyn *) malloc(shdr.sh_size)))
|
||||||
quit("Out of memory.");
|
quit("Out of memory.");
|
||||||
if (lseek(fd, shdr.sh_offset, SEEK_SET) != shdr.sh_offset ||
|
if ((ElfN_Off) lseek(fd, shdr.sh_offset, SEEK_SET) != shdr.sh_offset ||
|
||||||
read(fd, syms->dynamic, shdr.sh_size) != shdr.sh_size)
|
(uintN_t) read(fd, syms->dynamic, shdr.sh_size) != shdr.sh_size)
|
||||||
quit("Could not read dynamic table.");
|
quit("Could not read dynamic table.");
|
||||||
lseek(fd, spot, SEEK_SET);
|
lseek(fd, spot, SEEK_SET);
|
||||||
break;
|
break;
|
||||||
|
@ -477,6 +483,8 @@ static Symbols loadSyms(const char *fname)
|
||||||
|
|
||||||
if (*fname == '\0')
|
if (*fname == '\0')
|
||||||
return (Symbols) 0;
|
return (Symbols) 0;
|
||||||
|
if (!strcmp(VDSO_NAME, fname))
|
||||||
|
return (Symbols) 0;
|
||||||
syms = newSyms(fname);
|
syms = newSyms(fname);
|
||||||
if ((fd = open(fname, O_RDONLY)) < 0)
|
if ((fd = open(fname, O_RDONLY)) < 0)
|
||||||
{
|
{
|
||||||
|
@ -484,7 +492,12 @@ static Symbols loadSyms(const char *fname)
|
||||||
perror("opening object file");
|
perror("opening object file");
|
||||||
quit("Could not open object file.");
|
quit("Could not open object file.");
|
||||||
}
|
}
|
||||||
read(fd, &hdr, sizeof(hdr));
|
if (read(fd, &hdr, sizeof(hdr)) < (int) sizeof(hdr))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "'%s': ", fname);
|
||||||
|
perror("reading object file ELF header");
|
||||||
|
quit("Could not read object file ELF header.");
|
||||||
|
}
|
||||||
verify_ident(&hdr);
|
verify_ident(&hdr);
|
||||||
if (!find_stables(&hdr, fd, syms)) {
|
if (!find_stables(&hdr, fd, syms)) {
|
||||||
deleteSyms(syms);
|
deleteSyms(syms);
|
||||||
|
@ -542,16 +555,17 @@ static void resolveSymbols(Symbols syms, int offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadString(pid_t pid, ElfN_Addr addr, char *dp, int bytes)
|
static void loadString(pid_t pid, ElfN_Addr addr, char *dp, unsigned int bytes)
|
||||||
{
|
{
|
||||||
long *lp = (long *) dp, nr;
|
long *lp = (long *) dp;
|
||||||
|
unsigned int nr;
|
||||||
int error_occured = 0;
|
int error_occured = 0;
|
||||||
|
|
||||||
memset(dp, 0, bytes);
|
memset(dp, 0, bytes);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
addr = ptrace(PTRACE_PEEKDATA, pid, addr, 0);
|
addr = ptrace(PTRACE_PEEKDATA, pid, addr, 0);
|
||||||
if (addr == -1 && errno)
|
if (addr == (ElfN_Addr) -1 && errno)
|
||||||
error_occured = 0;
|
error_occured = 0;
|
||||||
|
|
||||||
for (nr = 0; bytes > sizeof(long) && strlen(dp) == nr;
|
for (nr = 0; bytes > sizeof(long) && strlen(dp) == nr;
|
||||||
|
@ -571,7 +585,7 @@ static void loadString(pid_t pid, ElfN_Addr addr, char *dp, int bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readLinkMap(int pid, ElfN_Addr base,
|
static void readLinkMap(int pid, ElfN_Addr base,
|
||||||
struct link_map *lm, char *name, int namelen)
|
struct link_map *lm, char *name, unsigned int namelen)
|
||||||
{
|
{
|
||||||
/* base address */
|
/* base address */
|
||||||
lm->l_addr = (ElfN_Addr) ptrace(PTRACE_PEEKDATA, pid,
|
lm->l_addr = (ElfN_Addr) ptrace(PTRACE_PEEKDATA, pid,
|
||||||
|
@ -640,12 +654,12 @@ static int crawl(int pid)
|
||||||
{
|
{
|
||||||
unsigned long pc, fp, nextfp, nargs, i, arg;
|
unsigned long pc, fp, nextfp, nargs, i, arg;
|
||||||
int ret, error_occured = 0;
|
int ret, error_occured = 0;
|
||||||
struct pt_regs regs;
|
DECLARE_REGS_STRUCT(regs);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
ret = ptrace(PTRACE_GETREGS, pid, NULL, ®s);
|
ret = ptrace(PTRACE_GETREGS, pid, NULL, ®s);
|
||||||
if (ret != -1 && !errno) {
|
if (ret != -1) {
|
||||||
pc = PROGRAM_COUNTER(regs);
|
pc = PROGRAM_COUNTER(regs);
|
||||||
fp = FRAME_POINTER(regs);
|
fp = FRAME_POINTER(regs);
|
||||||
}
|
}
|
||||||
|
@ -656,7 +670,7 @@ static int crawl(int pid)
|
||||||
print_pc(pc);
|
print_pc(pc);
|
||||||
for ( ; !error_occured && fp; ) {
|
for ( ; !error_occured && fp; ) {
|
||||||
nextfp = ptrace(PTRACE_PEEKDATA, pid, NEXT_FRAME_POINTER_ADDR(fp), 0);
|
nextfp = ptrace(PTRACE_PEEKDATA, pid, NEXT_FRAME_POINTER_ADDR(fp), 0);
|
||||||
if (nextfp == (unsigned) -1 && errno) {
|
if (nextfp == (unsigned long) -1 && errno) {
|
||||||
error_occured = 1;
|
error_occured = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -667,7 +681,7 @@ static int crawl(int pid)
|
||||||
fputs(" (", stdout);
|
fputs(" (", stdout);
|
||||||
for (i = 1; i <= nargs; i++) {
|
for (i = 1; i <= nargs; i++) {
|
||||||
arg = ptrace(PTRACE_PEEKDATA, pid, ARG_NMBR(fp,i), 0);
|
arg = ptrace(PTRACE_PEEKDATA, pid, ARG_NMBR(fp,i), 0);
|
||||||
if (arg == (unsigned) -1 && errno) {
|
if (arg == (unsigned long) -1 && errno) {
|
||||||
error_occured = 1;
|
error_occured = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -682,7 +696,7 @@ static int crawl(int pid)
|
||||||
|
|
||||||
if (error_occured || !nextfp) break;
|
if (error_occured || !nextfp) break;
|
||||||
pc = ptrace(PTRACE_PEEKDATA, pid, NEXT_PROGRAM_COUNTER_ADDR(fp), 0);
|
pc = ptrace(PTRACE_PEEKDATA, pid, NEXT_PROGRAM_COUNTER_ADDR(fp), 0);
|
||||||
if (pc == (unsigned) -1 && errno) {
|
if (pc == (unsigned long) -1 && errno) {
|
||||||
error_occured = 1;
|
error_occured = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -710,7 +724,7 @@ static char *cmdLine(int pid)
|
||||||
for (i = 0; i < len; i++) if (!cmd[i]) cmd[i] = ' ';
|
for (i = 0; i < len; i++) if (!cmd[i]) cmd[i] = ' ';
|
||||||
for ( ; len > 0 && cmd[len - 1] <= ' '; len--);
|
for ( ; len > 0 && cmd[len - 1] <= ' '; len--);
|
||||||
cmd[len] = 0;
|
cmd[len] = 0;
|
||||||
if (len >= sizeof(cmd) - 4)
|
if ((unsigned int) len >= sizeof(cmd) - 4)
|
||||||
strcpy(&cmd[sizeof(cmd) - 4], "...");
|
strcpy(&cmd[sizeof(cmd) - 4], "...");
|
||||||
} else printf("Could not read %s: %s\n", cmd, strerror(errno));
|
} else printf("Could not read %s: %s\n", cmd, strerror(errno));
|
||||||
if (fd < 0 || len <= 0) strcpy(cmd, "(command line?)");
|
if (fd < 0 || len <= 0) strcpy(cmd, "(command line?)");
|
||||||
|
@ -729,6 +743,7 @@ void usage(const char *argv0, const char *param)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
long thePidTmp;
|
||||||
const char *argv0 = argv[0];
|
const char *argv0 = argv[0];
|
||||||
|
|
||||||
/* Arrange to detach if we get an unexpected signal. This prevents
|
/* Arrange to detach if we get an unexpected signal. This prevents
|
||||||
|
@ -741,10 +756,11 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
for (argc--, argv++; argc > 0; argc--, argv++) {
|
for (argc--, argv++; argc > 0; argc--, argv++) {
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
thePid = strtol(*argv, &endptr, 0);
|
thePidTmp = strtol(*argv, &endptr, 0);
|
||||||
if (!*argv || *endptr || (errno == ERANGE &&
|
if (!*argv || *endptr || (errno == ERANGE &&
|
||||||
(thePid == LONG_MIN || thePid == LONG_MAX)))
|
(thePidTmp == LONG_MIN || thePidTmp == LONG_MAX)))
|
||||||
usage(argv0, *argv);
|
usage(argv0, *argv);
|
||||||
|
thePid = thePidTmp;
|
||||||
if (!thePid || thePid == getpid()) {
|
if (!thePid || thePid == getpid()) {
|
||||||
fprintf(stderr, "Invalid PID %d\n", thePid);
|
fprintf(stderr, "Invalid PID %d\n", thePid);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue