/*
   When handling kill, call this function
*/
void kill_handler(int signum)
{
	printf("signal:%d\n", signum);

	on_free();
	exit(signum);
}
Exemple #2
0
gboolean
qof_commit_edit_part2(QofInstance *inst,
                      void (*on_error)(QofInstance *, QofBackendError),
                      void (*on_done)(QofInstance *),
                      void (*on_free)(QofInstance *))
{
    QofInstancePrivate *priv;
    QofBackend * be;
    gboolean dirty;

    priv = GET_PRIVATE(inst);
    dirty = priv->dirty;

    /* See if there's a backend.  If there is, invoke it. */
    be = qof_book_get_backend(priv->book);
    if (be && qof_backend_commit_exists(be))
    {
        QofBackendError errcode;

        /* clear errors */
        do
        {
            errcode = qof_backend_get_error(be);
        }
        while (ERR_BACKEND_NO_ERR != errcode);

        qof_backend_run_commit(be, inst);
        errcode = qof_backend_get_error(be);
        if (ERR_BACKEND_NO_ERR != errcode)
        {
            /* XXX Should perform a rollback here */
            priv->do_free = FALSE;

            /* Push error back onto the stack */
            qof_backend_set_error (be, errcode);
            if (on_error)
                on_error(inst, errcode);
            return FALSE;
        }
        /* XXX the backend commit code should clear dirty!! */
        priv->dirty = FALSE;
    }
//    if (dirty && qof_get_alt_dirty_mode() &&
//        !(priv->infant && priv->do_free)) {
//      qof_collection_mark_dirty(priv->collection);
//      qof_book_mark_dirty(priv->book);
//    }
    priv->infant = FALSE;

    if (priv->do_free)
    {
        if (on_free)
            on_free(inst);
        return TRUE;
    }

    if (on_done)
        on_done(inst);
    return TRUE;
}
Exemple #3
0
static void free_chash_entry(chash_entry* e, chash_callback_t* on_free) {
    if (e == NULL) {
        return;
    }
    free_chash_entry(e->next, on_free);
    free(e->key);
    on_free(e->data);
    free(e);
}
int main(int argc, const char *const argv[])
{	
	int memory_to_allocate = 0;
	int timeout = 0;
	check_arguments(argc, argv);

	memory_to_allocate = get_memory_to_allocate(argv);
	timeout = get_timeout(argv);

	signal(SIGTERM, kill_handler);

	on_allocate(memory_to_allocate);
	sleep(timeout);		
	on_free();

	return 0;
}