LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Making syscall chdir permanent when app ends (https://www.linuxquestions.org/questions/programming-9/making-syscall-chdir-permanent-when-app-ends-512947/)

mcamember 12-22-2006 02:46 PM

Making syscall chdir permanent when app ends
 
I can get syscall chdir (eax=12 / int 0x80) to work correctly but I'd like the directory to remain changed when the app ends. Is there a syscall equivalent to "set current directory" ?

I've read jilliagre's post on the unique nature of chdir but hope
I don't need to get involved with the parent shell.

This is the applicable section of jilliagre's post:

;----------------
. . . in the old system chdir was an ordinary command; it adjusted the current directory of the (unique) process attached to the terminal. Under the new system, the chdir command correctly changed the current directory of the process created to execute it, but this process promptly terminated and had no effect whatsoever on its parent shell! It was necessary to make chdir a special command, executed internally within the shell. It turns out that several command-like functions have the same property, for example login.
;----------------

Thanks in advance.

Hko 12-22-2006 03:20 PM

Quote:

Originally Posted by mcamember
I can get syscall chdir (eax=12 / int 0x80) to work correctly but I'd like the directory to remain changed when the app ends. Is there a syscall equivalent to "set current directory"

Sorry, but this is not really possible this way under UN*X-like operating systems.

The way around it would be something like:
  1. Fork an new shell from you program.
  2. Kill the parent process of you program.
  3. Have your program exit.

mcamember 12-22-2006 03:55 PM

Thanks Hko. Now, at least, I won't waste any more time searching for something which doesn't exist.

jlliagre 12-22-2006 04:18 PM

Quote:

Originally Posted by mcamember
I can get syscall chdir to work correctly but I'd like the directory

which one ?
Quote:

to remain changed when the app ends.
After an application ends, it has no more a current directory so I assume you mean the parent process one.

Each process has its own "current directory".
Assuming you find a way to have the parent's current directory "inherited" from its dying child, that would generate a big mess as daemons / process leaders see their current directory more or less randomly changed during their own lifetime.

mcamember 12-22-2006 07:03 PM

Quote:

Originally Posted by jlliagre
which one ?

The destination directory. If chdir moved from /home to /home/.mozilla while the application was processing I wanted the command prompt to remain in /home/.mozilla after the application terminated.

I wanted it to act the same as if cd home/.mozilla were issued from the command prompt.
But the application is a trivial utility and certainly not worth
endangering the stability of the o.s.

Thanks very much for your time jlliagre.


All times are GMT -5. The time now is 12:43 AM.