projects
/
lttng-ust.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rename registers.h -> processor.h
[lttng-ust.git]
/
libustcmd
/
ustcmd.c
diff --git
a/libustcmd/ustcmd.c
b/libustcmd/ustcmd.c
index 55ac02a6193996afd109269bc077d6792feffe28..49b76f541af9f5c8bd883093d117f4c7e8b4d09d 100644
(file)
--- a/
libustcmd/ustcmd.c
+++ b/
libustcmd/ustcmd.c
@@
-15,6
+15,7
@@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
@@
-22,27
+23,24
@@
#include <fcntl.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <string.h>
#include <dirent.h>
-#
#include "ustcomm.h"
#include "ustcmd.h"
#include "ustcomm.h"
#include "ustcmd.h"
-#define _GNU_SOURCE
-
-pid_t* ustcmd_get_online_pids(void) {
- struct dirent* dirent;
- DIR* dir;
- char* ping_res;
+pid_t *ustcmd_get_online_pids(void)
+{
+ struct dirent *dirent;
+ DIR *dir;
+ unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
dir = opendir(SOCK_DIR);
if (!dir) {
return NULL;
}
dir = opendir(SOCK_DIR);
if (!dir) {
return NULL;
}
- unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
- pid_t* ret = (pid_t*) malloc(ret_size);
+ pid_t *ret = (pid_t *) malloc(ret_size);
- while (
dirent = readdir(dir
)) {
+ while (
(dirent = readdir(dir)
)) {
if (!strcmp(dirent->d_name, ".") ||
!strcmp(dirent->d_name, "..")) {
if (!strcmp(dirent->d_name, ".") ||
!strcmp(dirent->d_name, "..")) {
@@
-52,10
+50,10
@@
pid_t* ustcmd_get_online_pids(void) {
if (dirent->d_type != DT_DIR &&
!!strcmp(dirent->d_name, "ustd")) {
if (dirent->d_type != DT_DIR &&
!!strcmp(dirent->d_name, "ustd")) {
- sscanf(dirent->d_name, "%u", (unsigned int*) &ret[i]);
+ sscanf(dirent->d_name, "%u", (unsigned int
*) &ret[i]);
if (pid_is_online(ret[i])) {
ret_size += sizeof(pid_t);
if (pid_is_online(ret[i])) {
ret_size += sizeof(pid_t);
- ret = (pid_t*) realloc(ret, ret_size);
+ ret = (pid_t
*) realloc(ret, ret_size);
++i;
}
}
++i;
}
}
@@
-63,7
+61,8
@@
pid_t* ustcmd_get_online_pids(void) {
ret[i] = 0; /* Array end */
ret[i] = 0; /* Array end */
- if (ret[0] == 0) { /* No PID at all.. */
+ if (ret[0] == 0) {
+ /* No PID at all */
free(ret);
return NULL;
}
free(ret);
return NULL;
}
@@
-80,17
+79,20
@@
pid_t* ustcmd_get_online_pids(void) {
* @param pid Traced process ID
* @return 0 if successful, or errors {USTCMD_ERR_GEN, USTCMD_ERR_ARG}
*/
* @param pid Traced process ID
* @return 0 if successful, or errors {USTCMD_ERR_GEN, USTCMD_ERR_ARG}
*/
-int ustcmd_set_marker_state(const char* mn, int state, pid_t pid) {
+int ustcmd_set_marker_state(const char *mn, int state, pid_t pid)
+{
+ char *cmd_str [] = {"disable_marker", "enable_marker"};
+ char *cmd;
+ int result;
+
if (mn == NULL) {
return USTCMD_ERR_ARG;
}
if (mn == NULL) {
return USTCMD_ERR_ARG;
}
- char* cmd_str [] = {"disable_marker", "enable_marker"};
- char* cmd;
asprintf(&cmd, "%s %s", cmd_str[state], mn);
asprintf(&cmd, "%s %s", cmd_str[state], mn);
-
int tres
;
- if (
tres = ustcmd_shoot(cmd, pid, NULL)
) {
+
result = ustcmd_send_cmd(cmd, pid, NULL)
;
+ if (
result
) {
free(cmd);
return USTCMD_ERR_GEN;
}
free(cmd);
return USTCMD_ERR_GEN;
}
@@
-105,10
+107,12
@@
int ustcmd_set_marker_state(const char* mn, int state, pid_t pid) {
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
-int ustcmd_destroy_trace(pid_t pid) {
- int tres;
+int ustcmd_destroy_trace(pid_t pid)
+{
+ int result;
- if (tres = ustcmd_shoot("destroy", pid, NULL)) {
+ result = ustcmd_send_cmd("destroy", pid, NULL);
+ if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
@@
-121,10
+125,12
@@
int ustcmd_destroy_trace(pid_t pid) {
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
-int ustcmd_setup_and_start(pid_t pid) {
- int tres;
+int ustcmd_setup_and_start(pid_t pid)
+{
+ int result;
- if (tres = ustcmd_shoot("start", pid, NULL)) {
+ result = ustcmd_send_cmd("start", pid, NULL);
+ if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
@@
-137,10
+143,12
@@
int ustcmd_setup_and_start(pid_t pid) {
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
-int ustcmd_start_trace(pid_t pid) {
- int tres;
+int ustcmd_start_trace(pid_t pid)
+{
+ int result;
- if (tres = ustcmd_shoot("trace_start", pid, NULL)) {
+ result = ustcmd_send_cmd("trace_start", pid, NULL);
+ if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
@@
-153,10
+161,12
@@
int ustcmd_start_trace(pid_t pid) {
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
* @param pid Traced process ID
* @return 0 if successful, or error USTCMD_ERR_GEN
*/
-int ustcmd_stop_trace(pid_t pid) {
- int tres;
+int ustcmd_stop_trace(pid_t pid)
+{
+ int result;
- if (tres = ustcmd_shoot("trace_stop", pid, NULL)) {
+ result = ustcmd_send_cmd("trace_stop", pid, NULL);
+ if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
@@
-169,7
+179,8
@@
int ustcmd_stop_trace(pid_t pid) {
* @param str String to search in
* @return Total newlines count
*/
* @param str String to search in
* @return Total newlines count
*/
-unsigned int ustcmd_count_nl(const char* str) {
+unsigned int ustcmd_count_nl(const char *str)
+{
unsigned int i = 0, tot = 0;
while (str[i] != '\0') {
unsigned int i = 0, tot = 0;
while (str[i] != '\0') {
@@
-188,7
+199,8
@@
unsigned int ustcmd_count_nl(const char* str) {
* @param cmsf CMSF array to free
* @return 0 if successful, or error USTCMD_ERR_ARG
*/
* @param cmsf CMSF array to free
* @return 0 if successful, or error USTCMD_ERR_ARG
*/
-int ustcmd_free_cmsf(struct USTcmd_cmsf* cmsf) {
+int ustcmd_free_cmsf(struct marker_status *cmsf)
+{
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
}
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
}
@@
-213,14
+225,18
@@
int ustcmd_free_cmsf(struct USTcmd_cmsf* cmsf) {
* @param pid Targeted PID
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_GEN}
*/
* @param pid Targeted PID
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_GEN}
*/
-int ustcmd_get_cmsf(struct USTcmd_cmsf** cmsf, const pid_t pid) {
+int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid)
+{
+ char *big_str = NULL;
+ int result;
+ struct marker_status *tmp_cmsf = NULL;
+ unsigned int i = 0, cmsf_ind = 0;
+
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
}
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
}
- char* big_str = NULL;
- int tres;
-
- if (tres = ustcmd_shoot("list_markers", pid, &big_str)) {
+ result = ustcmd_send_cmd("list_markers", pid, &big_str);
+ if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
@@
-229,18
+245,17
@@
int ustcmd_get_cmsf(struct USTcmd_cmsf** cmsf, const pid_t pid) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
- struct USTcmd_cmsf* tmp_cmsf = NULL;
- tmp_cmsf = (struct USTcmd_cmsf*) malloc(sizeof(struct USTcmd_cmsf) *
+ tmp_cmsf = (struct marker_status *) malloc(sizeof(struct marker_status) *
(ustcmd_count_nl(big_str) + 1));
if (tmp_cmsf == NULL) {
return USTCMD_ERR_GEN;
}
/* Parse received reply string (format: "[chan]/[mark] [st] [fs]"): */
(ustcmd_count_nl(big_str) + 1));
if (tmp_cmsf == NULL) {
return USTCMD_ERR_GEN;
}
/* Parse received reply string (format: "[chan]/[mark] [st] [fs]"): */
- unsigned int i = 0, cur_st, cmsf_ind = 0;
while (big_str[i] != '\0') {
char state;
while (big_str[i] != '\0') {
char state;
- sscanf(big_str + i, "%a[^/]/%a[^ ] %c %a[^\n]",
+
+ sscanf(big_str + i, "marker: %a[^/]/%a[^ ] %c %a[^\n]",
&tmp_cmsf[cmsf_ind].channel,
&tmp_cmsf[cmsf_ind].marker,
&state,
&tmp_cmsf[cmsf_ind].channel,
&tmp_cmsf[cmsf_ind].marker,
&state,
@@
-273,14
+288,17
@@
int ustcmd_get_cmsf(struct USTcmd_cmsf** cmsf, const pid_t pid) {
* be NULL if no reply is needed for the given command).
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_CONN}
*/
* be NULL if no reply is needed for the given command).
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_CONN}
*/
-int ustcmd_shoot(const char* cmd, const pid_t pid, char** reply) {
+
+int ustcmd_send_cmd(const char *cmd, const pid_t pid, char **reply)
+{
+ struct ustcomm_connection conn;
+
if (cmd == NULL) {
return USTCMD_ERR_ARG;
}
if (cmd == NULL) {
return USTCMD_ERR_ARG;
}
- struct ustcomm_connection conn;
if (ustcomm_connect_app(pid, &conn)) {
if (ustcomm_connect_app(pid, &conn)) {
- fprintf(stderr, "ustcmd_s
hoot
: could not connect to PID %u\n",
+ fprintf(stderr, "ustcmd_s
end_cmd
: could not connect to PID %u\n",
(unsigned int) pid);
return USTCMD_ERR_CONN;
}
(unsigned int) pid);
return USTCMD_ERR_CONN;
}
This page took
0.046023 seconds
and
4
git commands to generate.