Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive mode is unuseable #73

Open
melonlm opened this issue Feb 5, 2024 · 5 comments
Open

Interactive mode is unuseable #73

melonlm opened this issue Feb 5, 2024 · 5 comments

Comments

@melonlm
Copy link

melonlm commented Feb 5, 2024

Issuing commands in interactive mode results in error loop of

"send error: Socket operation on non-socket"

I tracked it down in the code to the fact that even in interactive mode the program wants to send the responses back using
socket_send( ) function, but using file descriptor "1" (STDOUT stream), which causes the socket lib to error out.

OS is Debian, from Stable to Sid, kernels : 6.1 and 6.7, arch amd64 and arm64.

melonlm referenced this issue Feb 5, 2024
@worikgh
Copy link

worikgh commented Feb 5, 2024

I came here to report the same issue.

I have mine working now

    // Protocol OK
    if (index >= 0)
      {
        if (g_commands[index].callback)
	  {
            g_commands[index].callback(&proto);
            if (proto.response)
	      {
		if(msg->sender_id > 3){
		  SEND_TO_SENDER(msg->sender_id, proto.response, proto.response_size);
		}else{
		  fprintf(stdout, "%s\n", proto.response);
		}
		if (g_verbose) printf("PROTOCOL: response '%s'\n", proto.response);

                FREE(proto.response);
	      }
	  }
      }
    // Protocol error
    else
      {
	if(msg->sender_id > 3){
	  SEND_TO_SENDER(msg->sender_id, g_error_messages[-index-1], strlen(g_error_messages[-index-1]));
	}else{
	  fprintf(stdout, "%s\n", g_error_messages[-index-1]);
	}
	if (g_verbose) printf("PROTOCOL: error '%s'\n", g_error_messages[-index-1]);
      }

That is a bit hairy. But I do not think a socket file number can be less than 3, I just cannot find documentation for that.

@melonlm
Copy link
Author

melonlm commented Feb 6, 2024

Looks like it is a POSIX thing. FDs 0, 1 and 2 are supposed to be standard streams: https://en.wikipedia.org/wiki/File_descriptor
So the patch is ok I suppose?

@worikgh
Copy link

worikgh commented Feb 8, 2024

My workaround is just a workaround

The problem of getting into an infinite loop I have not looked at, yet.

@melonlm
Copy link
Author

melonlm commented Feb 9, 2024

The infinite loop issue is due to missing return (or break) statement after perror() is called in SEND_TO_SENDER function.

See comments here: c69480e

@riban-bw
Copy link

riban-bw commented Jul 3, 2024

Looks like it is a POSIX thing. FDs 0, 1 and 2 are supposed to be standard streams: https://en.wikipedia.org/wiki/File_descriptor

By convention, a shell based / launched application will use file descriptors 0, 1 & 2 for std in, out & err but this does not need to be the case and this behaviour can be changed. One should never assume that the first three file descriptors are used by in/out/err.

I found this issue wieht continual send error messages which seems to be in the code base for a while. I wonder when the last person to use / test interactive mode was?

This is a significant issue. Do we need to submit a PR to fix it?

riban-bw added a commit to riban-bw/mod-host that referenced this issue Jul 7, 2024
Check if command response is for fd 1.
@riban-bw riban-bw mentioned this issue Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants