Re: [PATCH 3/5] trace-cmd: lookup syscall names in profile

From: Josef Bacik
Date: Wed May 20 2015 - 15:07:13 EST


On 05/20/2015 03:01 PM, Steven Rostedt wrote:
On Wed, 20 May 2015 14:56:17 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

On Wed, 20 May 2015 14:22:31 -0400
Josef Bacik <jbacik@xxxxxx> wrote:

I'll keep this as is, but I'm going to add code to check for this
library, and go back to the default raw numbers if it doesn't exist.


Maybe we should think about autoconf at some point? Thanks,

Egad no! I hate autoconf. And so do many others!

A simple test works fine. I don't want to require libaudit. Just warn
users that compile without it.

I like to install trace-cmd on minimal setups (like embedded devices).
autoconf will kill that.


Here's what I did to fix it:

-- Steve

diff --git a/Makefile b/Makefile
index 402f7114ab42..a8e63ad0c223 100644
--- a/Makefile
+++ b/Makefile
@@ -160,7 +160,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
python_dir_SQ = $(subst ','\'',$(python_dir))

-LIBS = -L. -ltracecmd -ldl -laudit
+LIBS = -L. -ltracecmd -ldl
LIB_FILE = libtracecmd.a

PACKAGES= gtk+-2.0 libxml-2.0 gthread-2.0
@@ -231,12 +231,25 @@ override CFLAGS += -D_GNU_SOURCE
ifndef NO_PTRACE
ifneq ($(call try-cc,$(SOURCE_PTRACE),),y)
NO_PTRACE = 1
- CFLAGS += -DWARN_NO_PTRACE
+ override CFLAGS += -DWARN_NO_PTRACE
endif
endif

ifdef NO_PTRACE
-CFLAGS += -DNO_PTRACE
+override CFLAGS += -DNO_PTRACE
+endif
+
+ifndef NO_AUDIT
+ifneq ($(call try-cc,$(SOURCE_AUDIT),-laudit),y)
+ NO_AUDIT = 1
+ override CFLAGS += -DWARN_NO_AUDIT
+endif
+endif
+
+ifdef NO_AUDIT
+override CFLAGS += -DNO_AUDIT
+else
+LIBS += -laudit
endif

# Append required CFLAGS
diff --git a/features.mk b/features.mk
index cb2e8bd897be..9c9d63c13a23 100644
--- a/features.mk
+++ b/features.mk
@@ -34,3 +34,21 @@ int main (void)
return ret;
}
endef
+
+define SOURCE_AUDIT
+#include <stdio.h>
+#include <libaudit.h>
+
+int main (void)
+{
+ char *name;
+ int ret;
+ ret = audit_detect_machine();
+ if (ret < 0)
+ return ret;
+ name = audit_syscall_to_name(1, ret);
+ if (!name)
+ return -1;
+ return ret;
+}
+endef
diff --git a/trace-profile.c b/trace-profile.c
index 24f989715f05..640dca822d46 100644
--- a/trace-profile.c
+++ b/trace-profile.c
@@ -23,11 +23,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifndef NO_AUDIT
#include <libaudit.h>
-
+#endif
#include "trace-local.h"
#include "trace-hash.h"

+#ifdef WARN_NO_AUDIT
+# warning "lib audit not found, using raw syscalls " \
+ "(install libaudit-devel and try again)"
+#endif
+
#define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWP"
#define TASK_STATE_MAX 1024

@@ -848,6 +854,7 @@ static void func_print(struct trace_seq *s, struct event_hash *event_hash)

static void syscall_print(struct trace_seq *s, struct event_hash *event_hash)
{
+#ifndef NO_AUDIT
const char *name = NULL;
int machine;

@@ -860,6 +867,7 @@ static void syscall_print(struct trace_seq *s, struct event_hash *event_hash)
trace_seq_printf(s, "syscall:%s", name);
return;
fail:
+#endif
trace_seq_printf(s, "%s:%d", event_hash->event_data->event->name,
(int)event_hash->val);
}


Looks good to me, thanks,

Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/