Jump to content

Problem with File Descriptors

Recommended Posts

I am having an issue using the extra file descriptors possible via use of the -cloudserver argurment.

I am starting the server using the following code (some vars left out)

fd3, fd4 = os.pipe()
server_process = subprocess.Popen([f"{install_dir}/bin64/dontstarve_dedicated_server_nullrenderer_x64",
     "-cluster", "TestServer", "-shard", "Master", "-cloudserver"],pass_fds=(fd3, fd4),cwd=bin_dir)

I then attempt to write to the fds using this code:

write_path = f"/proc/{pid}/fd/3"
read_path = f"/proc/{pid}/fd/4"

wf = os.open(write_path, os.O_RDWR | os.O_SYNC)
ret = os.write(wf, bytes('c_announce("Test")\n', "utf-8"))
print(f"After OS Write {ret}")
print("After OS Close")

Once again, some vars left out.

The command executes okay, the problem is that after executing the command the console gets spammed with "attempt to call a nil value"

I don't know if I have done something foolish, but if you can help me out with this it would be greatly appreciated.

Link to comment
Share on other sites

  • Developer

fd3 and fd4 are the opposite ends of the same pipe in your example code. That would have the server talking to itself.

You want to create multiple pipes, in each case you'll keep one end for yourself and give the other end to the DST process. Which end is which will depend on if that FD is for reading or writing.


Link to comment
Share on other sites

fd3, stdin = os.pipe()
stdout, fd4 = os.pipe()
server_process = subprocess.Popen([f"{install_dir}/bin64/dontstarve_dedicated_server_nullrenderer_x64",
     "-cluster", "Server1", "-shard", "Master", "-cloudserver"],pass_fds=(fd3, fd4), cwd=bin_dir, stdin=stdin, stdout=stdout)

I changed my pipes like so and this is working great. Is this the correct way to do it?

If this is the correct way, does fd5 just map to stderr?

Apologies for the silly questions I am new to programming and this is all very confusing.

Link to comment
Share on other sites

  • Developer

0 is stdin

1 is stdout

2 is stderr

3 & 4 are special additional FDs that let you communicate with DST servers in additional ways. Off the top of my head I forget which is which is read and which is write though. :wilson_smile:

Link to comment
Share on other sites

  • Developer

Thanks, that's the post I was going to google up if you asked. :)

So yes, for fd 3 you keep the write half of the pipe and give the read half to DST. For fd4 & fd5 you keep the read half.

Combined with stdin/stdout/stderr (where you have the write, read and read ends of the pipes respectively) you'll have a whole bunch of channels for speaking to DST

Link to comment
Share on other sites

I'm sorry to keep bugging you with this, I know you must be busy. but I have made some progress with these additional FDs but have hit another roadblock:

fd3, ex3 = os.pipe()
ex4, fd4 = os.pipe()
ex5, fd5 = os.pipe()
server_process = subprocess.Popen([f"{install_dir}/bin64/dontstarve_dedicated_server_nullrenderer_x64",
     "-cluster", "Server1", "-shard", "Master", "-cloudserver"], pass_fds=(fd3, fd4, fd5), cwd=bin_dir)

I split the pipes down for the 3 additional FDs, with this setup, I can send data into ex3 and it will correctly send to the server and will be actioned. The issue I am seeing is that I do not get any output from ex4 an ex5 at all in this example.

I noticed in the post, there was mention of possible documentation around this. Has this been created or do you have any examples I can work from?

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...