From: david.goulet@polymtl.ca (David Goulet)
Subject: [ltt-dev] [UST PATCH] Set the exit status of ustctl main function v2
Date: Thu, 9 Sep 2010 10:11:34 -0400 [thread overview]
Message-ID: <1284041494-1237-1-git-send-email-david.goulet@polymtl.ca> (raw)
Each possible command checks the return value and, on error,
print on stderr and set the retval. This makes ustctl return
an EXIT_FAILURE on any command that fails.
Signed-off-by: David Goulet <david.goulet at polymtl.ca>
---
ustctl/ustctl.c | 58 ++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c
index d290975..8832844 100644
--- a/ustctl/ustctl.c
+++ b/ustctl/ustctl.c
@@ -170,6 +170,7 @@ int main(int argc, char *argv[])
{
pid_t *pidit;
int result;
+ int retval = EXIT_SUCCESS;
char *tmp;
struct ust_opts opts;
@@ -216,12 +217,13 @@ int main(int argc, char *argv[])
pidit = opts.pids;
struct marker_status *cmsf = NULL;
- while(*pidit != -1) {
+ while (*pidit != -1) {
switch (opts.cmd) {
case CREATE_TRACE:
result = ustcmd_create_trace(*pidit);
if (result) {
ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
break;
@@ -230,6 +232,7 @@ int main(int argc, char *argv[])
result = ustcmd_start_trace(*pidit);
if (result) {
ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
break;
@@ -238,6 +241,7 @@ int main(int argc, char *argv[])
result = ustcmd_stop_trace(*pidit);
if (result) {
ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
break;
@@ -246,6 +250,7 @@ int main(int argc, char *argv[])
result = ustcmd_destroy_trace(*pidit);
if (result) {
ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
break;
@@ -253,9 +258,8 @@ int main(int argc, char *argv[])
case LIST_MARKERS:
cmsf = NULL;
if (ustcmd_get_cmsf(&cmsf, *pidit)) {
- fprintf(stderr,
- "error while trying to list markers for"
- " PID %u\n", (unsigned int) *pidit);
+ ERR("error while trying to list markers for PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
unsigned int i = 0;
@@ -273,26 +277,49 @@ int main(int argc, char *argv[])
break;
case ENABLE_MARKER:
- if(opts.regex)
- ustcmd_set_marker_state(opts.regex, 1, *pidit);
+ if (opts.regex) {
+ if (ustcmd_set_marker_state(opts.regex, 1, *pidit)) {
+ ERR("error while trying to enable marker %s with PID %u\n",
+ opts.regex, (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
+ }
+ }
break;
case DISABLE_MARKER:
- if(opts.regex)
- ustcmd_set_marker_state(opts.regex, 0, *pidit);
+ if (opts.regex) {
+ if (ustcmd_set_marker_state(opts.regex, 0, *pidit)) {
+ ERR("error while trying to disable marker %s with PID %u\n",
+ opts.regex, (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
+ }
+ }
break;
case SET_SUBBUF_SIZE:
- ustcmd_set_subbuf_size(opts.regex, *pidit);
+ if (opts.regex) {
+ if (ustcmd_set_subbuf_size(opts.regex, *pidit)) {
+ ERR("error while trying to set the size of subbuffers with PID %u\n",
+ (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
+ }
+ }
break;
case SET_SUBBUF_NUM:
- ustcmd_set_subbuf_num(opts.regex, *pidit);
+ if (opts.regex) {
+ if (ustcmd_set_subbuf_num(opts.regex, *pidit)) {
+ ERR("error while trying to set the number of subbuffers with PID %u\n",
+ (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
+ }
+ }
break;
case GET_SUBBUF_SIZE:
result = ustcmd_get_subbuf_size(opts.regex, *pidit);
if (result == -1) {
ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
@@ -303,6 +330,7 @@ int main(int argc, char *argv[])
result = ustcmd_get_subbuf_num(opts.regex, *pidit);
if (result == -1) {
ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
@@ -313,7 +341,7 @@ int main(int argc, char *argv[])
result = ustcmd_alloc_trace(*pidit);
if (result) {
ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit);
- break;
+ retval = EXIT_FAILURE;
}
break;
@@ -321,6 +349,7 @@ int main(int argc, char *argv[])
result = ustcmd_get_sock_path(&tmp, *pidit);
if (result) {
ERR("error while trying to get sock path for PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
break;
}
printf("the socket path is %s\n", tmp);
@@ -331,6 +360,7 @@ int main(int argc, char *argv[])
result = ustcmd_set_sock_path(opts.regex, *pidit);
if (result) {
ERR("error while trying to set sock path for PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
}
break;
@@ -338,12 +368,14 @@ int main(int argc, char *argv[])
result = ustcmd_force_switch(*pidit);
if (result) {
ERR("error while trying to force switch for PID %u\n", (unsigned int) *pidit);
+ retval = EXIT_FAILURE;
}
break;
default:
ERR("unknown command\n");
- break;
+ retval = EXIT_FAILURE;
+ break;
}
pidit++;
@@ -356,6 +388,6 @@ int main(int argc, char *argv[])
free(opts.regex);
}
- return 0;
+ return retval;
}
--
1.7.2.3
next reply other threads:[~2010-09-09 14:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-09 14:11 David Goulet [this message]
2010-09-09 16:44 ` Mathieu Desnoyers
2010-09-09 16:45 ` David Goulet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1284041494-1237-1-git-send-email-david.goulet@polymtl.ca \
--to=david.goulet@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox