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

fix: make monitor more readable #3702

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

anoushk1234
Copy link
Contributor

@anoushk1234 anoushk1234 commented Dec 14, 2024

Fixes #3676

@anoushk1234 anoushk1234 force-pushed the anoushk1234/sep-monitor-panes branch from 2c11519 to b1bc7f1 Compare December 17, 2024 13:21
@anoushk1234
Copy link
Contributor Author

Hey @ripatel-fd did you get a chance to review this yet?

@anoushk1234
Copy link
Contributor Author

Also the sandbox prevents reading STDIN preventing tab switching in the monitor, is there a way to allow that for non dev builds without disabling the sandbox?

Signed-off-by: Anoushk Kharangate <[email protected]>
@anoushk1234 anoushk1234 force-pushed the anoushk1234/sep-monitor-panes branch from b1bc7f1 to 84fd7c0 Compare December 17, 2024 13:52
@ripatel-fd
Copy link
Contributor

Hey @ripatel-fd did you get a chance to review this yet?

@anoushk1234 Thank you for the contribution! I tagged @mmcgee-jump for review.

Also the sandbox prevents reading STDIN preventing tab switching in the monitor, is there a way to allow that for non dev builds without disabling the sandbox?

Yes, the syscall policy for the monitor is defined in src/app/fdctl/monitor/monitor.seccomppolicy.
You'd probably want to amend the expression for the read syscall to allow file descriptor 0 (stdin).

@anoushk1234
Copy link
Contributor Author

Hey @ripatel-fd did you get a chance to review this yet?

@anoushk1234 Thank you for the contribution! I tagged @mmcgee-jump for review.

Also the sandbox prevents reading STDIN preventing tab switching in the monitor, is there a way to allow that for non dev builds without disabling the sandbox?

Yes, the syscall policy for the monitor is defined in src/app/fdctl/monitor/monitor.seccomppolicy. You'd probably want to amend the expression for the read syscall to allow file descriptor 0 (stdin).

Thanks! @ripatel-fd Let me push the updated policy

@ripatel-fd
Copy link
Contributor

Thanks! @ripatel-fd Let me push the updated policy

Great, thanks! I forgot to mention, could you please also run make seccomp-policies to regenerate the C header files created from those seccomp policy files?

@@ -107,4 +107,6 @@ printf_pct( char ** buf,
ulong den_then,
double lhopital_den );

int
fd_getch(void);
Copy link
Contributor

@ripatel-fd ripatel-fd Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add documentation what this function does?

Suggested change
fd_getch(void);
/* fd_getch silently reads a single character. The terminal is temporarily switched
to non-canonical non-echo mode. */
fd_getch( void );

Comment on lines +180 to +203
int
fd_getch()
{
struct termios oldt, newt;
int ch;
int oldf;
/* Disables character echo and canonical mode since we want the input to be processes immediately.
* Terminal also set to non blocking in case the user doesn't send any input.
* */
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= (tcflag_t)~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);

ch = getchar();

/*Restore the terminal back to it's original configuration*/
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);

return ch;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple code style suggestions, some of which are in https://github.com/firedancer-io/firedancer/blob/main/CONTRIBUTING.md

  • We follow the C strict prototypes rule where we use void to signal a blank argument list.
  • The curly goes on the same line as the method definition
int
fd_getch( void ) {
  • Comment style looks like this:
  /* Disables character echo and canonical mode since we want the input to be processes immediately.
     Terminal also set to non blocking in case the user doesn't send any input. */
  • Variable declarations go as close as possible to the definition
  • libc library functions should do error handling
  • Spaces inside brackets when doing control flow statements and function calls
  struct termios oldt;
  if( FD_UNLIKELY( 0!=tcgetattr( STDIN_FILENO, &oldt ) ) ) {
    ... handle error ...
  }
  struct termios newt = oldt;
  newt.c_lflag &= (tcflag_t)~(ICANON | ECHO);

Copy link
Contributor

@ripatel-fd ripatel-fd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. It looks good overall. I posted a couple nits above.

src/app/fdctl/monitor/monitor.c Outdated Show resolved Hide resolved
@@ -293,8 +293,9 @@ run_monitor( config_t * const config,
if( FD_UNLIKELY( (ulong)n>=buf_sz ) ) FD_LOG_ERR(( "snprintf truncated" )); \
buf += n; buf_sz -= (ulong)n; \
} while(0)

#define TAB 9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be more readable to use \t instead of a TAB define

tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= (tcflag_t)~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can leave this enabled all the time? 🤔
I'm not sure whether that's a good idea though since it requires extra care to restore the terminal when the user exits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can leave this enabled all the time? 🤔 I'm not sure whether that's a good idea though since it requires extra care to restore the terminal when the user exits.

The terminal restores back fine even if I leave it on so I don't see any issues if you think that's better. It would save us calls to ioctl.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better metrics rendering in monitor
2 participants