Example #1
0
int
sg_warn(const char *prefix)
{
	sg_error_details err_det;
	char *errmsg = NULL;
	int rc;
	sg_error errc;

	if( SG_ERROR_NONE != ( errc = sg_get_error_details(&err_det) ) ) {
		fprintf(stderr, "can't get error details (%d, %s)\n", errc, sg_str_error(errc));
		return 0;
	}

	if( NULL == sg_strperror(&errmsg, &err_det) ) {
		errc = sg_get_error();
		fprintf(stderr, "panic: can't prepare error message (%d, %s)\n", errc, sg_str_error(errc));
		return 0;
	}

	rc = fprintf( stderr, "%s: %s\n", prefix, errmsg );

	free( errmsg );

	return rc;
}
Example #2
0
static void
populate_proc(void) {
	/* FIXME expose individual process info too */
	sg_process_count *proc = sg_get_process_count();

	if (proc != NULL) {
		add_stat(UNSIGNED_LONG_LONG, &proc->total, "proc", "total", NULL);
		add_stat(UNSIGNED_LONG_LONG, &proc->running, "proc", "running", NULL);
		add_stat(UNSIGNED_LONG_LONG, &proc->sleeping, "proc", "sleeping", NULL);
		add_stat(UNSIGNED_LONG_LONG, &proc->stopped, "proc", "stopped", NULL);
		add_stat(UNSIGNED_LONG_LONG, &proc->zombie, "proc", "zombie", NULL);
	}
	else {
		char *errbuf;
		sg_error_details errdet;
		if( SG_ERROR_NONE != sg_get_error_details(&errdet) )
			return;
		if( NULL == sg_strperror( &errbuf, &errdet ) )
			return;
		fprintf( stderr, "%s\n", errbuf );
	}
}
void
DataSourceStatgrab::report_sg_error(string const &who, string const &what)
{
    sg_error_details err_det;
    char *errmsg = NULL;
    sg_error errc;

    if( SG_ERROR_NONE != ( errc = sg_get_error_details(&err_det) ) )
    {
        LOG_BEGIN( loggerModuleName, ERROR_LOG | 1 );
        LOG( string( string("report_sg_error(") + who + ", " + what + "): can't get error details - " + sg_str_error(errc) ).c_str() );
        LOG_END;
        return;
    }

    if( NULL == sg_strperror(&errmsg, &err_det) )
    {
        errc = sg_get_error();
        LOG_BEGIN( loggerModuleName, ERROR_LOG | 1 );
        LOG( string( string("report_sg_error(") + who + ", " + what + "): can't prepare error message - " + sg_str_error(errc) ).c_str() );
        LOG_END;
        return;
    }

    LOG_BEGIN( loggerModuleName, ERROR_LOG | 1 );
    if( errmsg )
    {
        LOG( string( who + ": " + what + " - " + errmsg ).c_str() );
    }
    else
    {
        LOG( string( who + ": " + what + " - " + sg_str_error( sg_get_error() ) + " - unknown details" ).c_str() );
    }
    LOG_END;

    free( errmsg );

    return;
}
Example #4
0
static void
sg_die(const char *prefix, int exit_code)
{
	sg_error_details err_det;
	char *errmsg = NULL;
	sg_error errc;

	if( SG_ERROR_NONE != ( errc = sg_get_error_details(&err_det) ) ) {
		fprintf(stderr, "panic: can't get error details (%d, %s)\n", errc, sg_str_error(errc));
		exit(exit_code);
	}

	if( NULL == sg_strperror(&errmsg, &err_det) ) {
		errc = sg_get_error();
		fprintf(stderr, "panic: can't prepare error message (%d, %s)\n", errc, sg_str_error(errc));
		exit(exit_code);
	}

	fprintf( stderr, "%s: %s\n", prefix, errmsg );

	free( errmsg );

	exit(exit_code);
}
Example #5
0
char *
sg_strperror(char **buf, const sg_error_details * const err_details) {

#ifdef HAVE_STRERROR_R
	char errno_buf[128] = { '\0' };
#endif
	char *errno_msg = NULL;
	sg_error_details err_det;

	if((NULL == buf) || (NULL != *buf)) {
		sg_set_error_int(SG_ERROR_INVALID_ARGUMENT, 0, "strperror", empty_ap);
		return NULL;
	}

	if(NULL == err_details) {
		sg_get_error_details(&err_det);
	}
	else {
		err_det = *err_details;
	}

	if( NULL != (*buf = malloc(SG_STRPERROR_BUF_SIZE)) ) {
		if(err_det.errno_value) {
#ifdef HAVE_STRERROR_R
# ifdef STRERROR_R_RETURN_INT
			int rc;
# else
			char *rc;
# endif
			rc = strerror_r(err_det.errno_value, errno_buf, sizeof(errno_buf));
# ifdef STRERROR_R_RETURN_INT
			if(0 != rc)
# else
			if(NULL == rc)
# endif
			{
				sg_set_error_int(SG_ERROR_MALLOC, errno, "strerror_r", empty_ap);
				free(*buf);
				*buf = NULL;
				return NULL;
			}
			else {
# ifdef STRERROR_R_RETURN_INT
				errno_msg = errno_buf;
# else
				errno_msg = rc;
# endif
			}
#else
			errno_msg = strerror(errno);
#endif
		}

		snprintf( *buf, SG_STRPERROR_BUF_SIZE, "%s (%s%s%s)",
			  sg_str_error(err_det.error),
			  err_det.errno_value ? errno_msg : "",
			  err_det.errno_value ? ": " : "",
			  err_det.error_arg ? err_det.error_arg : "" );

	}
	else {
		sg_set_error_int(SG_ERROR_MALLOC, 0, "sg_strperror", empty_ap);
	}

	return *buf;
}