Berkeley DB: log_unlink
Полезная информация


#include <db.h>

int log_unlink(const char *dir, int force, DB_ENV *);


The log_unlink function destroys the log region identified by the directory dir, removing all files used to implement the log region. (The log files themselves and the directory dir are not removed.)

If there are processes that have called log_open without calling log_close (i.e., there are processes currently using the log region), log_unlink will fail without further action, unless the force flag is set, in which case log_unlink will attempt to remove the log region files regardless of any processes still using it.

The result of attempting to forcibly destroy the region when a process has the region open is unspecified. Processes using a shared memory region maintain an open file descriptor for it. On UNIX systems, the region removal should succeed and processes that have already joined the region should continue to run in the region without change, however processes attempting to join the log region will either fail or attempt to create a new region. On other systems (e.g., Windows/NT), where the unlink(2) system call will fail if any process has an open file descriptor for the file, the region removal will fail.

In the case of catastrophic or system failure, database recovery must be performed (see db_recover), or the DB_RECOVER and DB_RECOVER_FATAL flags to db_appinit must be specified. Alternatively, if recovery is not required because no database state is maintained across failures, it is possible to clean up a log region by removing all of the files in the directory specified to the log_open function, as no log region files are created in any other directory. Note, however, that this has the potential to remove files created by the other Berkeley DB subsystems in the same database environment.

The log_unlink function returns the value of errno on failure, and 0 on success.


If a fatal error occurs in Berkeley DB, the log_unlink function may fail and return DB_RUNRECOVERY, at which point all subsequent database calls will also return DB_RUNRECOVERY.

The log_unlink function may fail and return errno for any of the errors specified for the following Berkeley DB and C library functions: abort(3), close(3), db_version, fcntl(3), fflush(3), fprintf(3), free(3), fstat(3), fsync(3), getenv(3), getpid(3), getuid(3), isdigit(3), lseek(3), malloc(3), memcpy(3), memset(3), mmap(3), munmap(3), open(3), pstat_getdynamic(3), read(3), shmat(3), shmctl(3), shmdt(3), sigfillset(3), sigprocmask(3), stat(3), strerror(3), strlen(3), sysconf(3), unlink(3), vfprintf(3), vsnprintf(3), and write(3).

In addition, the log_unlink function may fail and return errno for the following conditions:

The shared memory region was in use and the force flag was not set.

See Also

log_archive, log_close, log_compare, log_file, log_flush, log_get, log_open, log_put, log_register, log_stat, log_unlink and log_unregister.