6cc540922a77b78ebd29c505255bfa54ad65996b
2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sys/types.h>
33 #include <lttng/liblttngctl.h>
39 static char *progname
;
42 static int process_client_opt(void);
43 static int process_opt_list_apps(void);
48 * Process client request from the command line
49 * options. Every tracing action is done by the
52 static int process_client_opt(void)
56 /* Connect to the session daemon */
57 ret
= lttng_connect_sessiond();
59 ERR("%s", lttng_get_readable_code(ret
));
64 ret
= process_opt_list_apps();
66 ERR("%s", lttng_get_readable_code(ret
));
78 * process_opt_list_apps
80 * Get the UST traceable pid list and print
83 static int process_opt_list_apps(void)
88 char path
[24]; /* Can't go bigger than /proc/65535/cmdline */
89 char cmdline
[PATH_MAX
];
91 ret
= lttng_ust_list_apps(&pids
);
96 MSG("LTTng UST traceable application [name (pid)]:");
97 for (i
=0; i
< ret
; i
++) {
98 snprintf(path
, sizeof(path
), "/proc/%d/cmdline", pids
[i
]);
99 fp
= fopen(path
, "r");
103 ret
= fread(cmdline
, 1, sizeof(cmdline
), fp
);
104 MSG("\t%s (%d)", cmdline
, pids
[i
]);
108 /* Allocated by lttng_ust_list_apps() */
120 * Check if the session daemon is available using
121 * the liblttngctl API for the check.
123 static int check_ltt_sessiond(void)
127 ret
= lttng_check_session_daemon();
129 ERR("No session daemon found. Aborting.");
139 void clean_exit(int code
)
148 int main(int argc
, char *argv
[])
152 progname
= argv
[0] ? argv
[0] : "lttng";
154 /* For Mathieu Desnoyers aka Dr Tracing */
155 if (strncmp(progname
, "drtrace", 7) == 0) {
156 MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n\n", 27,1,33,27,0);
159 ret
= parse_args(argc
, (const char **) argv
);
164 if (opt_tracing_group
!= NULL
) {
165 DBG("Set tracing group to '%s'", opt_tracing_group
);
166 lttng_set_tracing_group(opt_tracing_group
);
169 /* If ask for kernel tracing, need root perms */
170 if (opt_trace_kernel
) {
171 DBG("Kernel tracing activated");
173 ERR("%s must be setuid root", progname
);
178 /* Check if the lttng session daemon is running.
179 * If no, a daemon will be spawned.
181 if (check_ltt_sessiond() < 0) {
185 ret
= process_client_opt();
This page took 0.032173 seconds and 4 git commands to generate.