jerome-pouiller / reredirect Goto Github PK
View Code? Open in Web Editor NEWTool to dynamicly redirect outputs of a running process
License: MIT License
Tool to dynamicly redirect outputs of a running process
License: MIT License
Hey, this tool saved me. Thanks!
What do you think about putting it in https://aur.archlinux.org ?
I'm using command "reredirect -m /tmp/logfile.txt PID" for redirect log of the application to logfile.txt. But I was checked the log file after short time. Some information of the log file is lost. Example:
Log file before:
[20180806 19:00] String in log file
[20180806 19:01] String in log file
[20180806 19:02] String in log file
[20180806 19:03] String in log file
New log file in the short time when I get from the log file:
[20180806 19:01] String in log file
[20180806 19:02] String in log file
[20180806 19:03] String in log file
[20180806 19:04] String in log file
[20180806 19:05] String in log file
=>The string "[20180806 19:00] String in log file" is lost after redirect in the short time.
The log only store between 24h. If the log has two string the same time, reredirect will remove one string.
Please help me to check the issue. Thank you
redirect can not catch the output of nodejs process.
Readme.md says that "Ports to other architectures should be straightforward, and should in most cases be as simple as adding an arch/ARCH.h file and adding a clause to the ifdef ladder in ptrace.c."
But I have no knowlesge of assembly. What should be done to create a valid mips.h?
During compilation on aarch64 target, I got an incomplete type for user struct:
ptrace.h:62:17: error: field ‘user’ has incomplete type
62 | struct user user;
Are you aware of any resolution for this?
attach.c: In function ‘child_open’:
attach.c:94:9: warning: ‘strncat’ specified bound 4097 equals destination size [-Wstringop-overflow=]
94 | strncat(buf, "/", sizeof(buf));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello
I've been using reredirect with no issues on arm but i recently saw this error
Unable to open the file in the child
i traced the code but was not sure of the cause. does anyone have any thoughts?
thanks
There is no configure file, so how can I cross-compile reredirect for ARM?
What would cause this to occur? It happens on almost every single process on one linux box and not on the other (running same firmwares and programs). Hoping it's a simple fix!
If target process's stdout was redirected, it is full buffered(size=4096) in general.
# reredirect -m /tmp/log PID
# tail -f /tmp/log
if stdout
is set to line buffered, then the tail
output will be immediate.
Maybe should do the following operation automatically after attached:
setvbuf(stdout, NULL, _IOLBF, 0);
see also:
I ran into a bug that reredirect hung forever, and the strace(1)
output is collected as followed:
# strace -fT reredirect -m rere-shim.log 365991
execve("/usr/local/bin/reredirect", ["reredirect", "-m", "rere-shim.log", "365991"], [/* 18 vars */]) = 0
<0.000142>
brk(NULL) = 0x1bc2000 <0.000010>
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) <0.000012>
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) <0.000010>
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 <0.000012>
fstat(3, {st_mode=S_IFREG|0644, st_size=36276, ...}) = 0 <0.000010>
mmap(NULL, 36276, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f8e37c34000 <0.000011>
close(3) = 0 <0.000010>
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) <0.000010>
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 <0.000011>
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\t\2\0\0\0\0\0"..., 832) = 832 <0.000010>
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0 <0.000010>
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8e37c33000 <0.000010>
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8e3764e000 <0.000010>
mprotect(0x7f8e3780e000, 2097152, PROT_NONE) = 0 <0.000013>
mmap(0x7f8e37a0e000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7f
8e37a0e000 <0.000013>
mmap(0x7f8e37a14000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8e37a1
4000 <0.000011>
close(3) = 0 <0.000009>
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8e37c32000 <0.000010>
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8e37c31000 <0.000010>
arch_prctl(ARCH_SET_FS, 0x7f8e37c32700) = 0 <0.000009>
mprotect(0x7f8e37a0e000, 16384, PROT_READ) = 0 <0.000012>
mprotect(0x603000, 4096, PROT_READ) = 0 <0.000011>
mprotect(0x7f8e37c3d000, 4096, PROT_READ) = 0 <0.000011>
munmap(0x7f8e37c34000, 36276) = 0 <0.000015>
ptrace(PTRACE_ATTACH, 365991, NULL, NULL) = 0 <0.000024>
kill(365991, SIGCONT) = 0 <0.000015>
wait4(365991,
There should have been a SIGCHLD triggered by SIGSTOP or SIGCONT, and the missing signal made wait4(2)
hang forever.
This situation was likely caused by SIGSTOP followed by SIGCONT. According to the man7:
instant SIGCONT after SIGSTOP may be discarded, as a result the tracer won't receive any signal and will end with endless wait4(2)
.
I can demonstrate this by very simple programs.
First prepare a python script:
import os
import time
pid = os.fork()
if pid:
print(pid)
while 1:
os.waitpid(-1, os.WSTOPPED|os.WCONTINUED)
print('waited')
else:
time.sleep(1000)
Then compose a c program:
#include <signal.h>
#include<stdlib.h>
void main(int argc, char **argv) {
int pid = atoi(argv[1]);
kill(pid, SIGSTOP);
kill(pid, SIGCONT);
}
Then run the python script and run the c program to send signals to the child python process. On my test env, the sent signals won't trigger waitpid(2)
at all.
My recommendation for revise is to use PTRACE_SEIZE
instead of PTRACE_ATTACH
+ SIGCONT
:
I believe that can eradicate the issue.
This is the output of make
:
cc -Wall -g -c -o reredirect.o reredirect.c
cc -Wall -g -c -o ptrace.o ptrace.c
In file included from ptrace.c:82:
arch/amd64.h:84: error: request for member ‘nr_dup’ in something not a structure or union
make: *** [ptrace.o] Error 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.