Skip to content

Commit

Permalink
daemons: fix issue with pid file option
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Jul 25, 2022
1 parent 2a2d528 commit 00260d0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
6 changes: 3 additions & 3 deletions core/src/dird/dird.cc
Expand Up @@ -95,7 +95,7 @@ static bool test_config = false;
struct resource_table_reference;
static alist<resource_table_reference*>* reload_table = nullptr;

static char* pidfile_path = nullptr;
static std::string pidfile_path;

/* Globals Imported */
extern ResourceItem job_items[];
Expand Down Expand Up @@ -297,8 +297,8 @@ int main(int argc, char* argv[])

int pidfile_fd = -1;
#if !defined(HAVE_WIN32)
if (!test_config && !foreground && pidfile_path) {
pidfile_fd = CreatePidFile("bareos-dir", pidfile_path);
if (!test_config && !foreground && !pidfile_path.empty()) {
pidfile_fd = CreatePidFile("bareos-dir", pidfile_path.c_str());
}
#endif
// See if we want to drop privs.
Expand Down
6 changes: 3 additions & 3 deletions core/src/filed/filed.cc
Expand Up @@ -51,7 +51,7 @@ extern bool PrintMessage(void* sock, const char* fmt, ...);
/* Forward referenced functions */
static bool CheckResources();

static char* pidfile_path = nullptr;
static std::string pidfile_path{};

/*********************************************************************
*
Expand Down Expand Up @@ -153,8 +153,8 @@ int main(int argc, char* argv[])

int pidfile_fd = -1;
#if !defined(HAVE_WIN32)
if (!foreground && !test_config && pidfile_path) {
pidfile_fd = CreatePidFile("bareos-fd", pidfile_path);
if (!foreground && !test_config && !pidfile_path.empty()) {
pidfile_fd = CreatePidFile("bareos-fd", pidfile_path.c_str());
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions core/src/lib/bsys.cc
Expand Up @@ -553,10 +553,10 @@ void WritePidFile(int pidfile_fd,
#endif

// Delete the pid file if we created it
int DeletePidFile(const char* pidfile_path)
int DeletePidFile(std::string pidfile_path)
{
#if !defined(HAVE_WIN32)
if (pidfile_path) { unlink(pidfile_path); }
if (!pidfile_path.empty()) { unlink(pidfile_path.c_str()); }
#endif
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/bsys.h
Expand Up @@ -45,7 +45,7 @@ int CreatePidFile(const char* progname, const char* pidfile_path);
void WritePidFile(int pidfile_fd,
const char* pidfile_path,
const char* progname);
int DeletePidFile(const char* pidfile_path);
int DeletePidFile(std::string pidfile_path);
void drop(char* uid, char* gid, bool keep_readall_caps);
int Bmicrosleep(int32_t sec, int32_t usec);
char* bfgets(char* s, int size, FILE* fd);
Expand Down
12 changes: 9 additions & 3 deletions core/src/lib/daemon.cc
Expand Up @@ -38,7 +38,9 @@

#if defined(HAVE_WIN32)

void daemon_start(const char* progname, int pidfile_fd, char* pidfile_path)
void daemon_start(const char* progname,
int pidfile_fd,
std::string pidfile_path)
{
return;
}
Expand All @@ -64,7 +66,9 @@ static void SetupStdFileDescriptors()
}
# endif // DEVELOPER

void daemon_start(const char* progname, int pidfile_fd, char* pidfile_path)
void daemon_start(const char* progname,
int pidfile_fd,
std::string pidfile_path)
{
Dmsg0(900, "Enter daemon_start\n");

Expand All @@ -73,7 +77,9 @@ void daemon_start(const char* progname, int pidfile_fd, char* pidfile_path)
setsid();
umask(umask(0) | S_IWGRP | S_IROTH | S_IWOTH);

if (pidfile_path) { WritePidFile(pidfile_fd, pidfile_path, progname); }
if (!pidfile_path.empty()) {
WritePidFile(pidfile_fd, pidfile_path.c_str(), progname);
}
SetupStdFileDescriptors();

break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/daemon.h
Expand Up @@ -21,6 +21,6 @@
#ifndef BAREOS_LIB_DAEMON_H_
#define BAREOS_LIB_DAEMON_H_

void daemon_start(const char* progname, int pidfile_fd, char* pidfilepath);
void daemon_start(const char* progname, int pidfile_fd, std::string pidfilepath);

#endif // BAREOS_LIB_DAEMON_H_
6 changes: 3 additions & 3 deletions core/src/stored/stored.cc
Expand Up @@ -83,7 +83,7 @@ static void CleanUpOldFiles();
extern "C" void* device_initialization(void* arg);

/* Global static variables */
static char* pidfile_path = nullptr;
static std::string pidfile_path;


/*********************************************************************
Expand Down Expand Up @@ -193,8 +193,8 @@ int main(int argc, char* argv[])

int pidfile_fd = -1;
#if !defined(HAVE_WIN32)
if (!foreground && !test_config && pidfile_path) {
pidfile_fd = CreatePidFile("bareos-sd", pidfile_path);
if (!foreground && !test_config && !pidfile_path.empty()) {
pidfile_fd = CreatePidFile("bareos-sd", pidfile_path.c_str());
}
#endif

Expand Down

0 comments on commit 00260d0

Please sign in to comment.