I have a select based server system, where I can manage multiple clients. The server automatically reads and responds to the client, which is great. But there's a minor issue. For instance user#1 changes directory (coded with chdir
), all of the other users are affected by this change. I really do wish that prevented for happening.
There's two ways to solve this:
Fork off a separate process to handle each connection. This process can have its own state, including current working directory. The disadvantages are that you'll need to refactor your code quite a lot, and if you have a lot of concurrent connections then it can be a performance problem. This is harder on Windows that *nix, but not impossible.
Keep the current directory as a per-connection setting within your program, and (re)set the directory before executing every user command.