pyrasite icon indicating copy to clipboard operation
pyrasite copied to clipboard

Support fifos as payload for pyrasite cli tool

Open spaceone opened this issue 9 years ago • 1 comments

Code in a fifo is not executed while the exit code doesn't complain.

# pyrasite 23079 <(echo "import resource; resource.setrlimit(resource.RLIMIT_NOFILE, (10, 10))"); echo $?
0
# grep files /proc/23079/limits 
Max open files            1024                 4096                 files   
# echo "import resource; resource.setrlimit(resource.RLIMIT_NOFILE, (10, 10))" > /tmp/payload
# pyrasite 23079 /tmp/payload
# grep files /proc/23079/limits 
Max open files            10                   10                   files  

spaceone avatar Apr 22 '16 05:04 spaceone

This issue/feature came up on irc today.

13:26 <     Xenthys> | why is it mandatory to give a filename for a payload, can't we pass     
          some code through a pipe?                                                            
13:27  Xenthys> like : echo "x = 5" | pyrasite PID                                             
14:48  lmacken> Xenthys: that would be a great feature to have                                 
14:49 <     Xenthys> | or allow the "-" as a file to read the STDIN :)                         
14:50  lmacken> Feel free to file an issue on github for it. Doesn't seem like it would be     
                very difficult.                                                                
14:50 <     Xenthys> | well, I don't know what the best method would be                        
14:50  lmacken> I think we can use the 'fileinput' module to accept stdin or a filename. I use 
                it here: https://github.com/lmacken/tbgrep/blob/master/tbgrep/commands.py#L33
14:51  lmacken> https://docs.python.org/2/library/fileinput.html
14:51  lmacken> I'm going to put some cycles into pyrasite next week at PyCon... if you file 
                an issue I'll try and have a look, unless you get to the PR before me :)
14:53  Xenthys> Well, I don't know Python enough to adapt Pyrasite to take code from STDIN
14:53 <     Xenthys> | the documentation on fileinput isn't really detailed
14:54 <     Xenthys> | and btw, I tried to use a fifo to emulate the STDIN reading
14:55  Xenthys> mkfifo <name> && pyrasite PID <name>
14:55  lmacken> import fileinput              
14:55  lmacken> payload = ''                  
14:55  lmacken> for line in fileinput.input():
14:55  lmacken>     payload += line + '\n'    
14:55  lmacken> I think that's basically it

lmacken avatar May 25 '16 20:05 lmacken