@@ -4080,58 +4080,47 @@ void sinsp_parser::parse_setsid_exit(sinsp_evt &evt) {
40804080}
40814081
40824082void sinsp_parser::parse_getsockopt_exit (sinsp_evt &evt, sinsp_parser_verdict &verdict) const {
4083- const sinsp_evt_param *parinfo;
4084- int64_t retval;
4085- int8_t level, optname;
4086-
40874083 if (evt.get_tinfo () == nullptr ) {
40884084 return ;
40894085 }
40904086
4091- // right now we only parse getsockopt() for SO_ERROR options
4092- // if that ever changes, move this check inside
4093- // the `if (level == PPM_SOCKOPT_LEVEL_SOL_SOCKET ...)` block
4087+ // Right now we only parse getsockopt() for SO_ERROR options. If that ever changes, move this
4088+ // check inside the `if (level == PPM_SOCKOPT_LEVEL_SOL_SOCKET ...)` block.
40944089 if (!m_track_connection_status) {
40954090 return ;
40964091 }
40974092
4098- //
4099- // Extract the return value
4100- //
4101- retval = evt.get_syscall_return_value ();
4102-
4103- if (retval < 0 ) {
4093+ if (evt.get_syscall_return_value () < 0 ) {
41044094 return ;
41054095 }
41064096
4107- level = evt.get_param (2 )->as <int8_t >();
4108-
4109- optname = evt.get_param (3 )->as <int8_t >();
4097+ const auto level = evt.get_param (2 )->as <int8_t >();
4098+ const auto optname = evt.get_param (3 )->as <int8_t >();
4099+ if (level != PPM_SOCKOPT_LEVEL_SOL_SOCKET || optname != PPM_SOCKOPT_SO_ERROR) {
4100+ return ;
4101+ }
41104102
4111- if (level == PPM_SOCKOPT_LEVEL_SOL_SOCKET && optname == PPM_SOCKOPT_SO_ERROR) {
4112- parinfo = evt.get_param (4 );
4113- ASSERT (*parinfo->data () == PPM_SOCKOPT_IDX_ERRNO);
4114- ASSERT (parinfo->len () == sizeof (int64_t ) + 1 );
4115- const auto err = *reinterpret_cast <const int64_t *>(
4116- parinfo->data () + 1 ); // add 1 byte to skip over PT_DYN param index
4103+ const auto val_param = evt.get_param (4 );
4104+ ASSERT (*val_param->data () == PPM_SOCKOPT_IDX_ERRNO);
4105+ ASSERT (val_param->len () == sizeof (int64_t ) + 1 );
4106+ const auto err = *reinterpret_cast <const int64_t *>(
4107+ val_param->data () + 1 ); // Add 1 byte to skip over PT_DYN param index.
41174108
4118- evt.set_errorcode (static_cast <int32_t >(err));
4119- if (evt.get_fd_info () != nullptr ) {
4120- if (err < 0 ) {
4121- evt.get_fd_info ()->set_socket_failed ();
4122- } else {
4123- evt.get_fd_info ()->set_socket_connected ();
4124- }
4125- }
4126- //
4127- // If there's a listener, add a callback to later invoke it.
4128- //
4129- if (m_observer) {
4130- verdict.add_post_process_cbs ([](sinsp_observer *observer, sinsp_evt *evt) {
4131- observer->on_socket_status_changed (evt);
4132- });
4109+ evt.set_errorcode (static_cast <int32_t >(err));
4110+ if (evt.get_fd_info () != nullptr ) {
4111+ if (err < 0 ) {
4112+ evt.get_fd_info ()->set_socket_failed ();
4113+ } else {
4114+ evt.get_fd_info ()->set_socket_connected ();
41334115 }
41344116 }
4117+
4118+ // If there's a listener, add a callback to later invoke it.
4119+ if (m_observer) {
4120+ verdict.add_post_process_cbs ([](sinsp_observer *observer, sinsp_evt *evt) {
4121+ observer->on_socket_status_changed (evt);
4122+ });
4123+ }
41354124}
41364125
41374126void sinsp_parser::parse_capset_exit (sinsp_evt &evt) {
0 commit comments