Skip to content

Commit 7538e56

Browse files
zehamind04
authored andcommitted
Fix zone2{sql,json} exit codes
To be consistent with general practice, fix zone2{sql,json} to exit with: * 0 on success * 1 on error This also moves the catch block after the last line of main, so a "theoretically" possible exception in ::arg().mustDo would get caught. (Also, one level less of indent!)
1 parent 7593c40 commit 7538e56

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

pdns/backends/bind/zone2json.cc

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ ArgvMap &arg()
122122

123123

124124
int main(int argc, char **argv)
125+
try
125126
{
126127
vector<string> lines;
127128

128-
try {
129129
reportAllTypes();
130130
reportFancyTypes();
131131
#if __GNUC__ >= 3
@@ -232,21 +232,19 @@ int main(int argc, char **argv)
232232
num_domainsdone=1;
233233
}
234234
cerr<<num_domainsdone<<" domains were fully parsed, containing "<<g_numRecords<<" records\n";
235+
236+
return 0;
235237

236-
}
237-
catch(AhuException &ae) {
238-
cerr<<"\nFatal error: "<<ae.reason<<endl;
239-
return 0;
240-
}
241-
catch(std::exception &e) {
242-
cerr<<"died because of STL error: "<<e.what()<<endl;
243-
exit(0);
244-
}
245-
catch(...) {
246-
cerr<<"died because of unknown exception"<<endl;
247-
exit(0);
248-
}
249-
238+
}
239+
catch(AhuException &ae) {
240+
cerr<<"\nFatal error: "<<ae.reason<<endl;
241+
return 1;
242+
}
243+
catch(std::exception &e) {
244+
cerr<<"\ndied because of STL error: "<<e.what()<<endl;
245+
return 1;
246+
}
247+
catch(...) {
248+
cerr<<"\ndied because of unknown exception"<<endl;
250249
return 1;
251-
252250
}

pdns/backends/bind/zone2sql.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ ArgvMap &arg()
241241

242242

243243
int main(int argc, char **argv)
244+
try
244245
{
245-
try {
246246
reportAllTypes();
247247
reportFancyTypes();
248248
#if __GNUC__ >= 3
@@ -379,26 +379,23 @@ int main(int argc, char **argv)
379379
}
380380
cerr<<num_domainsdone<<" domains were fully parsed, containing "<<g_numRecords<<" records\n";
381381

382-
}
383-
catch(AhuException &ae) {
384-
cerr<<"\nFatal error: "<<ae.reason<<endl;
385-
return 0;
386-
}
387-
catch(std::exception &e) {
388-
cerr<<"died because of STL error: "<<e.what()<<endl;
389-
exit(0);
390-
}
391-
catch(...) {
392-
cerr<<"died because of unknown exception"<<endl;
393-
exit(0);
394-
}
395-
396382
if(::arg().mustDo("transactions") && g_intransaction) {
397383
if(g_mode != SQLITE)
398384
cout<<"COMMIT WORK;"<<endl;
399385
else
400386
cout<<"COMMIT;"<<endl;
401387
}
388+
return 0;
389+
}
390+
catch(AhuException &ae) {
391+
cerr<<"\nFatal error: "<<ae.reason<<endl;
392+
return 1;
393+
}
394+
catch(std::exception &e) {
395+
cerr<<"\ndied because of STL error: "<<e.what()<<endl;
396+
return 1;
397+
}
398+
catch(...) {
399+
cerr<<"\ndied because of unknown exception"<<endl;
402400
return 1;
403-
404401
}

0 commit comments

Comments
 (0)