home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / sun / apps / 3068 < prev    next >
Encoding:
Internet Message Format  |  1993-01-23  |  1.5 KB

  1. Xref: sparky comp.sys.sun.apps:3068 comp.unix.programmer:6032 comp.unix.internals:2151
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!pyrite!edvax
  3. From: edvax@pyrite.som.cwru.edu (Ed Reznichenko)
  4. Newsgroups: comp.sys.sun.apps,comp.unix.programmer,comp.unix.internals
  5. Subject: modifying ARGV within a running program
  6. Date: 23 Jan 1993 06:11:35 GMT
  7. Organization: WSOM CSG, CWRU, Cleve. OH
  8. Lines: 33
  9. Distribution: world
  10. Message-ID: <1jqninINNa8l@usenet.INS.CWRU.Edu>
  11. NNTP-Posting-Host: pyrite.som.cwru.edu
  12. X-Post-Machine: pyrite.som.cwru.edu
  13.  
  14.  
  15.  
  16. Platform: SunOS4.1
  17. Hardware: SPARC IPC
  18.  
  19. Hi,
  20.  
  21. Does anyone know how to SAFELY modify (i.e. change) the argument vector inside
  22. a running program so that when you do a ps it is picked up. I.e. I think
  23. the C-runtime crt0.o sets up argv[0]...argv[n] on the stack followed by
  24. the actual strings.  But once a program is execve'd, I can't seem
  25. to realloc/malloc that area.  I got it to work for the case where you
  26. specify sufficiently long arguments to the program and then overwrite them.
  27.  
  28. The example below demonstrates what I do:
  29.  
  30.     you invoke your program (called xyz) with arguments abc def:
  31.     xyz abc def
  32.     but you want ps auxww, to show FOO arg0 arg1, so:
  33.  
  34.     sprintf(argv[-1],"FOO arg0 arg1");
  35.  
  36. for some reason I have to put argv[-1], because argv[0] maps to argv[1]
  37. when I do a ps.  This seems to work but I do not feel secure enough about it.
  38. Any ideas on how to do this portably (if at all) would be appreciated.
  39.  
  40. Thanks,
  41.  
  42. --ed
  43.  
  44.  
  45. --
  46. Bus error, core dumped
  47.