Simplify error handling in digwatch main

This commit is contained in:
Henri DF
2016-02-19 13:43:16 -08:00
parent 32ad5673c6
commit 208930fd55
2 changed files with 11 additions and 39 deletions

View File

@@ -123,9 +123,9 @@ captureinfo do_inspect(sinsp* inspector,
// //
// ARGUMENT PARSING AND PROGRAM SETUP // ARGUMENT PARSING AND PROGRAM SETUP
// //
digwatch_init_res digwatch_init(int argc, char **argv) int digwatch_init(int argc, char **argv)
{ {
digwatch_init_res res; int result;
sinsp* inspector = NULL; sinsp* inspector = NULL;
int op; int op;
uint64_t cnt = -1; uint64_t cnt = -1;
@@ -164,15 +164,13 @@ digwatch_init_res digwatch_init(int argc, char **argv)
{ {
case 'h': case 'h':
usage(); usage();
delete inspector; result = EXIT_SUCCESS;
return digwatch_init_res(EXIT_SUCCESS); goto exit;
case 'M': case 'M':
duration_to_tot = atoi(optarg); duration_to_tot = atoi(optarg);
if(duration_to_tot <= 0) if(duration_to_tot <= 0)
{ {
throw sinsp_exception(string("invalid duration") + optarg); throw sinsp_exception(string("invalid duration") + optarg);
res.m_res = EXIT_FAILURE;
goto exit;
} }
break; break;
case 'N': case 'N':
@@ -191,17 +189,14 @@ digwatch_init_res digwatch_init(int argc, char **argv)
if(cnt <= 0) if(cnt <= 0)
{ {
throw sinsp_exception(string("invalid event count ") + optarg); throw sinsp_exception(string("invalid event count ") + optarg);
res.m_res = EXIT_FAILURE;
goto exit;
} }
break; break;
case 'u': case 'u':
user_parser = optarg; user_parser = optarg;
break; break;
case '?': case '?':
delete inspector; result = EXIT_FAILURE;
return digwatch_init_res(EXIT_FAILURE); goto exit;
break;
default: default:
break; break;
} }
@@ -229,7 +224,7 @@ digwatch_init_res digwatch_init(int argc, char **argv)
#else #else
fprintf(stderr, "filtering not compiled.\n"); fprintf(stderr, "filtering not compiled.\n");
res.m_res = EXIT_FAILURE; result = EXIT_FAILURE;
goto exit; goto exit;
#endif #endif
} }
@@ -254,12 +249,12 @@ digwatch_init_res digwatch_init(int argc, char **argv)
catch(sinsp_exception& e) catch(sinsp_exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
res.m_res = EXIT_FAILURE; result = EXIT_FAILURE;
} }
catch(...) catch(...)
{ {
printf("Exeception\n"); printf("Exeception\n");
res.m_res = EXIT_FAILURE; result = EXIT_FAILURE;
} }
exit: exit:
@@ -269,7 +264,7 @@ exit:
delete inspector; delete inspector;
} }
return res; return result;
} }
// //
@@ -277,9 +272,5 @@ exit:
// //
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
digwatch_init_res res; return digwatch_init(argc, argv);
res = digwatch_init(argc, argv);
return res.m_res;
} }

View File

@@ -23,25 +23,6 @@ along with sysdig. If not, see <http://www.gnu.org/licenses/>.
#endif // HAS_CAPTURE #endif // HAS_CAPTURE
//
// Capture results
//
class digwatch_init_res
{
public:
digwatch_init_res()
{
m_res = EXIT_SUCCESS;
}
digwatch_init_res(int res)
{
m_res = res;
}
int m_res;
vector<string> m_next_run_args;
};
// //
// Capture results // Capture results