[ --enable-client-only build client (File daemon) only [disabled]],
[if test x$enableval = xyes; then
build_client_only=yes
+ db_name=None
+ DB_NAME=none
fi])
if test x$build_client_only = xno; then
ALL_DIRS="subdirs"
echo "You have set --sbindir and --with-subsys-dir"
echo " both equal to: ${subsysdir} "
echo " This is not permitted. Please reconfigure."
+ echo " "
echo "Aborting configuration ..."
echo " "
echo " "
exit 1
fi
+if test "x${db_name}" = "xInternal" ; then
+ echo " "
+ echo " "
+ echo "You have not specified either --enable-client-only or one of the"
+ echo " supported databases: MySQL, PostgreSQL, or SQLite".
+ echo " This is not permitted. Please reconfigure."
+ echo " "
+ echo "Aborting the configuration ..."
+ echo " "
+ echo " "
+ exit 1
+fi
+
echo "
Configuration on `date`:
enableval="$enable_client_only"
if test x$enableval = xyes; then
build_client_only=yes
+ db_name=None
+ DB_NAME=none
fi
fi;
if test x$build_client_only = xno; then
echo "You have set --sbindir and --with-subsys-dir"
echo " both equal to: ${subsysdir} "
echo " This is not permitted. Please reconfigure."
+ echo " "
echo "Aborting configuration ..."
echo " "
echo " "
exit 1
fi
+if test "x${db_name}" = "xInternal" ; then
+ echo " "
+ echo " "
+ echo "You have not specified either --enable-client-only or one of the"
+ echo " supported databases: MySQL, PostgreSQL, or SQLite".
+ echo " This is not permitted. Please reconfigure."
+ echo " "
+ echo "Aborting the configuration ..."
+ echo " "
+ echo " "
+ exit 1
+fi
+
echo "
Configuration on `date`:
The BACULA-FD file is
linked to missing export KERNEL32.DLL:GetFileAttributesExA.
- Add link to doc in message when authentication fails.
-- Add db_ensure...slot_unique to BDB.
+- Disallow using Internal database
+- Add better error codes to run_program (10000+)
Documentation to do: (any release a little bit at a time)
#! /bin/sh
#
# bacula This shell script takes care of starting and stopping
-# the bacula daemons.
+# the bacula daemons.
#
# This is pretty much watered down version of the RedHat script
# that works on Solaris as well as Linux, but it won't work everywhere.
RC=0
# Test syntax.
if [ $# = 0 ]; then
- echo "Usage: killproc {program} [signal]"
- return 1
+ echo "Usage: killproc {program} [signal]"
+ return 1
fi
notset=0
# check for third arg to be kill level
if [ "$3" != "" ] ; then
- killlevel=$3
+ killlevel=$3
else
- notset=1
- killlevel="-9"
+ notset=1
+ killlevel="-9"
fi
# Get base program name
# Kill it.
if [ "$pid" != "" ] ; then
- if [ "$notset" = "1" ] ; then
- if ps -p $pid>/dev/null 2>&1; then
- # TERM first, then KILL if not dead
- kill -TERM $pid 2>/dev/null
- sleep 1
- if ps -p $pid >/dev/null 2>&1 ; then
- sleep 1
- if ps -p $pid >/dev/null 2>&1 ; then
- sleep 3
- if ps -p $pid >/dev/null 2>&1 ; then
- kill -KILL $pid 2>/dev/null
- fi
- fi
- fi
- fi
- ps -p $pid >/dev/null 2>&1
- RC=$?
- [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
- # RC=$((! $RC))
- # use specified level only
- else
- if ps -p $pid >/dev/null 2>&1; then
- kill $killlevel $pid 2>/dev/null
- RC=$?
- [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
- fi
- fi
+ if [ "$notset" = "1" ] ; then
+ if ps -p $pid>/dev/null 2>&1; then
+ # TERM first, then KILL if not dead
+ kill -TERM $pid 2>/dev/null
+ sleep 1
+ if ps -p $pid >/dev/null 2>&1 ; then
+ sleep 1
+ if ps -p $pid >/dev/null 2>&1 ; then
+ sleep 3
+ if ps -p $pid >/dev/null 2>&1 ; then
+ kill -KILL $pid 2>/dev/null
+ fi
+ fi
+ fi
+ fi
+ ps -p $pid >/dev/null 2>&1
+ RC=$?
+ [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
+ # RC=$((! $RC))
+ # use specified level only
+ else
+ if ps -p $pid >/dev/null 2>&1; then
+ kill $killlevel $pid 2>/dev/null
+ RC=$?
+ [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
+ fi
+ fi
else
- failure "$base shutdown"
+ failure "$base shutdown"
fi
# Remove pid file if any.
if [ "$notset" = "1" ]; then
- rm -f ${PIDDIR}/$base.$2.pid
+ rm -f ${PIDDIR}/$base.$2.pid
fi
return $RC
}
pid=""
# Test syntax.
if [ $# = 0 ] ; then
- echo "Usage: pidofproc {program}"
- return 1
+ echo "Usage: pidofproc {program}"
+ return 1
fi
# Get base program name
# First try PID file
if [ -f ${PIDDIR}/$base.$2.pid ] ; then
- pid=`head -1 ${PIDDIR}/$base.$2.pid`
- if [ "$pid" != "" ] ; then
- echo $pid
- return 0
- fi
+ pid=`head -1 ${PIDDIR}/$base.$2.pid`
+ if [ "$pid" != "" ] ; then
+ echo $pid
+ return 0
+ fi
fi
# Next try "pidof"
status() {
# Test syntax.
if [ $# = 0 ] ; then
- echo "Usage: status {program}"
- return 1
+ echo "Usage: status {program}"
+ return 1
fi
# Get base program name
return 0
else
pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
- { if ((prog == $2) || (("(" prog ")") == $2) ||
- (("[" prog "]") == $2) ||
- ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
+ { if ((prog == $2) || (("(" prog ")") == $2) ||
+ (("[" prog "]") == $2) ||
+ ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
if [ "$pid" != "" ] ; then
- echo "$base (pid $pid) is running..."
- return 0
+ echo "$base (pid $pid) is running..."
+ return 0
fi
fi
# Next try the PID files
if [ -f ${PIDDIR}/$base.$2.pid ] ; then
- pid=`head -1 ${PIDDIR}/$base.$2.pid`
- if [ "$pid" != "" ] ; then
- echo "$base dead but pid file exists"
- return 1
- fi
+ pid=`head -1 ${PIDDIR}/$base.$2.pid`
+ if [ "$pid" != "" ] ; then
+ echo "$base not running, but pid file exists"
+ return 1
+ fi
fi
# See if the subsys lock exists
if [ -f ${SUBSYSDIR}/$base ] ; then
- echo "$base dead but subsys locked"
- return 2
+ echo "$base not running, but subsys locked"
+ return 2
fi
echo "$base is stopped"
return 3
return $rc
}
-
#! /bin/sh
#
# bacula This shell script takes care of starting and stopping
-# the bacula daemons.
+# the bacula daemons.
#
# This is pretty much watered down version of the RedHat script
# that works on Solaris as well as Linux, but it won't work everywhere.
# description: It comes by night and sucks the vital essence from your computers.
#
### BEGIN INIT INFO
-# Provides: bacula
-# Required-Start: network mysql
+# Provides: bacula
+# Required-Start: network mysql
# Required-Stop:
-# Default-Start: 2 3 5
+# Default-Start: 2 3 5
# Default-Stop:
-# Description: run bacula daemon(s)
+# Description: run bacula daemon(s)
### END INIT INFO
PSCMD="@PSCMD@"
RC=0
# Test syntax.
if [ $# = 0 ]; then
- echo "Usage: killproc {program} [signal]"
- return 1
+ echo "Usage: killproc {program} [signal]"
+ return 1
fi
notset=0
# check for third arg to be kill level
if [ "$3" != "" ] ; then
- killlevel=$3
+ killlevel=$3
else
- notset=1
- killlevel="-9"
+ notset=1
+ killlevel="-9"
fi
# Get base program name
# Kill it.
if [ "$pid" != "" ] ; then
- if [ "$notset" = "1" ] ; then
- if ps -p $pid>/dev/null 2>&1; then
- # TERM first, then KILL if not dead
- kill -TERM $pid 2>/dev/null
- sleep 1
- if ps -p $pid >/dev/null 2>&1 ; then
- sleep 1
- if ps -p $pid >/dev/null 2>&1 ; then
- sleep 3
- if ps -p $pid >/dev/null 2>&1 ; then
- kill -KILL $pid 2>/dev/null
- fi
- fi
- fi
- fi
- ps -p $pid >/dev/null 2>&1
- RC=$?
- [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
- # RC=$((! $RC))
- # use specified level only
- else
- if ps -p $pid >/dev/null 2>&1; then
- kill $killlevel $pid 2>/dev/null
- RC=$?
- [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
- fi
- fi
+ if [ "$notset" = "1" ] ; then
+ if ps -p $pid>/dev/null 2>&1; then
+ # TERM first, then KILL if not dead
+ kill -TERM $pid 2>/dev/null
+ sleep 1
+ if ps -p $pid >/dev/null 2>&1 ; then
+ sleep 1
+ if ps -p $pid >/dev/null 2>&1 ; then
+ sleep 3
+ if ps -p $pid >/dev/null 2>&1 ; then
+ kill -KILL $pid 2>/dev/null
+ fi
+ fi
+ fi
+ fi
+ ps -p $pid >/dev/null 2>&1
+ RC=$?
+ [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
+ # RC=$((! $RC))
+ # use specified level only
+ else
+ if ps -p $pid >/dev/null 2>&1; then
+ kill $killlevel $pid 2>/dev/null
+ RC=$?
+ [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
+ fi
+ fi
else
- failure "$base shutdown"
+ failure "$base shutdown"
fi
# Remove pid file if any.
if [ "$notset" = "1" ]; then
- rm -f ${PIDDIR}/$base.$2.pid
+ rm -f ${PIDDIR}/$base.$2.pid
fi
return $RC
}
pid=""
# Test syntax.
if [ $# = 0 ] ; then
- echo "Usage: pidofproc {program}"
- return 1
+ echo "Usage: pidofproc {program}"
+ return 1
fi
# Get base program name
# First try PID file
if [ -f ${PIDDIR}/$base.$2.pid ] ; then
- pid=`head -1 ${PIDDIR}/$base.$2.pid`
- if [ "$pid" != "" ] ; then
- echo $pid
- return 0
- fi
+ pid=`head -1 ${PIDDIR}/$base.$2.pid`
+ if [ "$pid" != "" ] ; then
+ echo $pid
+ return 0
+ fi
fi
# Next try "pidof"
status() {
# Test syntax.
if [ $# = 0 ] ; then
- echo "Usage: status {program}"
- return 1
+ echo "Usage: status {program}"
+ return 1
fi
# Get base program name
return 0
else
pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
- { if ((prog == $2) || (("(" prog ")") == $2) ||
- (("[" prog "]") == $2) ||
- ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
+ { if ((prog == $2) || (("(" prog ")") == $2) ||
+ (("[" prog "]") == $2) ||
+ ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
if [ "$pid" != "" ] ; then
- echo "$base (pid $pid) is running..."
- return 0
+ echo "$base (pid $pid) is running..."
+ return 0
fi
fi
# Next try the PID files
if [ -f ${PIDDIR}/$base.$2.pid ] ; then
- pid=`head -1 ${PIDDIR}/$base.$2.pid`
- if [ "$pid" != "" ] ; then
- echo "$base dead but pid file exists"
- return 1
- fi
+ pid=`head -1 ${PIDDIR}/$base.$2.pid`
+ if [ "$pid" != "" ] ; then
+ echo "$base not running, but pid file exists"
+ return 1
+ fi
fi
# See if the subsys lock exists
if [ -f ${SUBSYSDIR}/$base ] ; then
- echo "$base dead but subsys locked"
- return 2
+ echo "$base not running, but subsys locked"
+ return 2
fi
echo "$base is stopped"
return 3
# First try PID file
if [ -f ${PIDDIR}/$base.$2.pid ] ; then
- pid=`head -1 ${PIDDIR}/$base.$2.pid`
+ pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
if [ "$pid" != "" ] ; then
echo $pid
return 0
# Next try the PID files
if [ -f ${PIDDIR}/$base.$2.pid ] ; then
- pid=`head -1 ${PIDDIR}/$base.$2.pid`
+ pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
if [ "$pid" != "" ] ; then
echo "$base dead but pid file exists"
return 1
bconsole: $(CONSOBJS) ../lib/libbac.a
$(CXX) $(LDFLAGS) $(CONS_LDFLAGS) -L../lib -L../cats -o $@ $(CONSOBJS) \
- $(LIBS) $(DLIB) $(CONS_LIBS) -lbac -lm
+ $(DLIB) $(CONS_LIBS) -lbac -lm $(LIBS)
static-bconsole: $(CONSOBJS) ../lib/libbac.a
$(CXX) -static $(LDFLAGS) $(CONS_LDFLAGS) -L../lib -L../cats -o $@ $(CONSOBJS) \
- $(LIBS) $(DLIB) $(CONS_LIBS) -lbac -lm
+ $(DLIB) $(CONS_LIBS) -lbac -lm $(LIBS)
strip $@
bacula-dir: $(SVROBJS) ../lib/libbac.a ../cats/libsql.a ../findlib/libfind.a
$(CXX) $(WLDFLAGS) $(LDFLAGS) -L../lib -L../cats -L../findlib -o $@ $(SVROBJS) \
- -lsql -lbac -lfind -lm $(LIBS) $(DLIB) $(DB_LIBS)
+ -lsql -lbac -lfind -lm $(DLIB) $(DB_LIBS) $(LIBS)
static-bacula-dir: $(SVROBJS) ../lib/libbac.a ../cats/libsql.a ../findlib/libfind.a
$(CXX) $(WLDFLAGS) $(LDFLAGS) -static -L../lib -L../cats -L../findlib -o $@ $(SVROBJS) \
- -lsql -lbac -lfind -lm $(LIBS) $(DLIB) $(DB_LIBS)
+ -lsql -lbac -lfind -lm $(DLIB) $(DB_LIBS) $(LIBS)
strip $@
TREE_CTX tree;
JobId_t JobId, last_JobId;
char *p;
- char empty = '\0';
- char *nofname;
bool OK = true;
- nofname = ∅
memset(&tree, 0, sizeof(TREE_CTX));
/*
* Build the directory tree containing JobIds user selected
*/
tree.root = new_tree(rx->TotalFiles);
- tree.root->fname = nofname;
tree.ua = ua;
tree.all = rx->all;
last_JobId = 0;
{
struct stat statp;
TREE_CTX *tree = (TREE_CTX *)ctx;
- char fname[5000];
- TREE_NODE *node, *new_node;
+ TREE_NODE *node;
int type;
- bool hard_link, first_time, ok;
+ bool hard_link, ok;
int FileIndex;
JobId_t JobId;
} else {
type = TN_FILE;
}
- if (tree->avail_node) {
- node = tree->avail_node; /* if prev node avail use it */
- } else {
- node = new_tree_node(tree->root, type); /* get new node */
- tree->avail_node = node;
- }
hard_link = (decode_LinkFI(row[4], &statp) != 0);
- bsnprintf(fname, sizeof(fname), "%s%s%s", row[0], row[1], "");
- Dmsg3(200, "FI=%d type=%d fname=%s\n", node->FileIndex, type, fname);
- new_node = insert_tree_node(fname, node, tree->root, NULL);
+ node = insert_tree_node(row[0], row[1], NULL, tree->root, NULL);
/* Note, if node already exists, save new one for next time */
- if (new_node != node) {
- first_time = false; /* we saw this file before */
- tree->avail_node = node; /* node already exists */
- } else {
- first_time = true; /* first time we saw this file */
- tree->avail_node = NULL; /* added node to tree */
- }
JobId = (JobId_t)str_to_int64(row[3]);
FileIndex = atoi(row[2]);
/*
- * - The first time we see a file, we accept it.
+ * - The first time we see a file (node->inserted==true), we accept it.
* - In the same JobId, we accept only the first copy of a
* hard linked file (the others are simply pointers).
* - In the same JobId, we accept the last copy of any other
* line, but it would be even harder to read.
*/
ok = true;
- if (!first_time && JobId == new_node->JobId) {
- if ((hard_link && FileIndex > new_node->FileIndex) ||
- (!hard_link && FileIndex < new_node->FileIndex)) {
+ if (!node->inserted && JobId == node->JobId) {
+ if ((hard_link && FileIndex > node->FileIndex) ||
+ (!hard_link && FileIndex < node->FileIndex)) {
ok = false;
}
}
if (ok) {
- new_node->hard_link = hard_link;
- new_node->FileIndex = FileIndex;
- new_node->JobId = JobId;
- new_node->type = type;
- new_node->soft_link = S_ISLNK(statp.st_mode) != 0;
+ node->hard_link = hard_link;
+ node->FileIndex = FileIndex;
+ node->JobId = JobId;
+ node->type = type;
+ node->soft_link = S_ISLNK(statp.st_mode) != 0;
if (tree->all) {
- new_node->extract = true; /* extract all by default */
+ node->extract = true; /* extract all by default */
if (type == TN_DIR || type == TN_DIR_NLS) {
- new_node->extract_dir = true; /* if dir, extract it */
+ node->extract_dir = true; /* if dir, extract it */
}
}
}
count++;
}
/* For a non-file (i.e. directory), we see all the children */
- if (node->type != TN_FILE || (node->soft_link && node->child)) {
+ if (node->type != TN_FILE || (node->soft_link && tree_node_has_child(node))) {
/* Recursive set children within directory */
- for (n=node->child; n; n=n->sibling) {
+ foreach_child(n, node) {
count += set_extract(ua, n, tree, extract);
}
/*
TREE_NODE *node;
int count = 0;
- if (ua->argc < 2 || !tree->node->child) {
+ if (ua->argc < 2 || !tree_node_has_child(tree->node)) {
bsendmsg(ua, _("No files marked.\n"));
return 1;
}
for (int i=1; i < ua->argc; i++) {
- for (node = tree->node->child; node; node=node->sibling) {
+ foreach_child(node, tree->node) {
if (fnmatch(ua->argk[i], node->fname, 0) == 0) {
count += set_extract(ua, node, tree, true);
}
TREE_NODE *node;
int count = 0;
- if (ua->argc < 2 || !tree->node->child) {
+ if (ua->argc < 2 || !tree_node_has_child(tree->node)) {
bsendmsg(ua, _("No files marked.\n"));
return 1;
}
for (int i=1; i < ua->argc; i++) {
- for (node = tree->node->child; node; node=node->sibling) {
+ foreach_child(node, tree->node) {
if (fnmatch(ua->argk[i], node->fname, 0) == 0) {
if (node->type == TN_DIR || node->type == TN_DIR_NLS) {
node->extract_dir = true;
{
TREE_NODE *node;
- if (!tree->node->child) {
+ if (!tree_node_has_child(tree->node)) {
return 1;
}
- for (node = tree->node->child; node; node=node->sibling) {
+ foreach_child(node, tree->node) {
if (ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) {
const char *tag;
if (node->extract) {
} else {
tag = "";
}
- bsendmsg(ua, "%s%s%s\n", tag, node->fname, node->child?"/":"");
+ bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":"");
}
}
return 1;
*/
static void rlsmark(UAContext *ua, TREE_NODE *node)
{
- if (!node->child) {
+ if (!tree_node_has_child(node)) {
return;
}
- for (node = node->child; node; node=node->sibling) {
+ foreach_child(node, node) {
if ((ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) &&
(node->extract || node->extract_dir)) {
const char *tag;
} else {
tag = "";
}
- bsendmsg(ua, "%s%s%s\n", tag, node->fname, node->child?"/":"");
- if (node->child) {
+ bsendmsg(ua, "%s%s%s\n", tag, node->fname, tree_node_has_child(node)?"/":"");
+ if (tree_node_has_child(node)) {
rlsmark(ua, node);
}
}
char buf[1100];
char cwd[1100], *pcwd;
- if (!tree->node->child) {
+ if (!tree_node_has_child(tree->node)) {
+ bsendmsg(ua, "Node %s has no children.\n", tree->node->fname);
return 1;
}
- for (node = tree->node->child; node; node=node->sibling) {
+
+ foreach_child(node, tree->node) {
const char *tag;
if (ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) {
if (node->extract) {
* treats soft links as files, so they do not have a trailing
* slash like directory names.
*/
- if (node->type == TN_FILE && node->child) {
+ if (node->type == TN_FILE && tree_node_has_child(node)) {
bstrncpy(buf, cwd, sizeof(buf));
pcwd = buf;
int len = strlen(buf);
TREE_NODE *node;
int count = 0;
- if (ua->argc < 2 || !tree->node->child) {
+ if (ua->argc < 2 || !tree_node_has_child(tree->node)) {
bsendmsg(ua, _("No files unmarked.\n"));
return 1;
}
for (int i=1; i < ua->argc; i++) {
- for (node = tree->node->child; node; node=node->sibling) {
+ foreach_child(node, tree->node) {
if (fnmatch(ua->argk[i], node->fname, 0) == 0) {
count += set_extract(ua, node, tree, false);
}
TREE_NODE *node;
int count = 0;
- if (ua->argc < 2 || !tree->node->child) {
+ if (ua->argc < 2 || !tree_node_has_child(tree->node)) {
bsendmsg(ua, _("No directories unmarked.\n"));
return 1;
}
for (int i=1; i < ua->argc; i++) {
- for (node = tree->node->child; node; node=node->sibling) {
+ foreach_child(node, tree->node) {
if (fnmatch(ua->argk[i], node->fname, 0) == 0) {
if (node->type == TN_DIR || node->type == TN_DIR_NLS) {
node->extract_dir = false;
if (WIFEXITED(chldstatus)) { /* process exit()ed */
stat = WEXITSTATUS(chldstatus);
if (stat != 0) {
+ Dmsg1(100, "Non-zero status %s returned from child.\n", stat);
stat = ECHILD;
}
Dmsg1(200, "child status=%d\n", stat);
#ifdef the_old_way
#define foreach_dlist(var, list) \
- for((var)=NULL; (((void *)(var))=(list)->next(var)); )
+ for((var)=NULL; (((void *)(var))=(list)->next(var)); )
#endif
struct dlink {
class dlist {
void *head;
void *tail;
- int loffset;
- int num_items;
+ uint16_t loffset;
+ uint32_t num_items;
public:
dlist(void *item, void *link);
void init(void *item, void *link);
void *dlist::binary_insert(void *item, int compare(void *item1, void *item2));
void remove(void *item);
bool empty();
- int size();
+ int size();
void *next(void *item);
void *prev(void *item);
void destroy();
void operator delete(void *);
};
-/*
+/*
* This allows us to do explicit initialization,
* allowing us to mix C++ classes inside malloc'ed
* C structures. Define before called in constructor.
#include "bacula.h"
#include "findlib/find.h"
-/*
- * Define SORT_SIBLINGS you want the sibling list to
- * be sorted otherwise it will be appended when
- * a new entry is added.
- */
-#define SORT_SIBLINGS
-
/* Forward referenced subroutines */
static TREE_NODE *search_and_insert_tree_node(char *fname, int type,
TREE_NODE *node, TREE_ROOT *root, TREE_NODE *parent);
+static char *tree_alloc(TREE_ROOT *root, int size);
/*
* NOTE !!!!! we turn off Debug messages for performance reasons.
}
root = (TREE_ROOT *)malloc(sizeof(TREE_ROOT));
memset(root, 0, sizeof(TREE_ROOT));
- root->type = TN_ROOT;
/* Assume filename + node = 40 characters average length */
size = count * (BALIGN(sizeof(TREE_NODE)) + 40);
if (count > 1000000 || size > 10000000) {
Dmsg2(400, "count=%d size=%d\n", count, size);
malloc_buf(root, size);
root->cached_path = get_pool_memory(PM_FNAME);
+ root->type = TN_ROOT;
+ root->fname = "";
return root;
}
/*
- * Create a new tree node. Size depends on type.
+ * Create a new tree node.
*/
-TREE_NODE *new_tree_node(TREE_ROOT *root, int type)
+static TREE_NODE *new_tree_node(TREE_ROOT *root, int type)
{
TREE_NODE *node;
- int asize = BALIGN(sizeof(TREE_NODE));
-
- if (root->mem->rem < asize) {
- uint32_t mb_size;
- if (root->total_size >= 1000000) {
- mb_size = 1000000;
- } else {
- mb_size = 100000;
- }
- malloc_buf(root, mb_size);
- }
- root->mem->rem -= asize;
- node = (TREE_NODE *)root->mem->mem;
- root->mem->mem += asize;
- memset(node, 0, sizeof(TREE_NODE));
- node->type = type;
+ int size = sizeof(TREE_NODE);
+ node = (TREE_NODE *)tree_alloc(root, size);
+ memset(node, 0, size);
return node;
}
+
/*
* Allocate bytes for filename in tree structure.
* Keep the pointers properly aligned by allocating
}
if (root->cached_path) {
free_pool_memory(root->cached_path);
+ root->cached_path = NULL;
}
Dmsg2(400, "Total size=%u blocks=%d\n", root->total_size, root->blocks);
free(root);
}
-
/*
* Insert a node in the tree. This is the main subroutine
* called when building a tree.
*
*/
-TREE_NODE *insert_tree_node(char *path, TREE_NODE *node,
+TREE_NODE *insert_tree_node(char *path, char *fname, TREE_NODE *node,
TREE_ROOT *root, TREE_NODE *parent)
{
- char *p, *q, *fname;
+ char *p, *q;
int path_len = strlen(path);
Dmsg1(100, "insert_tree_node: %s\n", path);
/*
- * If trailing slash, strip it
+ * If trailing slash on path, strip it
*/
if (path_len > 0) {
q = path + path_len - 1;
} else {
q = NULL; /* no trailing slash */
}
- p = strrchr(path, '/'); /* separate path and filename */
- if (p) {
- fname = p + 1;
+ /* If no filename, strip last component of path as "filename" */
+ if (*fname == 0) {
+ p = strrchr(path, '/'); /* separate path and filename */
+ if (p) {
+ fname = p + 1; /* set new filename */
+ *p = 0; /* terminate new path */
+ }
+ } else {
+ p = NULL;
+ }
+ if (*fname) {
if (!parent) { /* if no parent, we need to make one */
- *p = 0; /* terminate path */
Dmsg1(100, "make_tree_path for %s\n", path);
path_len = strlen(path); /* get new length */
if (path_len == root->cached_path_len &&
root->cached_parent = parent;
}
Dmsg1(100, "parent=%s\n", parent->fname);
- *p = '/'; /* restore full path */
}
} else {
fname = path;
if (q) { /* if trailing slash on entry */
*q = '/'; /* restore it */
}
+ if (p) { /* if slash in path trashed */
+ *p = '/'; /* restore full path */
+ }
return node;
}
TREE_NODE *node, TREE_ROOT *root, TREE_NODE *parent)
{
TREE_NODE *sibling, *last_sibling = NULL;
-#ifdef SORT_SIBLINGS
uint16_t fname_len = strlen(fname);
int cmp;
/* Is it already a sibling? */
- for (sibling=parent->child; sibling; sibling=sibling->sibling) {
+ foreach_child(sibling, parent) {
Dmsg2(000, "sibling->fname=%s fname=%s\n", sibling->fname, fname);
if (fname[0] > sibling->fname[0] || (cmp=strcmp(fname, sibling->fname)) > 0) {
last_sibling = sibling;
if (!node) {
node = new_tree_node(root, type);
}
- node->sibling = sibling;
- if (sibling == parent->child) { /* if sibling was at head of list */
- parent->child = NULL; /* force parent to be updated below */
+ node->sibling_ = sibling;
+ if (sibling == first_child(parent)) { /* if sibling was at head of list */
+ parent->child_ = NULL; /* force parent to be updated below */
}
Dmsg2(000, "insert before sibling->fname=%s fname=%s\n", sibling->fname, fname);
break;
}
/* Found it */
+ sibling->inserted = false; /* already in tree */
return sibling;
}
-#else
- uint16_t fname_len = strlen(fname);
-
- /* Is it already a sibling? */
- for (sibling=parent->child; sibling; sibling=sibling->sibling) {
- Dmsg2(100, "sibling->fname=%s fname=%s\n", sibling->fname, fname);
- if (sibling->fname_len == fname_len &&
- strcmp(sibling->fname, fname) == 0) {
- Dmsg1(100, "make_tree_path: found parent=%s\n", parent->fname);
- return sibling;
- }
- last_sibling = sibling;
- }
-#endif
/*
node->fname = tree_alloc(root, node->fname_len + 1);
strcpy(node->fname, fname);
node->parent = parent;
- if (!parent->child) {
- parent->child = node;
+ if (!tree_node_has_child(parent)) {
+ parent->child_ = node;
} else {
- last_sibling->sibling = node;
+ last_sibling->sibling_ = node;
}
/* Maintain a linear chain of nodes */
root->last->next = node;
root->last = node;
}
+ node->inserted = true; /* inserted into tree */
return node;
}
* i.e. it is linked to a directory.
*/
if ((node->type != TN_FILE && !(buf[0] == '/' && buf[1] == 0)) ||
- (node->soft_link && node->child)) {
+ (node->soft_link && tree_node_has_child(node))) {
bstrncat(buf, "/", buf_size);
}
return 1;
len = strlen(path);
}
Dmsg2(100, "tree_relcwd: len=%d path=%s\n", len, path);
- for (cd=node->child; cd; cd=cd->sibling) {
+ foreach_child(cd, node) {
Dmsg1(100, "tree_relcwd: test cd=%s\n", cd->fname);
if (cd->fname[0] == path[0] && len == (int)strlen(cd->fname)
&& strncmp(cd->fname, path, len) == 0) {
break;
}
}
- if (!cd || (cd->type == TN_FILE && !cd->child)) {
+ if (!cd || (cd->type == TN_FILE && !tree_node_has_child(cd))) {
return NULL;
}
if (!p) {
case TN_DIR:
case TN_DIR_NLS:
bsnprintf(buf, sizeof(buf), "%s/%s", path, tree->fname);
- print_tree(buf, tree->child);
+ print_tree(buf, first_child(tree));
break;
case TN_ROOT:
- print_tree(path, tree->child);
+ print_tree(path, first_child(tree));
break;
default:
Pmsg1(000, "Unknown node type %d\n", tree->type);
}
- print_tree(path, tree->sibling);
+ print_tree(path, tree->sibling_);
return;
}
*/
struct s_mem {
- struct s_mem *next; /* next buffer */
- int rem; /* remaining bytes */
- char *mem; /* memory pointer */
- char first[1]; /* first byte */
+ struct s_mem *next; /* next buffer */
+ int rem; /* remaining bytes */
+ char *mem; /* memory pointer */
+ char first[1]; /* first byte */
};
+#define foreach_child(cld, node) \
+ for(cld=(node)->child_; cld; cld=cld->sibling_)
+
+#define tree_node_has_child(node) \
+ ((node)->child_ != NULL)
+
+#define first_child(node) \
+ ((node)->child_)
+
+
/*
* Keep this node as small as possible because
* there is one for each file.
*/
struct s_tree_node {
- char *fname; /* file name */
- int32_t FileIndex; /* file index */
- uint32_t JobId; /* JobId */
- uint16_t fname_len; /* filename length */
- int type: 8; /* node type */
- unsigned int extract: 1; /* extract item */
+ char *fname; /* file name */
+ int32_t FileIndex; /* file index */
+ uint32_t JobId; /* JobId */
+ uint16_t fname_len; /* filename length */
+ int type: 8; /* node type */
+ unsigned int extract: 1; /* extract item */
unsigned int extract_dir: 1; /* extract dir entry only */
- unsigned int hard_link: 1; /* set if have hard link */
- unsigned int soft_link: 1; /* set if is soft link */
+ unsigned int hard_link: 1; /* set if have hard link */
+ unsigned int soft_link: 1; /* set if is soft link */
+ unsigned int inserted: 1; /* set when newly inserted */
struct s_tree_node *parent;
- struct s_tree_node *sibling;
- struct s_tree_node *child;
- struct s_tree_node *next; /* next hash of FileIndex */
+ struct s_tree_node *sibling_;
+ struct s_tree_node *next; /* next hash of FileIndex */
+ struct s_tree_node *child_;
};
typedef struct s_tree_node TREE_NODE;
struct s_tree_root {
- char *fname; /* file name */
- int32_t FileIndex; /* file index */
- uint32_t JobId; /* JobId */
- uint16_t fname_len; /* filename length */
- unsigned int type: 8; /* node type */
- unsigned int extract: 1; /* extract item */
+ char *fname; /* file name */
+ int32_t FileIndex; /* file index */
+ uint32_t JobId; /* JobId */
+ uint16_t fname_len; /* filename length */
+ unsigned int type: 8; /* node type */
+ unsigned int extract: 1; /* extract item */
unsigned int extract_dir: 1; /* extract dir entry only */
- unsigned int have_link: 1; /* set if have hard link */
+ unsigned int have_link: 1; /* set if have hard link */
+ unsigned int inserted: 1; /* set when newly inserted */
struct s_tree_node *parent;
- struct s_tree_node *sibling;
- struct s_tree_node *child;
- struct s_tree_node *next; /* next hash of FileIndex */
+ struct s_tree_node *sibling_;
+ struct s_tree_node *next; /* next hash of FileIndex */
+ struct s_tree_node *child_;
/* The above ^^^ must be identical to a TREE_NODE structure */
- struct s_tree_node *first; /* first entry in the tree */
- struct s_tree_node *last; /* last entry in tree */
- struct s_mem *mem; /* tree memory */
- uint32_t total_size; /* total bytes allocated */
- uint32_t blocks; /* total mallocs */
- int cached_path_len; /* length of cached path */
- char *cached_path; /* cached current path */
- TREE_NODE *cached_parent; /* cached parent for above path */
+ struct s_tree_node *first; /* first entry in the tree */
+ struct s_tree_node *last; /* last entry in tree */
+ struct s_mem *mem; /* tree memory */
+ uint32_t total_size; /* total bytes allocated */
+ uint32_t blocks; /* total mallocs */
+ int cached_path_len; /* length of cached path */
+ char *cached_path; /* cached current path */
+ TREE_NODE *cached_parent; /* cached parent for above path */
};
typedef struct s_tree_root TREE_ROOT;
/* type values */
-#define TN_ROOT 1 /* root node */
-#define TN_NEWDIR 2 /* created directory to fill path */
-#define TN_DIR 3 /* directory entry */
-#define TN_DIR_NLS 4 /* directory -- no leading slash -- win32 */
-#define TN_FILE 5 /* file entry */
+#define TN_ROOT 1 /* root node */
+#define TN_NEWDIR 2 /* created directory to fill path */
+#define TN_DIR 3 /* directory entry */
+#define TN_DIR_NLS 4 /* directory -- no leading slash -- win32 */
+#define TN_FILE 5 /* file entry */
+/* External interface */
TREE_ROOT *new_tree(int count);
-TREE_NODE *new_tree_node(TREE_ROOT *root, int type);
-TREE_NODE *insert_tree_node(char *fname, TREE_NODE *node,
- TREE_ROOT *root, TREE_NODE *parent);
+TREE_NODE *insert_tree_node(char *path, char *fname, TREE_NODE *node,
+ TREE_ROOT *root, TREE_NODE *parent);
TREE_NODE *make_tree_path(char *path, TREE_ROOT *root);
TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node);
TREE_NODE *tree_relcwd(char *path, TREE_ROOT *root, TREE_NODE *node);
@echo " "
bacula-sd: $(SVROBJS) ../lib/libbac.a
- $(CXX) $(WLDFLAGS) $(LDFLAGS) -L../lib -o $@ $(SVROBJS) $(FDLIBS) -lbac -lm $(LIBS) $(DLIB)
+ $(CXX) $(WLDFLAGS) $(LDFLAGS) -L../lib -o $@ $(SVROBJS) $(FDLIBS) -lbac -lm $(DLIB) $(LIBS)
static-bacula-sd: $(SVROBJS) ../lib/libbac.a
- $(CXX) $(WLDFLAGS) $(LDFLAGS) -static -L../lib -o $@ $(SVROBJS) $(FDLIBS) -lbac -lm $(LIBS) $(DLIB)
+ $(CXX) $(WLDFLAGS) $(LDFLAGS) -static -L../lib -o $@ $(SVROBJS) $(FDLIBS) -lbac -lm $(DLIB) $(LIBS)
strip $@
btape.o: btape.c
$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
btape: $(TAPEOBJS) ../lib/libbac.a ../cats/libsql.a
- $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../cats -o $@ $(TAPEOBJS) -lsql $(LIBS) $(DLIB) -lbac -lm
+ $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../cats -o $@ $(TAPEOBJS) -lsql $(DLIB) -lbac -lm $(LIBS)
bls.o: bls.c
$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
bls: ../findlib/libfind.a $(BLSOBJS) ../lib/libbac.a
- $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BLSOBJS) $(LIBS) $(DLIB) -lfind -lbac -lm
+ $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BLSOBJS) $(DLIB) -lfind -lbac -lm $(LIBS)
bextract.o: bextract.c
$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
bextract: ../findlib/libfind.a $(BEXTOBJS) ../lib/libbac.a
- $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BEXTOBJS) $(LIBS) $(DLIB) $(FDLIBS) -lfind -lbac -lm
+ $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BEXTOBJS) $(DLIB) $(FDLIBS) -lfind -lbac -lm $(LIBS)
bscan.o: bscan.c
$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
bscan: ../findlib/libfind.a $(SCNOBJS) ../cats/libsql.a
- $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../cats -L../findlib -o $@ $(SCNOBJS) -lsql $(LIBS) $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm
+ $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../cats -L../findlib -o $@ $(SCNOBJS) -lsql $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS)
bcopy.o: bcopy.c
$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
bcopy: $(COPYOBJS) ../findlib/libfind.a ../lib/libbac.a
- $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(COPYOBJS) $(LIBS) $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm
+ $(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(COPYOBJS) $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS)
Makefile: $(srcdir)/Makefile.in $(topdir)/config.status
if (slot > 0 && jcr->device->changer_name && jcr->device->changer_command) {
uint32_t timeout = jcr->device->max_changer_wait;
- POOLMEM *changer, *results;
+ POOLMEM *changer;
int loaded, status;
- results = get_pool_memory(PM_MESSAGE);
changer = get_pool_memory(PM_FNAME);
loaded = get_autochanger_loaded_slot(jcr);
- Dmsg1(400, "loaded=%s\n", results);
-
/* If tape we want is not loaded, load it. */
if (loaded != slot) {
offline_or_rewind_dev(dev);
status = 0; /* we got what we want */
}
free_pool_memory(changer);
- free_pool_memory(results);
Dmsg1(400, "After changer, status=%d\n", status);
if (status == 0) { /* did we succeed? */
rtn_stat = 1; /* tape loaded by changer */
}
dev->VolCatInfo.VolCatWrites++;
- Dmsg1(300, "Write block of %u bytes\n", wlen);
+ Dmsg1(200, "Write block of %u bytes\n", wlen);
stat = write(dev->fd, block->buf, (size_t)wlen);
if (stat != (ssize_t)wlen) {
/* We should check for errno == ENOSPC, BUT many
if (dev->dev_errno == 0) {
dev->dev_errno = ENOSPC; /* out of space */
}
- Jmsg(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"),
+ Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"),
dev->file, dev->block_num, dev->dev_name, strerror(dev->dev_errno));
} else {
dev->dev_errno = ENOSPC; /* out of space */
@echo " "
bsmtp: bsmtp.o ../lib/libbac.a
- $(CXX) $(LDFLAGS) -L../lib -o $@ bsmtp.o -lbac -lm $(LIBS) $(DLIB)
+ $(CXX) $(LDFLAGS) -L../lib -o $@ bsmtp.o -lbac -lm $(DLIB) $(LIBS)
dbcheck: dbcheck.o ../lib/libbac.a ../cats/libsql.a $(DIRCONFOBJS)
- $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ dbcheck.o $(DIRCONFOBJS) -lsql -lbac -lm $(LIBS) $(DB_LIBS)
+ $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ dbcheck.o $(DIRCONFOBJS) -lsql -lbac -lm $(DB_LIBS) $(LIBS)
testfind: ../findlib/libfind.a ../lib/libbac.a $(FINDOBJS)
$(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ $(FINDOBJS) \
- $(LIBS) $(DLIB) -lfind -lbac -lm
+ $(DLIB) -lfind -lbac -lm $(LIBS)
testls: ../findlib/libfind.a ../lib/libbac.a testls.o
$(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ testls.o \
- $(LIBS) $(DLIB) -lfind -lbac -lm
+ $(DLIB) -lfind -lbac -lm $(LIBS)
Makefile: $(srcdir)/Makefile.in $(topdir)/config.status
cd $(topdir) \
#undef VERSION
#define VERSION "1.35.0"
#define VSTRING "1"
-#define BDATE "15 June 2004"
-#define LSMDATE "15Jun04"
+#define BDATE "16 June 2004"
+#define LSMDATE "16Jun04"
/* Debug flags */
#undef DEBUG