netatalk  4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
main.c File Reference

CNID DBD (Database Daemon) Backend startup routines. More...

#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <bstrlib.h>
#include <atalk/cnid_bdb_private.h>
#include <atalk/errchk.h>
#include <atalk/logger.h>
#include <atalk/netatalk_conf.h>
#include <atalk/util.h>
#include "db_param.h"
#include "dbd.h"
#include "dbif.h"
#include "pack.h"
#include "comm.h"

Macros

#define DBOPTIONS   (DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN)
 

Functions

static void sig_exit (int signo)
 
static void block_sigs_onoff (int block)
 
static int get_lock (int cmd, const char *dbpath)
 Get lock on db lock file.
 
static int open_db (void)
 
static int delete_db (void)
 
static int reinit_db (void)
 Close dbd if open, delete it, reopen.
 
static int loop (struct db_param *dbp)
 
static void switch_to_user (char *dir)
 
static void set_signal (void)
 
static uid_t uid_from_name (const char *name)
 
int main (int argc, char *argv[])
 

Variables

static DBDdbd
 
static int exit_sig = 0
 
static int db_locked
 
static bstring dbpath
 
static struct db_paramdbp
 
static struct volvol
 

Detailed Description

CNID DBD (Database Daemon) Backend startup routines.

The dbd_XXX and comm_XXX functions all obey the same protocol for return values:

  • 1: Success, if transactions are used commit.
  • 0: Failure, but we continue to serve requests. If transactions are used abort/rollback.
  • -1: Fatal error, either from the database or from the socket. Abort the transaction if applicable (which might fail as well) and then exit.

We always try to notify the client process about the outcome, the result field of the cnid_dbd_rply structure contains further details.

Macro Definition Documentation

◆ DBOPTIONS

#define DBOPTIONS   (DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN)

Function Documentation

◆ block_sigs_onoff()

static void block_sigs_onoff ( int  block)
static

◆ delete_db()

static int delete_db ( void  )
static

◆ get_lock()

static int get_lock ( int  cmd,
const char *  dbpath 
)
static

Get lock on db lock file.

Parameters
[in]cmdlock command:
  • LOCK_FREE: close lockfd
  • LOCK_UNLOCK: unlock lockm keep lockfd open
  • LOCK_EXCL: F_WRLCK on lockfd
  • LOCK_SHRD: F_RDLCK on lockfd
[in]dbpathpath to lockfile, only used on first call, later the stored fd is used
Returns
depending on lock command:
  • LOCK_FREE/LOCK_UNLOCK return 0 on success, -1 on error
  • LOCK_EXCL/LOCK_SHRD return LOCK_EXCL or LOCK_SHRD respectively on success, 0 if the lock couldn't be acquired, -1 on other errors

◆ loop()

static int loop ( struct db_param dbp)
static

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ open_db()

static int open_db ( void  )
static

◆ reinit_db()

static int reinit_db ( void  )
static

Close dbd if open, delete it, reopen.

Also tries to copy the rootinfo key, that would allow for keeping the db stamp and last used CNID

◆ set_signal()

static void set_signal ( void  )
static

◆ sig_exit()

static void sig_exit ( int  signo)
static

◆ switch_to_user()

static void switch_to_user ( char *  dir)
static

◆ uid_from_name()

static uid_t uid_from_name ( const char *  name)
static

Variable Documentation

◆ db_locked

int db_locked
static

◆ dbd

DBD* dbd
static

◆ dbp

struct db_param* dbp
static

◆ dbpath

bstring dbpath
static

◆ exit_sig

int exit_sig = 0
static

◆ vol

struct vol* vol
static