if (ret) {
//if (ptrace_ret) {
PERROR("kill");
- abort();
+ return -1;
}
for (;;) {
}
} else if (pid == 0) {
ERR("Unexpected PID 0");
- abort();
+ return -1;
} else {
if (WIFSTOPPED(status)) {
int shiftstatus, restartsig;
ptrace_ret = ptrace(PTRACE_GETEVENTMSG, pid, 0, &newpid);
if (ptrace_ret) {
PERROR("ptrace");
- abort();
+ return -1;
}
DBG("Child pid %d is forking, child pid %ld", pid, newpid);
for (i = 0; i < nr_handles; i++) {
ptrace_ret = ptrace(PTRACE_GETEVENTMSG, pid, 0, &newpid);
if (ptrace_ret) {
PERROR("ptrace");
- abort();
+ return -1;
}
DBG("Child pid %d issuing vfork, child pid %ld", pid, newpid);
for (i = 0; i < nr_handles; i++) {
ptrace_ret = ptrace(PTRACE_GETEVENTMSG, pid, 0, &newpid);
if (ptrace_ret) {
PERROR("ptrace");
- abort();
+ return -1;
}
DBG("Child pid %d issuing clone, child pid %ld", pid, newpid);
for (i = 0; i < nr_handles; i++) {
ptrace_ret = ptrace(PTRACE_GETEVENTMSG, pid, 0, &oldpid);
if (ptrace_ret) {
PERROR("ptrace");
- abort();
+ return -1;
}
DBG("Child pid (old: %ld, new: %d) is issuing exec",
oldpid, pid);
ret = kill(pid, SIGTTIN);
if (ret) {
PERROR("kill");
- abort();
+ return -1;
}
} else if (status >> 16 == PTRACE_EVENT_STOP) {
DBG("ptrace stop");
ptrace_ret = ptrace(PTRACE_CONT, pid, 0, 0);
if (ptrace_ret) {
PERROR("ptrace cont");
- abort();
+ return -1;
}
} else {
DBG("job control stop ret %ld errno %d", ptrace_ret, errno);
ptrace_ret = ptrace(PTRACE_CONT, pid, 0, 0);
if (ptrace_ret) {
PERROR("ptrace cont");
- abort();
+ return -1;
}
}
break;
ptrace_ret = ptrace(PTRACE_CONT, pid, 0, 0);
if (ptrace_ret) {
PERROR("ptrace");
- abort();
+ return -1;
}
break;
//}
ptrace_ret = ptrace(PTRACE_CONT, pid, 0, restartsig);
if (ptrace_ret) {
PERROR("ptrace");
- abort();
+ return -1;
}
}
} else if (WIFEXITED(status)) {
struct lttng_domain domain;
struct lttng_event *ev;
struct lttng_handle *handle;
- int ret;
+ int ret = 0;
if (opt_no_syscall)
return 0;
memset(&domain, 0, sizeof(domain));
ev = lttng_event_create();
- if (!ev)
- abort();
+ if (!ev) {
+ ERR("Error creating event");
+ goto end;
+ }
domain.type = LTTNG_DOMAIN_KERNEL;
domain.buf_type = LTTNG_BUFFER_GLOBAL;
handle = lttng_create_handle(ctx->session_name, &domain);
- if (!handle)
- abort();
+ if (!handle) {
+ ERR("Error creating handle");
+ ret = -1;
+ goto error_handle;
+ }
ev->type = LTTNG_EVENT_SYSCALL;
strcpy(ev->name, "*");
ev->loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
ret = lttng_enable_event_with_exclusions(handle,
ev, NULL, NULL, 0, NULL);
- if (ret)
- abort();
+ if (ret) {
+ ERR("Error enabling syscall events");
+ ret = -1;
+ }
lttng_destroy_handle(handle);
- return 0;
+error_handle:
+ lttng_event_destroy(ev);
+end:
+ return ret;
}
static
struct lttng_domain domain;
struct lttng_event_context event_ctx;
struct lttng_handle *handle;
+ const char *domain_str;
+ int ret = 0;
if (opt_no_context)
return 0;
switch (domain_type) {
case LTTNG_DOMAIN_KERNEL:
domain.buf_type = LTTNG_BUFFER_GLOBAL;
+ domain_str = "kernel";
break;
case LTTNG_DOMAIN_UST:
domain.buf_type = LTTNG_BUFFER_PER_UID;
+ domain_str = "ust";
break;
default:
return -1;
domain.type = domain_type;
handle = lttng_create_handle(ctx->session_name, &domain);
- if (!handle)
- abort();
-
+ if (!handle) {
+ ERR("Error creating handle");
+ ret = -1;
+ goto end;
+ }
memset(&event_ctx, 0, sizeof(event_ctx));
event_ctx.ctx = LTTNG_EVENT_CONTEXT_PROCNAME;
- if (lttng_add_context(handle, &event_ctx, NULL, NULL) < 0)
- abort();
-
+ if (lttng_add_context(handle, &event_ctx, NULL, NULL) < 0) {
+ ERR("Error adding `procname` context to domain `%s`", domain_str);
+ ret = -1;
+ goto error_context;
+ }
memset(&event_ctx, 0, sizeof(event_ctx));
event_ctx.ctx = LTTNG_EVENT_CONTEXT_VPID;
- if (lttng_add_context(handle, &event_ctx, NULL, NULL) < 0)
- abort();
-
+ if (lttng_add_context(handle, &event_ctx, NULL, NULL) < 0) {
+ ERR("Error adding `vpid` context to domain `%s`", domain_str);
+ ret = -1;
+ goto error_context;
+ }
memset(&event_ctx, 0, sizeof(event_ctx));
event_ctx.ctx = LTTNG_EVENT_CONTEXT_VTID;
- if (lttng_add_context(handle, &event_ctx, NULL, NULL) < 0)
- abort();
+ if (lttng_add_context(handle, &event_ctx, NULL, NULL) < 0) {
+ ERR("Error adding `vtid` context to domain `%s`", domain_str);
+ ret = -1;
+ goto error_context;
+ }
+error_context:
lttng_destroy_handle(handle);
- return 0;
+end:
+ return ret;
}
static
struct lttng_domain domain;
struct lttng_channel *channel;
struct lttng_handle *handle;
+ const char *domain_str;
+ int ret = 0;
memset(&domain, 0, sizeof(domain));
switch (domain_type) {
case LTTNG_DOMAIN_KERNEL:
domain.buf_type = LTTNG_BUFFER_GLOBAL;
+ domain_str = "kernel";
break;
case LTTNG_DOMAIN_UST:
domain.buf_type = LTTNG_BUFFER_PER_UID;
+ domain_str = "ust";
break;
default:
return -1;
}
domain.type = domain_type;
channel = lttng_channel_create(&domain);
+ if (!channel) {
+ ERR("Error creating channel for domain `%s`", domain_str);
+ ret = -1;
+ goto end;
+ }
channel->enabled = 1;
handle = lttng_create_handle(ctx->session_name, &domain);
- if (!handle)
- abort();
- if (lttng_enable_channel(handle, channel) < 0)
- abort();
+ if (!handle) {
+ ERR("Error creating handle");
+ ret = -1;
+ goto error_handle;
+ }
+ if (lttng_enable_channel(handle, channel) < 0) {
+ ERR("Error enabling channel for domain `%s`", domain_str);
+ ret = -1;
+ }
lttng_destroy_handle(handle);
-
+error_handle:
lttng_channel_destroy(channel);
- return 0;
+end:
+ return ret;
}
static
struct tm *timeinfo;
ctx->creation_time = time(NULL);
- if (ctx->creation_time == (time_t) -1)
- abort();
+ if (ctx->creation_time == (time_t) -1) {
+ PERROR("time");
+ return -1;
+ }
timeinfo = localtime(&ctx->creation_time);
- if (!timeinfo)
- abort();
+ if (!timeinfo) {
+ PERROR("localtime");
+ return -1;
+ }
strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
if (opt_session) {
if (strlen(session_name) > LTTNG_NAME_MAX - 1) {
- abort();
+ ERR("Session name is too long");
+ return -1;
}
strcpy(ctx->session_name, session_name);
} else {
if (opt_output) {
if (strlen(output_path) > PATH_MAX - 1) {
- abort();
+ ERR("output path is too long");
+ return -1;
}
strcpy(ctx->path, output_path);
} else {
ret = lttng_untrack_pid(handle[i], -1);
if (ret && ret != -LTTNG_ERR_INVALID) {
ERR("Error %d untracking pid %d", ret, -1);
- abort();
}
}
return 0;
return EXIT_SUCCESS;
}
- if (lttng_trace_ctx_init(&ptrace_ctx, argv[skip_args]))
- abort();
+ if (lttng_trace_ctx_init(&ptrace_ctx, argv[skip_args])) {
+ ERR("Error initializing trace context");
+ retval = -1;
+ goto end;
+ }
act.sa_sigaction = sighandler;
act.sa_flags = SA_SIGINFO | SA_RESTART;
sigemptyset(&act.sa_mask);
ret = sigaction(SIGTERM, &act, NULL);
- if (ret)
- abort();
+ if (ret) {
+ PERROR("sigaction");
+ retval = -1;
+ goto end;
+ }
ret = sigaction(SIGINT, &act, NULL);
- if (ret)
- abort();
-
+ if (ret) {
+ PERROR("sigaction");
+ retval = -1;
+ goto end;
+ }
if (create_session(&ptrace_ctx) < 0) {
fprintf(stderr, "%sError: Unable to create tracing session. Please ensure that lttng-sessiond is running as root and that your user belongs to the `tracing` group.\n", MESSAGE_PREFIX);
retval = -1;
end_ust_handle:
lttng_destroy_handle(handle[0]);
end_kernel_handle:
- if (destroy_session(&ptrace_ctx))
- abort();
+ if (destroy_session(&ptrace_ctx)) {
+ ERR("Error destroying session");
+ retval = -1;
+ }
end:
if (retval) {
return EXIT_FAILURE;