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; }
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; }
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); }