From eba054a713d9b4aedc59b8f122df273a4c626186 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 8 Sep 2023 13:13:22 +0200 Subject: [PATCH] daemons: tools: replace `1` exits with `BEXIT_FAILURE` --- core/src/console/console.cc | 4 ++-- core/src/dird/dbcheck.cc | 34 +++++++++++++++++----------------- core/src/dird/dbcheck_utils.cc | 15 +++++++++++---- core/src/dird/dird.cc | 2 +- core/src/filed/filed.cc | 4 ++-- core/src/lib/message.cc | 4 ++-- core/src/lib/signal.cc | 3 ++- core/src/stored/bcopy.cc | 12 ++++++------ core/src/stored/bextract.cc | 8 ++++---- core/src/stored/bls.cc | 8 ++++---- core/src/stored/bscan.cc | 2 +- core/src/stored/btape.cc | 13 +++++++------ core/src/stored/stored.cc | 2 +- core/src/tests/dlist_test.cc | 3 ++- core/src/tools/bregex.cc | 3 ++- core/src/tools/bsmtp.cc | 34 +++++++++++++++++----------------- core/src/tools/btestls.cc | 6 +++--- core/src/tools/bwild.cc | 2 +- core/src/tools/testfind.cc | 2 +- 19 files changed, 86 insertions(+), 75 deletions(-) diff --git a/core/src/console/console.cc b/core/src/console/console.cc index 40f68692c1b..458f6d0f090 100644 --- a/core/src/console/console.cc +++ b/core/src/console/console.cc @@ -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(); @@ -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; } diff --git a/core/src/dird/dbcheck.cc b/core/src/dird/dbcheck.cc index 9d247a4ca49..a65c592628f 100644 --- a/core/src/dird/dbcheck.cc +++ b/core/src/dird/dbcheck.cc @@ -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): "))) { @@ -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]); } @@ -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); @@ -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); } @@ -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); @@ -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); } @@ -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); @@ -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); } } } @@ -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): "))) { @@ -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++) { @@ -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): "))) { @@ -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++) { @@ -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++) { @@ -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++) { @@ -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): "))) { @@ -890,7 +890,7 @@ int main(int argc, char* argv[]) "[%s]\n"), configfile.c_str()); } - exit(1); + exit(BEXIT_FAILURE); } else { { ResLocker _{my_config}; @@ -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); diff --git a/core/src/dird/dbcheck_utils.cc b/core/src/dird/dbcheck_utils.cc index d6e44184c8e..0710889cbb2 100644 --- a/core/src/dird/dbcheck_utils.cc +++ b/core/src/dird/dbcheck_utils.cc @@ -20,6 +20,7 @@ */ #include "dbcheck_utils.h" +#include "include/exit_codes.h" using namespace directordaemon; @@ -166,7 +167,9 @@ std::vector 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 storage_ids_to_delete; NameList volume_names = {}; @@ -178,7 +181,9 @@ std::vector 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; @@ -197,7 +202,9 @@ std::vector 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; @@ -240,7 +247,7 @@ std::vector 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 orphaned_storage_names_list; diff --git a/core/src/dird/dird.cc b/core/src/dird/dird.cc index d992e4eafe4..9bdb35c182f 100644 --- a/core/src/dird/dird.cc +++ b/core/src/dird/dird.cc @@ -390,7 +390,7 @@ static if (is_reloading) { /* avoid recursive termination problems */ Bmicrosleep(2, 0); /* yield */ - exit(1); + exit(BEXIT_FAILURE); } is_reloading = true; diff --git a/core/src/filed/filed.cc b/core/src/filed/filed.cc index d985bb5b539..258ccd6b4af 100644 --- a/core/src/filed/filed.cc +++ b/core/src/filed/filed.cc @@ -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 */ diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc index bd36bfe164c..57f29acb95f 100644 --- a/core/src/lib/message.cc +++ b/core/src/lib/message.cc @@ -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); } @@ -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); } diff --git a/core/src/lib/signal.cc b/core/src/lib/signal.cc index dc1d835c05c..bb140245a47 100644 --- a/core/src/lib/signal.cc +++ b/core/src/lib/signal.cc @@ -37,6 +37,7 @@ # include # include # include "include/bareos.h" +# include "include/exit_codes.h" # include "lib/watchdog.h" # include "lib/berrno.h" # include "lib/bsignal.h" @@ -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 diff --git a/core/src/stored/bcopy.cc b/core/src/stored/bcopy.cc index 69aeed7d185..013190ea36f 100644 --- a/core/src/stored/bcopy.cc +++ b/core/src/stored/bcopy.cc @@ -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) @@ -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) @@ -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; diff --git a/core/src/stored/bextract.cc b/core/src/stored/bextract.cc index f05b6194f51..812674e278f 100644 --- a/core/src/stored/bextract.cc +++ b/core/src/stored/bextract.cc @@ -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); @@ -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); @@ -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 diff --git a/core/src/stored/bls.cc b/core/src/stored/bls.cc index 4fcf46d46dc..0841994fdc4 100644 --- a/core/src/stored/bls.cc +++ b/core/src/stored/bls.cc @@ -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); @@ -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); @@ -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 @@ -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); diff --git a/core/src/stored/bscan.cc b/core/src/stored/bscan.cc index b8e10b1a4c6..23516e9463b 100644 --- a/core/src/stored/bscan.cc +++ b/core/src/stored/bscan.cc @@ -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 diff --git a/core/src/stored/btape.cc b/core/src/stored/btape.cc index dcde82519ae..3d841e4c04d 100644 --- a/core/src/stored/btape.cc +++ b/core/src/stored/btape.cc @@ -36,6 +36,7 @@ #include "include/fcntl_def.h" #include "include/bareos.h" +#include "include/exit_codes.h" #include "include/streams.h" #include "stored/stored.h" #include "stored/stored_globals.h" @@ -213,7 +214,7 @@ int main(int margc, char* margv[]) if (i != 1 || x32 != y32) { Pmsg3(-1, _("32 bit printf/scanf problem. i=%d x32=%u y32=%u\n"), i, x32, y32); - exit(1); + exit(BEXIT_FAILURE); } uint64_t x64 = 123456789; @@ -226,7 +227,7 @@ int main(int margc, char* margv[]) if (i != 1 || x64 != y64) { Pmsg3(-1, _("64 bit printf/scanf problem. i=%d x64=%llu y64=%llu\n"), i, x64, y64); - exit(1); + exit(BEXIT_FAILURE); } working_directory = "/tmp"; @@ -325,14 +326,14 @@ int main(int margc, char* margv[]) dcr = new BTAPE_DCR; jcr = SetupJcr("btape", archive_name.data(), bsr, director, dcr, "", false); /* write device */ - if (!jcr) { exit(1); } + if (!jcr) { exit(BEXIT_FAILURE); } dev = jcr->sd_impl->dcr->dev; - if (!dev) { exit(1); } + if (!dev) { exit(BEXIT_FAILURE); } if (!dev->IsTape()) { Pmsg0(000, _("btape only works with tape storage.\n")); - exit(1); + exit(BEXIT_FAILURE); } // Let SD plugins setup the record translation @@ -340,7 +341,7 @@ int main(int margc, char* margv[]) Jmsg(jcr, M_FATAL, 0, _("bSdEventSetupRecordTranslation call failed!\n")); } - if (!open_the_device()) { exit(1); } + if (!open_the_device()) { exit(BEXIT_FAILURE); } Dmsg0(200, "Do tape commands\n"); do_tape_cmds(); diff --git a/core/src/stored/stored.cc b/core/src/stored/stored.cc index 276d5f21326..b903d467534 100644 --- a/core/src/stored/stored.cc +++ b/core/src/stored/stored.cc @@ -589,7 +589,7 @@ static if (in_here) { /* prevent loops */ Bmicrosleep(2, 0); /* yield */ - exit(1); + exit(BEXIT_FAILURE); } in_here = true; debug_level = 0; /* turn off any debug */ diff --git a/core/src/tests/dlist_test.cc b/core/src/tests/dlist_test.cc index 6be764c8146..6b4d0e4e77f 100644 --- a/core/src/tests/dlist_test.cc +++ b/core/src/tests/dlist_test.cc @@ -34,6 +34,7 @@ # include "gtest/gtest.h" # include "include/bareos.h" #endif +#include "include/exit_codes.h" #include "lib/dlist.h" #include @@ -281,7 +282,7 @@ TEST(dlist, BinaryInsert) foreach_dlist (jcr, jcr_chain) { if (!jcr_chain->binary_search(jcr, MyCompare)) { printf("Dlist binary_search item not found = %s\n", jcr->buf); - exit(1); + exit(BEXIT_FAILURE); } } foreach_dlist (jcr, jcr_chain) { diff --git a/core/src/tools/bregex.cc b/core/src/tools/bregex.cc index ac927ebe696..87669e540ca 100644 --- a/core/src/tools/bregex.cc +++ b/core/src/tools/bregex.cc @@ -26,6 +26,7 @@ */ #include "include/bareos.h" +#include "include/exit_codes.h" #include "lib/cli.h" #ifndef HAVE_REGEX_H @@ -86,7 +87,7 @@ int main(int argc, char** argv) fd = fopen(fname.c_str(), "r"); if (!fd) { printf(_("Could not open data file: %s\n"), fname.c_str()); - exit(1); + exit(BEXIT_FAILURE); } lineno = 0; while (fgets(data, sizeof(data) - 1, fd)) { diff --git a/core/src/tools/bsmtp.cc b/core/src/tools/bsmtp.cc index 8e10494a651..c08ee1574ac 100644 --- a/core/src/tools/bsmtp.cc +++ b/core/src/tools/bsmtp.cc @@ -125,7 +125,7 @@ static void GetResponse(const std::string& mailhost) Dmsg2(10, "%s --> %s\n", mailhost.c_str(), buf); if (!isdigit((int)buf[0]) || buf[0] > '3') { Pmsg2(0, _("Fatal malformed reply from %s: %s\n"), mailhost.c_str(), buf); - exit(1); + exit(BEXIT_FAILURE); } if (buf[3] != '-') { break; } } @@ -339,7 +339,7 @@ int main(int argc, char* argv[]) char my_hostname[MAXSTRING]; if (gethostname(my_hostname, sizeof(my_hostname) - 1) < 0) { Pmsg1(0, _("Fatal gethostname error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } #ifdef HAVE_GETADDRINFO @@ -357,7 +357,7 @@ int main(int argc, char* argv[]) if ((res = getaddrinfo(my_hostname, NULL, &hints, &ai)) != 0) { Pmsg2(0, _("Fatal getaddrinfo for myself failed \"%s\": ERR=%s\n"), my_hostname, gai_strerror(res)); - exit(1); + exit(BEXIT_FAILURE); } strncpy(my_hostname, ai->ai_canonname, sizeof(my_hostname) - 1); my_hostname[sizeof(my_hostname) - 1] = '\0'; @@ -369,7 +369,7 @@ int main(int argc, char* argv[]) if ((hp = gethostbyname(my_hostname)) == NULL) { Pmsg2(0, _("Fatal gethostbyname for myself failed \"%s\": ERR=%s\n"), my_hostname, strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } strncpy(my_hostname, hp->h_name, sizeof(my_hostname) - 1); my_hostname[sizeof(my_hostname) - 1] = '\0'; @@ -433,7 +433,7 @@ int main(int argc, char* argv[]) mailhost = "localhost"; goto lookup_host; } - exit(1); + exit(BEXIT_FAILURE); } # if defined(HAVE_WIN32) @@ -456,7 +456,7 @@ int main(int argc, char* argv[]) if (!rp) { Pmsg1(0, _("Failed to connect to mailhost %s\n"), mailhost.c_str()); - exit(1); + exit(BEXIT_FAILURE); } freeaddrinfo(ai); @@ -469,13 +469,13 @@ int main(int argc, char* argv[]) mailhost = "localhost"; goto lookup_host; } - exit(1); + exit(BEXIT_FAILURE); } if (hp->h_addrtype != AF_INET) { Pmsg1(0, _("Fatal error: Unknown address family for smtp host: %d\n"), hp->h_addrtype); - exit(1); + exit(BEXIT_FAILURE); } memset((char*)&sin, 0, sizeof(sin)); memcpy((char*)&sin.sin_addr, hp->h_addr, hp->h_length); @@ -484,18 +484,18 @@ int main(int argc, char* argv[]) # if defined(HAVE_WIN32) if ((s = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) < 0) { Pmsg1(0, _("Fatal socket error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } # else if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { Pmsg1(0, _("Fatal socket error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } # endif if (connect(s, (struct sockaddr*)&sin, sizeof(sin)) < 0) { Pmsg2(0, _("Fatal connect error to %s: ERR=%s\n"), mailhost.c_str(), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } Dmsg0(20, "Connected\n"); #endif @@ -504,31 +504,31 @@ int main(int argc, char* argv[]) int fdSocket = _open_osfhandle(s, _O_RDWR | _O_BINARY); if (fdSocket == -1) { Pmsg1(0, _("Fatal _open_osfhandle error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } int fdSocket2 = dup(fdSocket); if ((sfp = fdopen(fdSocket, "wb")) == NULL) { Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } if ((rfp = fdopen(fdSocket2, "rb")) == NULL) { Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } #else if ((r = dup(s)) < 0) { Pmsg1(0, _("Fatal dup error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } if ((sfp = fdopen(s, "w")) == 0) { Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } if ((rfp = fdopen(r, "r")) == 0) { Pmsg1(0, _("Fatal fdopen error: ERR=%s\n"), strerror(errno)); - exit(1); + exit(BEXIT_FAILURE); } #endif diff --git a/core/src/tools/btestls.cc b/core/src/tools/btestls.cc index 5f139eee5ee..46ae3c10b1d 100644 --- a/core/src/tools/btestls.cc +++ b/core/src/tools/btestls.cc @@ -80,7 +80,7 @@ static void usage() "Truncation is only in catalog.\n" "\n")); - exit(1); + exit(BEXIT_FAILURE); } @@ -155,7 +155,7 @@ int main(int argc, char* const* argv) fd = fopen(inc, "rb"); if (!fd) { printf(_("Could not open include file: %s\n"), inc); - exit(1); + exit(BEXIT_FAILURE); } while (fgets(name, sizeof(name) - 1, fd)) { StripTrailingJunk(name); @@ -168,7 +168,7 @@ int main(int argc, char* const* argv) fd = fopen(exc, "rb"); if (!fd) { printf(_("Could not open exclude file: %s\n"), exc); - exit(1); + exit(BEXIT_FAILURE); } while (fgets(name, sizeof(name) - 1, fd)) { StripTrailingJunk(name); diff --git a/core/src/tools/bwild.cc b/core/src/tools/bwild.cc index ca757c217ab..e81d29f8869 100644 --- a/core/src/tools/bwild.cc +++ b/core/src/tools/bwild.cc @@ -79,7 +79,7 @@ int main(int argc, char** argv) fd = fopen(fname.c_str(), "r"); if (!fd) { printf(_("Could not open data file: %s\n"), fname.c_str()); - exit(1); + exit(BEXIT_FAILURE); } lineno = 0; while (fgets(data, sizeof(data) - 1, fd)) { diff --git a/core/src/tools/testfind.cc b/core/src/tools/testfind.cc index 263e6738d05..ca80e41c38f 100644 --- a/core/src/tools/testfind.cc +++ b/core/src/tools/testfind.cc @@ -78,7 +78,7 @@ int main(int argc, char** argv) foreach_res (var, R_FILESET) { std::cerr << " " << var->resource_name_ << std::endl; } - exit(1); + exit(BEXIT_FAILURE); } ProcessFileset(dir_fileset, configfile.c_str());