void pdc_set_warnmsg( pdc_core * pdc, int errnum, const char *parm1, const char *parm2, const char *parm3, const char *parm4) { char errbuf[PDC_ERRBUF_SIZE]; strcpy(errbuf, pdc->pr->errbuf); if (errnum != -1) { const pdc_error_info *ei = get_error_info(pdc, errnum); make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_false); } pdc_logg_cond(pdc, 1, trc_warning, "\n[Warning message %d: \"%s\"]\n", errnum, pdc->pr->errbuf); strcpy(pdc->pr->errbuf, errbuf); } /* pdc_set_warnmsg */
/* Convert a BDB error to a Subversion error. */ static svn_error_t * convert_bdb_error(bdb_env_t *bdb, int db_err) { if (db_err) { bdb_env_baton_t bdb_baton; bdb_baton.env = bdb->env; bdb_baton.bdb = bdb; bdb_baton.error_info = get_error_info(bdb); SVN_BDB_ERR(&bdb_baton, db_err); } return SVN_NO_ERROR; }
int main(void) { cybersock = cyberspace_connect("127.0.0.1", 2233, client_god, "Neo"); if (cybersock < 0) { fprintf(stderr, "Error connecting cyberspace (%s).\n", get_error_info(cybersock)); } cli_mainloop(god_cmds, "cyber", 0); message_send(cybersock, CMD_DISCONNECT, 1); return 0; }
std::string get_lb_message(Context const& context) { std::string result; int error; std::string error_txt; std::string description_txt; boost::tie(error, error_txt, description_txt) = get_error_info(context); result += error_txt; result += " ("; result += boost::lexical_cast<std::string>(error); result += ") - "; result += description_txt; return result; }
/* BDB error callback. See bdb_error_info_t in env.h for more info. Note: bdb_error_gatherer is a macro with BDB < 4.3, so be careful how you use it! */ static void bdb_error_gatherer(const DB_ENV *dbenv, const char *baton, const char *msg) { /* See the documentation at bdb_env_t's definition why the (bdb_env_t *) cast is safe and why it is done. */ bdb_error_info_t *error_info = get_error_info((const bdb_env_t *) baton); svn_error_t *new_err; SVN_BDB_ERROR_GATHERER_IGNORE(dbenv); new_err = svn_error_createf(APR_SUCCESS, NULL, "bdb: %s", msg); if (error_info->pending_errors) svn_error_compose(error_info->pending_errors, new_err); else error_info->pending_errors = new_err; if (error_info->user_callback) error_info->user_callback(NULL, (char *)msg); /* ### I hate this cast... */ }
void pdc_push_errmsg( pdc_core * pdc, int errnum, const char *parm1, const char *parm2, const char *parm3, const char *parm4) { static const char fn[] = "pdc_push_errmsg"; const pdc_error_info *ei = get_error_info(pdc, errnum); pdc_pop_errmsg(pdc); make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_false); pdc->pr->premsg = pdc_strdup_ext(pdc, pdc->pr->errbuf, 0, fn); } /* pdc_push_errmsg */
void pdc_set_errmsg( pdc_core * pdc, int errnum, const char *parm1, const char *parm2, const char *parm3, const char *parm4) { const pdc_error_info *ei = get_error_info(pdc, errnum); make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_false); pdc->pr->errnum = errnum; pdc_logg_cond(pdc, 2, trc_warning, "[Reason for error message %d: \"%s\"]\n", pdc->pr->errnum, pdc->pr->errbuf); } /* pdc_set_errmsg */
static svn_error_t * svn_fs_bdb__open_internal(bdb_env_baton_t **bdb_batonp, const char *path, u_int32_t flags, int mode, apr_pool_t *pool) { bdb_env_key_t key; bdb_env_t *bdb; svn_boolean_t panic; /* We can safely discard the open DB_CONFIG file handle. If the environment descriptor is in the cache, the key's immutability is guaranteed. If it's not, we don't care if the key changes, between here and the actual insertion of the newly-created environment into the cache, because no other thread can touch the cache in the meantime. */ SVN_ERR(bdb_cache_key(&key, NULL, path, pool)); bdb = bdb_cache_get(&key, &panic); if (panic) return svn_error_create(SVN_ERR_FS_BERKELEY_DB, NULL, db_strerror(DB_RUNRECOVERY)); /* Make sure that the environment's open flags haven't changed. */ if (bdb && bdb->flags != flags) { /* Handle changes to the DB_PRIVATE flag specially */ if ((flags ^ bdb->flags) & DB_PRIVATE) { if (flags & DB_PRIVATE) return svn_error_create(SVN_ERR_FS_BERKELEY_DB, NULL, "Reopening a public Berkeley DB" " environment with private attributes"); else return svn_error_create(SVN_ERR_FS_BERKELEY_DB, NULL, "Reopening a private Berkeley DB" " environment with public attributes"); } /* Otherwise return a generic "flags-mismatch" error. */ return svn_error_create(SVN_ERR_FS_BERKELEY_DB, NULL, "Reopening a Berkeley DB environment" " with different attributes"); } if (!bdb) { svn_error_t *err; SVN_ERR(create_env(&bdb, path, svn_pool_create(bdb_cache_pool))); err = bdb_open(bdb, flags, mode); if (err) { /* Clean up, and we can't do anything about returned errors. */ svn_error_clear(bdb_close(bdb)); return svn_error_trace(err); } apr_hash_set(bdb_cache, &bdb->key, sizeof bdb->key, bdb); bdb->flags = flags; bdb->refcount = 1; } else { ++bdb->refcount; } *bdb_batonp = apr_palloc(pool, sizeof **bdb_batonp); (*bdb_batonp)->env = bdb->env; (*bdb_batonp)->bdb = bdb; (*bdb_batonp)->error_info = get_error_info(bdb); ++(*bdb_batonp)->error_info->refcount; apr_pool_cleanup_register(pool, *bdb_batonp, cleanup_env_baton, apr_pool_cleanup_null); return SVN_NO_ERROR; }
void* client_service_thread(void *fd) { int connection_fd; char request[MESSAGE_SIZE]; char response[MESSAGE_SIZE]; int status; char *error_info; account_t *current_account; connection_fd = *((int *)fd); free(fd); current_account = NULL; pthread_detach(pthread_self()); printf("server: connected to a client\n"); while (recv(connection_fd, request, MESSAGE_SIZE, 0) > 0) { if (strncmp(request, "create ", 7) == 0) { if ((status = create(&request[7], ¤t_account)) < 0) { error_info = get_error_info(status); send(connection_fd, error_info, strlen(error_info)+1, 0); free(error_info); } else { sprintf(response, "create: success"); send(connection_fd, response, strlen(response)+1, 0); } } else if (strncmp(request, "serve ", 6) == 0) { while ((status = serve(&request[6], ¤t_account)) == BUSY) { sprintf(response, "serve: waiting..."); send(connection_fd, response, strlen(response)+1, 0); sleep(2); } if (status != SUCCESS) { error_info = get_error_info(status); send(connection_fd, error_info, strlen(error_info)+1, 0); free(error_info); } else { sprintf(response, "serve: success"); send(connection_fd, response, strlen(response)+1, 0); } } else if (strncmp(request, "deposit ", 8) == 0) { if ((status = deposit(&request[8],¤t_account)) < 0) { error_info = get_error_info(status); send(connection_fd, error_info, strlen(error_info)+1, 0); free(error_info); } else { sprintf(response, "deposit: success"); send(connection_fd, response, strlen(response)+1, 0); } } else if (strncmp(request, "withdraw ", 9) == 0) { if ((status = withdraw(&request[9],¤t_account)) < 0) { error_info = get_error_info(status); send(connection_fd, error_info, strlen(error_info)+1, 0); free(error_info); } else { sprintf(response, "withdraw: success"); send(connection_fd, response, strlen(response)+1, 0); } } else if (strcmp(request, "query") == 0) { double amount; if ((amount = query(¤t_account)) < 0) { status = amount; error_info = get_error_info(status); send(connection_fd, error_info, strlen(error_info)+1, 0); free(error_info); } else { sprintf(response, "query: success\nbalance: %lf", amount); send(connection_fd, response, strlen(response)+1, 0); } } else if (strcmp(request, "end") == 0) { if ((status = end(¤t_account)) < 0) { error_info = get_error_info(status); send(connection_fd, error_info, strlen(error_info)+1, 0); free(error_info); } else { sprintf(response, "end: success"); send(connection_fd, response, strlen(response)+1, 0); } } else if (strcmp(request, "quit") == 0) { quit(¤t_account); sprintf(response, "quit"); send(connection_fd, response, strlen(response)+1, 0); printf("server: disconnected to a client\n"); close(connection_fd); pthread_exit(NULL); } else if (strcmp(request, "help") == 0) { sprintf(response, "%s", usage); send(connection_fd, response, strlen(response)+1, 0); } else { sprintf(response, "invalid command, enter again('help' for usage)"); send(connection_fd, response, strlen(response)+1, 0); } bzero(request, MESSAGE_SIZE); bzero(response, MESSAGE_SIZE); } close(connection_fd); return NULL; }
void pdc_error( pdc_core * pdc, int errnum, const char *parm1, const char *parm2, const char *parm3, const char *parm4) { const char *logmsg = NULL; /* avoid recursive errors, but allow rethrow. */ if (errnum != -1 && pdc->pr->in_error) return; pdc->pr->in_error = pdc_true; pdc->pr->x_thrown = pdc_true; if (errnum != -1) { const pdc_error_info *ei = get_error_info(pdc, errnum); make_errmsg(pdc, ei, parm1, parm2, parm3, parm4, pdc_true); pdc->pr->errnum = errnum; } if (pdc->pr->x_sp > pdc->pr->x_sp0) { if (pdc_logg_is_enabled(pdc, 2, trc_warning)) logmsg = "[Nested exception %d in %s]"; } else { logmsg = "\n[Last exception %d in %s]"; } if (logmsg != NULL) { pdc_logg(pdc, logmsg, pdc->pr->errnum, (pdc->pr->errnum == 0 || !pdc->pr->apiname) ? "" : pdc->pr->apiname, pdc->pr->x_sp0 + 1, pdc->pr->x_sp - pdc->pr->x_sp0); pdc_logg(pdc, "[\"%s\"]\n\n", pdc->pr->errbuf); } if (pdc->pr->x_sp == -1) { char errbuf[PDC_ERRBUF_SIZE]; const char *apiname = pdc_get_apiname(pdc); const char *errmsg = pdc->pr->errbuf; if (strlen(apiname)) { sprintf(errbuf, "[%d] %s: %s", pdc->pr->errnum, apiname, errmsg); errmsg = errbuf; } (*pdc->pr->errorhandler)(pdc->pr->opaque, PDF_UnknownError, errmsg); /* * The error handler must never return. If it does, it is severely * broken. We cannot remedy this, so we exit. */ exit(99); } else { longjmp(pdc->pr->x_stack[pdc->pr->x_sp].jbuf.jbuf, 1); } } /* pdc_error */