-
Notifications
You must be signed in to change notification settings - Fork 193
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
base: main
Are you sure you want to change the base?
fix: make monitor more readable #3702
Conversation
2c11519
to
b1bc7f1
Compare
Hey @ripatel-fd did you get a chance to review this yet? |
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]>
b1bc7f1
to
84fd7c0
Compare
@anoushk1234 Thank you for the contribution! I tagged @mmcgee-jump for review.
Yes, the syscall policy for the monitor is defined in |
Thanks! @ripatel-fd Let me push the updated policy |
Great, thanks! I forgot to mention, could you please also run |
@@ -107,4 +107,6 @@ printf_pct( char ** buf, | |||
ulong den_then, | |||
double lhopital_den ); | |||
|
|||
int | |||
fd_getch(void); |
There was a problem hiding this comment.
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?
fd_getch(void); | |
/* fd_getch silently reads a single character. The terminal is temporarily switched | |
to non-canonical non-echo mode. */ | |
fd_getch( void ); |
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; | ||
} |
There was a problem hiding this comment.
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);
There was a problem hiding this 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.
@@ -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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me 👍
Co-authored-by: ripatel-fd <[email protected]>
Fixes #3676