Skip to content

Commit

Permalink
Fix state file truncation when running bareos-dir -t
Browse files Browse the repository at this point in the history
When bareos-dir -t is run (which is done from the systemd startup) we
never read the state-file nor create a pid-file but in the
terminate_dird() function we unconditionally write a new state-file
which means we clobber its content.

We now keep track of the test_config flag using a static global variable
and don't try updating the state-file nor removing the pid-file in
terminate_dird() when we are in test_config mode.

Also made the terminate_dird() and terminate_stored() static as they are
not referenced from anywhere else anyway so lets not clobber the
namespace with it.

Fixes #499: Director state file gets truncated
  • Loading branch information
Marco van Wieringen committed Aug 14, 2015
1 parent b7ea430 commit 6dd8b29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/dird/dird.c
Expand Up @@ -42,7 +42,7 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
#endif

/* Forward referenced subroutines */
void terminate_dird(int sig);
static void terminate_dird(int sig);
static bool check_resources();
static bool initialize_sql_pooling(void);
static void cleanup_old_files();
Expand All @@ -66,6 +66,7 @@ void init_device_resources();

static char *runjob = NULL;
static bool background = true;
static bool test_config = false;
static void init_reload(void);

/* Globals Exported */
Expand Down Expand Up @@ -155,7 +156,6 @@ int main (int argc, char *argv[])
JCR *jcr;
cat_op mode;
bool no_signals = false;
bool test_config = false;
bool export_config_schema = false;
char *uid = NULL;
char *gid = NULL;
Expand Down Expand Up @@ -405,8 +405,10 @@ void terminate_dird(int sig)
db_sql_pool_destroy();
db_flush_backends();
unload_dir_plugins();
write_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
delete_pid_file(me->pid_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
if (!test_config) { /* we don't need to do this block in test mode */
write_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
delete_pid_file(me->pid_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs));
}
term_scheduler();
term_job_server();

Expand Down
4 changes: 2 additions & 2 deletions src/stored/stored.c
Expand Up @@ -39,7 +39,7 @@
extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code);

/* Forward referenced functions */
void terminate_stored(int sig);
static void terminate_stored(int sig);
static int check_resources();
static void cleanup_old_files();

Expand Down Expand Up @@ -667,7 +667,7 @@ void *device_initialization(void *arg)
/*
* Clean up and then exit
*/
void terminate_stored(int sig)
static void terminate_stored(int sig)
{
static bool in_here = false;
DEVRES *device;
Expand Down

0 comments on commit 6dd8b29

Please sign in to comment.