void trace_manager::register_trace()

in krabs/krabs/etw.hpp [309:346]


    void trace_manager<T>::register_trace()
    {
        trace_info info = fill_trace_info();

        ULONG status = StartTrace(&trace_.registrationHandle_,
                                  trace_.name_.c_str(),
                                  &info.properties);
        if (status == ERROR_ALREADY_EXISTS) {
            try {
                stop_trace();
                status = StartTrace(&trace_.registrationHandle_,
                    trace_.name_.c_str(),
                    &info.properties);
            }
            catch (need_to_be_admin_failure) {
                (void)open_trace();
                close_trace();
                // insufficient privilege to stop/configure
                // but if open/close didn't throw also
                // then we're okay to process events
                status = ERROR_SUCCESS;
                // we also invalidate the registrationHandle_
                // StartTrace() actually sets this to 0 on failure
                trace_.registrationHandle_ = INVALID_PROCESSTRACE_HANDLE;
            }
            catch (invalid_parameter) {
                // In some versions, the error code is 87 when using
                // SystemTraceControlGuid session. If open/close doesn't
                // throw, then we can continually processing events.
                (void)open_trace();
                close_trace();
                status = ERROR_SUCCESS;
                trace_.registrationHandle_ = INVALID_PROCESSTRACE_HANDLE;
            }
        }

        error_check_common_conditions(status);
    }