Skip to content

Commit

Permalink
daemons: tools: replace 1 exits with BEXIT_FAILURE
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Sep 20, 2023
1 parent 17b1300 commit eba054a
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 75 deletions.
4 changes: 2 additions & 2 deletions core/src/console/console.cc
Expand Up @@ -1107,7 +1107,7 @@ static void TerminateConsole(int sig)
static bool already_here = false;

if (already_here) { /* avoid recursive temination problems */
exit(1);
exit(BEXIT_FAILURE);
}
already_here = true;
StopWatchdog();
Expand All @@ -1118,7 +1118,7 @@ static void TerminateConsole(int sig)
ConTerm();
WSACleanup(); /* Cleanup Windows sockets */

if (sig != 0) { exit(1); }
if (sig != 0) { exit(BEXIT_FAILURE); }
return;
}

Expand Down
34 changes: 17 additions & 17 deletions core/src/dird/dbcheck.cc
Expand Up @@ -230,7 +230,7 @@ static void eliminate_duplicate_paths()
= "SELECT Path, count(Path) as Count FROM Path "
"GROUP BY Path HAVING count(Path) > 1";

if (!MakeNameList(db, query, &name_list)) { exit(1); }
if (!MakeNameList(db, query, &name_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d duplicate Path records.\n"), name_list.num_ids);
fflush(stdout);
if (name_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand All @@ -246,7 +246,7 @@ static void eliminate_duplicate_paths()
Bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'",
esc_name);
if (verbose > 1) { printf("%s\n", buf); }
if (!MakeIdList(db, buf, &id_list)) { exit(1); }
if (!MakeIdList(db, buf, &id_list)) { exit(BEXIT_FAILURE); }
if (verbose) {
printf(_("Found %d for: %s\n"), id_list.num_ids, name_list.name[i]);
}
Expand Down Expand Up @@ -279,7 +279,7 @@ static void eliminate_orphaned_jobmedia_records()

printf(_("Checking for orphaned JobMedia entries.\n"));
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
// Loop doing 300000 at a time
while (id_list.num_ids != 0) {
printf(_("Found %d orphaned JobMedia records.\n"), id_list.num_ids);
Expand All @@ -305,7 +305,7 @@ static void eliminate_orphaned_jobmedia_records()
} else {
break; /* get out if not updating db */
}
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
}
fflush(stdout);
}
Expand All @@ -320,7 +320,7 @@ static void eliminate_orphaned_file_records()
printf(_("Checking for orphaned File entries. This may take some time!\n"));
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
// Loop doing 300000 at a time
while (id_list.num_ids != 0) {
printf(_("Found %d orphaned File records.\n"), id_list.num_ids);
Expand All @@ -343,7 +343,7 @@ static void eliminate_orphaned_file_records()
} else {
break; /* get out if not updating db */
}
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
}
fflush(stdout);
}
Expand All @@ -361,7 +361,7 @@ static void eliminate_orphaned_path_records()
printf(_("Checking for orphaned Path entries. This may take some time!\n"));
if (verbose > 1) { printf("%s\n", query.c_str()); }
fflush(stdout);
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(BEXIT_FAILURE); }
// Loop doing 300000 at a time
while (id_list.num_ids != 0) {
printf(_("Found %d orphaned Path records.\n"), id_list.num_ids);
Expand All @@ -383,7 +383,7 @@ static void eliminate_orphaned_path_records()
} else {
break; /* get out if not updating db */
}
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(BEXIT_FAILURE); }
}
}

Expand All @@ -398,7 +398,7 @@ static void eliminate_orphaned_fileset_records()
"WHERE Job.FileSetId IS NULL";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d orphaned FileSet records.\n"), id_list.num_ids);
fflush(stdout);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand Down Expand Up @@ -439,7 +439,7 @@ static void eliminate_orphaned_client_records()
"WHERE Job.ClientId IS NULL";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d orphaned Client records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (int i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -479,7 +479,7 @@ static void eliminate_orphaned_job_records()
"WHERE Client.Name IS NULL";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d orphaned Job records.\n"), id_list.num_ids);
fflush(stdout);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand Down Expand Up @@ -552,7 +552,7 @@ static void eliminate_admin_records()
"WHERE Job.Type='D'";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d Admin Job records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (int i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -585,7 +585,7 @@ static void eliminate_restore_records()
"WHERE Job.Type='R'";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d Restore Job records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (int i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -619,7 +619,7 @@ static void repair_bad_filenames()
"WHERE Name LIKE '%/'";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d bad Filename records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -676,7 +676,7 @@ static void repair_bad_paths()
db->FillQuery(query, BareosDb::SQL_QUERY::get_bad_paths_0);
if (verbose > 1) { printf("%s\n", query.c_str()); }
fflush(stdout);
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d bad Path records.\n"), id_list.num_ids);
fflush(stdout);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand Down Expand Up @@ -890,7 +890,7 @@ int main(int argc, char* argv[])
"[%s]\n"),
configfile.c_str());
}
exit(1);
exit(BEXIT_FAILURE);
} else {
{
ResLocker _{my_config};
Expand All @@ -899,7 +899,7 @@ int main(int argc, char* argv[])
}
if (!me) {
Pmsg0(0, _("Error no Director resource defined.\n"));
exit(1);
exit(BEXIT_FAILURE);
}

SetWorkingDirectory(me->working_directory);
Expand Down
15 changes: 11 additions & 4 deletions core/src/dird/dbcheck_utils.cc
Expand Up @@ -20,6 +20,7 @@
*/

#include "dbcheck_utils.h"
#include "include/exit_codes.h"

using namespace directordaemon;

Expand Down Expand Up @@ -166,7 +167,9 @@ std::vector<int> get_deletable_storageids(
query += ")";

ID_LIST orphaned_storage_ids_list{};
if (!MakeIdList(db, query.c_str(), &orphaned_storage_ids_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &orphaned_storage_ids_list)) {
exit(BEXIT_FAILURE);
}

std::vector<int> storage_ids_to_delete;
NameList volume_names = {};
Expand All @@ -178,7 +181,9 @@ std::vector<int> get_deletable_storageids(
= "SELECT volumename FROM media WHERE storageid="
+ std::to_string(orphaned_storage_ids_list.Id[orphaned_storage_id]);

if (!MakeNameList(db, media_query.c_str(), &volume_names)) { exit(1); }
if (!MakeNameList(db, media_query.c_str(), &volume_names)) {
exit(BEXIT_FAILURE);
}

if (volume_names.num_ids > 0) {
for (int volumename = 0; volumename < volume_names.num_ids;
Expand All @@ -197,7 +202,9 @@ std::vector<int> get_deletable_storageids(
= "SELECT name FROM device WHERE storageid="
+ std::to_string(orphaned_storage_ids_list.Id[orphaned_storage_id]);

if (!MakeNameList(db, device_query.c_str(), &device_names)) { exit(1); }
if (!MakeNameList(db, device_query.c_str(), &device_names)) {
exit(BEXIT_FAILURE);
}

if (device_names.num_ids > 0) {
for (int devicename = 0; devicename < device_names.num_ids;
Expand Down Expand Up @@ -240,7 +247,7 @@ std::vector<std::string> get_orphaned_storages_names(BareosDb* db)

NameList database_storage_names_list{};
if (!MakeNameList(db, query.c_str(), &database_storage_names_list)) {
exit(1);
exit(BEXIT_FAILURE);
}

std::vector<std::string> orphaned_storage_names_list;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/dird.cc
Expand Up @@ -390,7 +390,7 @@ static

if (is_reloading) { /* avoid recursive termination problems */
Bmicrosleep(2, 0); /* yield */
exit(1);
exit(BEXIT_FAILURE);
}

is_reloading = true;
Expand Down
4 changes: 2 additions & 2 deletions core/src/filed/filed.cc
Expand Up @@ -259,8 +259,8 @@ void TerminateFiled(int sig)
static bool already_here = false;

if (already_here) {
Bmicrosleep(2, 0); /* yield */
exit(1); /* prevent loops */
Bmicrosleep(2, 0); /* yield */
exit(BEXIT_FAILURE); /* prevent loops */
}
already_here = true;
debug_level = 0; /* turn off debug */
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib/message.cc
Expand Up @@ -1197,7 +1197,7 @@ void e_msg(const char* file,
if (type == M_ABORT) {
abort();
} else if (type == M_ERROR_TERM) {
exit(1);
exit(BEXIT_FAILURE);
} else if (type == M_CONFIG_ERROR) {
exit(BEXIT_CONFIG_ERROR);
}
Expand Down Expand Up @@ -1324,7 +1324,7 @@ void Jmsg(JobControlRecord* jcr, int type, utime_t mtime, const char* fmt, ...)
syslog(LOG_DAEMON | LOG_ERR, "BAREOS aborting to obtain traceback.\n");
abort();
} else if (type == M_ERROR_TERM) {
exit(1);
exit(BEXIT_FAILURE);
} else if (type == M_CONFIG_ERROR) {
exit(BEXIT_CONFIG_ERROR);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/lib/signal.cc
Expand Up @@ -37,6 +37,7 @@
# include <sys/wait.h>
# include <unistd.h>
# include "include/bareos.h"
# include "include/exit_codes.h"
# include "lib/watchdog.h"
# include "lib/berrno.h"
# include "lib/bsignal.h"
Expand Down Expand Up @@ -115,7 +116,7 @@ extern "C" void SignalHandler(int sig)
int chld_status = -1;

// If we come back more than once, get out fast!
if (already_dead) { exit(1); }
if (already_dead) { exit(BEXIT_FAILURE); }
Dmsg2(900, "sig=%d %s\n", sig, sig_names[sig]);

// Ignore certain signals -- SIGUSR2 used to interrupt threads
Expand Down
12 changes: 6 additions & 6 deletions core/src/stored/bcopy.cc
Expand Up @@ -195,12 +195,12 @@ int main(int argc, char* argv[])
DeviceControlRecord* in_dcr = new DeviceControlRecord;
in_jcr = SetupJcr("bcopy", input_archive.data(), bsr, director, in_dcr,
inputVolumes, true); /* read device */
if (!in_jcr) { exit(1); }
if (!in_jcr) { exit(BEXIT_FAILURE); }

in_jcr->sd_impl->ignore_label_errors = ignore_label_errors;

in_dev = in_jcr->sd_impl->dcr->dev;
if (!in_dev) { exit(1); }
if (!in_dev) { exit(BEXIT_FAILURE); }

// Let SD plugins setup the record translation
if (GeneratePluginEvent(in_jcr, bSdEventSetupRecordTranslation, in_dcr)
Expand All @@ -216,10 +216,10 @@ int main(int argc, char* argv[])
DeviceControlRecord* out_dcr = new DeviceControlRecord;
out_jcr = SetupJcr("bcopy", output_archive.data(), bsr, director, out_dcr,
outputVolumes, false); /* write device */
if (!out_jcr) { exit(1); }
if (!out_jcr) { exit(BEXIT_FAILURE); }

out_dev = out_jcr->sd_impl->dcr->dev;
if (!out_dev) { exit(1); }
if (!out_dev) { exit(BEXIT_FAILURE); }

// Let SD plugins setup the record translation
if (GeneratePluginEvent(out_jcr, bSdEventSetupRecordTranslation, out_dcr)
Expand All @@ -235,12 +235,12 @@ int main(int argc, char* argv[])
if (!out_dev->open(out_jcr->sd_impl->dcr, DeviceMode::OPEN_READ_WRITE)) {
Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), out_dev->errmsg);
out_dev->Unlock();
exit(1);
exit(BEXIT_FAILURE);
}
out_dev->Unlock();
if (!AcquireDeviceForAppend(out_jcr->sd_impl->dcr)) {
FreeJcr(in_jcr);
exit(1);
exit(BEXIT_FAILURE);
}
out_block = out_jcr->sd_impl->dcr->block;

Expand Down
8 changes: 4 additions & 4 deletions core/src/stored/bextract.cc
Expand Up @@ -155,7 +155,7 @@ int main(int argc, char* argv[])
BErrNo be;
Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"),
val.front().c_str(), be.bstrerror());
exit(1);
exit(BEXIT_FAILURE);
}
while (fgets(line, sizeof(line), fd) != nullptr) {
StripTrailingJunk(line);
Expand All @@ -178,7 +178,7 @@ int main(int argc, char* argv[])
BErrNo be;
Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"),
val.front().c_str(), be.bstrerror());
exit(1);
exit(BEXIT_FAILURE);
}
while (fgets(line, sizeof(line), fd) != nullptr) {
StripTrailingJunk(line);
Expand Down Expand Up @@ -398,9 +398,9 @@ static void DoExtract(char* devname,
dcr = new DeviceControlRecord;
jcr = SetupJcr("bextract", devname, bsr, director, dcr, VolumeName,
true); /* read device */
if (!jcr) { exit(1); }
if (!jcr) { exit(BEXIT_FAILURE); }
dev = jcr->sd_impl->read_dcr->dev;
if (!dev) { exit(1); }
if (!dev) { exit(BEXIT_FAILURE); }
dcr = jcr->sd_impl->read_dcr;

// Let SD plugins setup the record translation
Expand Down
8 changes: 4 additions & 4 deletions core/src/stored/bls.cc
Expand Up @@ -138,7 +138,7 @@ int main(int argc, char* argv[])
BErrNo be;
Pmsg2(0, _("Could not open exclude file: %s, ERR=%s\n"),
val.front().c_str(), be.bstrerror());
exit(1);
exit(BEXIT_FAILURE);
}
while (fgets(line, sizeof(line), fd) != nullptr) {
StripTrailingJunk(line);
Expand All @@ -159,7 +159,7 @@ int main(int argc, char* argv[])
BErrNo be;
Pmsg2(0, _("Could not open include file: %s, ERR=%s\n"),
val.front().c_str(), be.bstrerror());
exit(1);
exit(BEXIT_FAILURE);
}
while (fgets(line, sizeof(line), fd) != nullptr) {
StripTrailingJunk(line);
Expand Down Expand Up @@ -241,7 +241,7 @@ int main(int argc, char* argv[])
dcr = new DeviceControlRecord;
jcr = SetupJcr("bls", device.data(), bsr, director, dcr, VolumeNames,
true); /* read device */
if (!jcr) { exit(1); }
if (!jcr) { exit(BEXIT_FAILURE); }


// Let SD plugins setup the record translation
Expand All @@ -252,7 +252,7 @@ int main(int argc, char* argv[])

jcr->sd_impl->ignore_label_errors = ignore_label_errors;
dev = jcr->sd_impl->dcr->dev;
if (!dev) { exit(1); }
if (!dev) { exit(BEXIT_FAILURE); }
dcr = jcr->sd_impl->dcr;
rec = new_record();
attr = new_attr(jcr);
Expand Down
2 changes: 1 addition & 1 deletion core/src/stored/bscan.cc
Expand Up @@ -290,7 +290,7 @@ int main(int argc, char* argv[])
DeviceControlRecord* dcr = new DeviceControlRecord;
bjcr = SetupJcr("bscan", device_name.data(), bsr, director, dcr, volumes,
true);
if (!bjcr) { exit(1); }
if (!bjcr) { exit(BEXIT_FAILURE); }
dev = bjcr->sd_impl->read_dcr->dev;

// Let SD plugins setup the record translation
Expand Down

0 comments on commit eba054a

Please sign in to comment.