The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
txn.c File Reference

librat: transactions. More...

#include "internal.h"
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

Macros

#define TXN_FILE   RAT_DB_DIR "/transaction"
#define TXN_FIRST   "rat-transaction 1\n"

Functions

void rat_txn_init (rat_txn_t *txn)
void rat_txn_free (rat_txn_t *txn)
int rat_txn_add (rat_txn_t *txn, const char *format,...)
int rat_txn_commit (rat_t *rat, rat_txn_t *txn, const char *note, rat_error_t *err)
 write the list and do it, then remove the list and the stage folder.
int rat_recover (rat_t *rat, rat_error_t *err)
 finish the transaction of an earlier rat that stopped, or remove its stage folder.
bool rat_txn_pending (const rat_t *rat)
 true if the list of an interrupted change is there

Variables

int rat_test_stop_after = -1
 for the host tests only: when 0 or more, a transaction stops after this number of operations, as if the power went off.

Detailed Description

librat: transactions.

a change is a list of operations in the file var/lib/rat/transaction, done in order.

the file has one operation on each line, between a first line and an "end" line:

rat-transaction 1
note install lua 5.4.9-1
mkdir 0755 usr/share/lua
move f3a9... usr/bin/lua        (a file or link of the stage folder)
remove usr/bin/old              (a file or link)
rmdir usr/share/old             (only if it is empty)
record lua                      (stage/record replaces installed/lua)
unrecord lua                    (installed/lua is removed)
end

each operation gives the same result when it is done again (a move whose source is gone is done, a remove of a missing path is done), so an interrupted list is finished by doing all of it again.

Macro Definition Documentation

◆ TXN_FILE

#define TXN_FILE   RAT_DB_DIR "/transaction"

◆ TXN_FIRST

#define TXN_FIRST   "rat-transaction 1\n"

Function Documentation

◆ rat_txn_init()

void rat_txn_init ( rat_txn_t * txn)

◆ rat_txn_free()

void rat_txn_free ( rat_txn_t * txn)

◆ rat_txn_add()

int rat_txn_add ( rat_txn_t * txn,
const char * format,
... )

◆ rat_txn_commit()

int rat_txn_commit ( rat_t * rat,
rat_txn_t * txn,
const char * note,
rat_error_t * err )

write the list and do it, then remove the list and the stage folder.

Parameters
notea line that tells what the change is ("install lua 5.4.9-1").
Returns
0, or -1. after -1 the list can still be there: the next rat_open for writing finishes it.

◆ rat_recover()

int rat_recover ( rat_t * rat,
rat_error_t * err )

finish the transaction of an earlier rat that stopped, or remove its stage folder.

rat->recovered gets a message when there was one.

Returns
0, or -1.

◆ rat_txn_pending()

bool rat_txn_pending ( const rat_t * rat)

true if the list of an interrupted change is there

Variable Documentation

◆ rat_test_stop_after

int rat_test_stop_after = -1

for the host tests only: when 0 or more, a transaction stops after this number of operations, as if the power went off.

-1 normally.