开发者

Why does an RPC call fail in a C program called from Groovy on Linux?

开发者 https://www.devze.com 2023-01-13 03:27 出处:网络
We have a program, written in C, that uses RPC to communicate with another program (also written in C) on the same Linux server (in some production setups, the second C program would on another machin

We have a program, written in C, that uses RPC to communicate with another program (also written in C) on the same Linux server (in some production setups, the second C program would on another machine, therefore RPC instead of IPC).

When called from other C pr开发者_Python百科ograms, CRON or the command line, it works as expected and has been doing so for many years, so it's safe to say it generally works.

The same program, called from a Groovy script, fails, apparently with network problems.

In the C program, svc_register(xprt, prognum, versnum, dispatch, protocol) succeeds, but then

  • on the RPC server after request: clnttcp_create fails with "connection refused"
  • on the RPC client waiting for reply: select on svc_fdset fails with EBADF

Groovy program (just for completeness, not much to see here):

[ "myprogram", "someoption", "someprogram" ].execute()

What could we try to pinpoint and fix the problem?


Apparently, calling RPC based C-programs from Groovy does indeed work.

The problem could be narrowed down to the issue that "(int)sysconf (_SC_OPEN_MAX)", which is used to determine the number of fds in svc_fdset (a structure used to get replies from rpc-requests) does fail in case of being used by a C program called from Groovy.


Run the program through strace, to see what system call(s) is/are failing.


Check whether myprogram has output or waits for input. If you don't read the output or close the input, then it will hang, leading to timeouts in the RPC call. Create a thread which reads in and err of myprogram and close out:

def p = [ "myprogram", "someoption", "someprogram" ].execute()
p.out.close()
p.consumeProcessOutput()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号