Newsgroups: comp.unix.programmer
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!news
From: flee@cs.psu.edu (Felix Lee)
Subject: Re: how to change parent environment?
Message-ID: <#tG6d_+1@cs.psu.edu>
Sender: news@cs.psu.edu (Usenet)
Nntp-Posting-Host: dictionopolis.cs.psu.edu
Organization: Penn State Computer Science
References: <1991May2.194624.21819@kong.gsfc.nasa.gov>
Distribution: usa
Date: Fri, 3 May 91 11:36:21 GMT
Lines: 13

>How do you change the current working directory in a program, so
>that when the program is invoked from a shell, the cwd stays
>changed after the program exits?

Use ptrace().  In the child process you PTRACE_ATTACH the parent, save
the pc and registers and errno, find some spare room in the parent's
address space, write some code that will call chdir() and stop,
continue the parent at the code you've inserted, restore the pc and
registers and errno, and PTRACE_DETACH.

Implementation left as an exercise to the reader.
--
Felix Lee	flee@cs.psu.edu
