Skip to content

Commit

Permalink
[evdev_trace] Identify processes that have input devices open. Fixes …
Browse files Browse the repository at this point in the history
…JB#33642

It is cumbersome to check what processes have evdev input device open.

Make evdev_trace also identify processes that have the input devices open
when option -I / --show-readers is used.
  • Loading branch information
spiiroin committed Dec 9, 2015
1 parent ad535db commit 6fe01fd
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .depend
Expand Up @@ -1190,11 +1190,23 @@ tools/evdev_trace.o:\
tools/evdev_trace.c\
evdev.h\
mce-log.h\
tools/fileusers.h\

tools/evdev_trace.pic.o:\
tools/evdev_trace.c\
evdev.h\
mce-log.h\
tools/fileusers.h\

tools/fileusers.o:\
tools/fileusers.c\
mce-log.h\
tools/fileusers.h\

tools/fileusers.pic.o:\
tools/fileusers.c\
mce-log.h\
tools/fileusers.h\

tools/mcetool.o:\
tools/mcetool.c\
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -361,7 +361,7 @@ $(TOOLDIR)/mcetool : $(TOOLDIR)/mcetool.o mce-command-line.o

$(TOOLDIR)/evdev_trace : CFLAGS += $(TOOLS_CFLAGS)
$(TOOLDIR)/evdev_trace : LDLIBS += $(TOOLS_LDLIBS)
$(TOOLDIR)/evdev_trace : $(TOOLDIR)/evdev_trace.o evdev.o
$(TOOLDIR)/evdev_trace : $(TOOLDIR)/evdev_trace.o evdev.o $(TOOLDIR)/fileusers.o

# ----------------------------------------------------------------------------
# UNIT TESTS
Expand Down Expand Up @@ -584,6 +584,8 @@ NORMALIZE_USES_SPC =\
tklock.h\
tools/evdev_trace.c\
tools/mcetool.c\
tools/fileusers.c\
tools/fileusers.h\

NORMALIZE_USES_TAB =\
datapipe.c\
Expand Down
27 changes: 27 additions & 0 deletions tools/evdev_trace.c
Expand Up @@ -6,6 +6,7 @@

#include "../mce-log.h"
#include "../evdev.h"
#include "fileusers.h"

#include <linux/input.h>

Expand Down Expand Up @@ -128,7 +129,20 @@ mainloop(char **path, int count, int identify, int trace)
if( identify )
{
printf("----====( %s )====----\n", path[i]);

evdev_identify_device(pfd[i].fd);

GSList *list = fileusers_get(path[i]);
if( list ) {
printf("Readers:\n");
for( GSList *item = list; item; item = item->next )
{
fileuser_t *fu = item->data;
printf("\t%s(pid=%d,fd=%d)\n", fu->cmd, fu->pid, fu->fd);
}
g_slist_free(list);
}

printf("\n");
}
}
Expand Down Expand Up @@ -175,6 +189,7 @@ static struct option optL[] =
{ "help", 0, 0, 'h' },
{ "trace", 0, 0, 't' },
{ "identify", 0, 0, 'i' },
{ "show-readers", 0, 0, 'I' },
{ "emit-also-tod", 0, 0, 'e' },
{ "emit-only-tod", 0, 0, 'E' },
{ 0,0,0,0 }
Expand All @@ -185,6 +200,7 @@ static const char optS[] =
"h" // --help
"t" // --trace
"i" // --identify
"I" // --show-readers
"e" // --emit-also-tod
"E" // --emit-only-tod
;
Expand Down Expand Up @@ -309,6 +325,7 @@ main(int argc, char **argv)

int f_trace = 0;
int f_identify = 0;
int f_readers = 0;

setlinebuf(stdout);

Expand Down Expand Up @@ -341,6 +358,10 @@ main(int argc, char **argv)
f_identify = 1;
break;

case 'I':
f_identify = f_readers = 1;
break;

case 'e':
emit_time_of_day = true;
break;
Expand All @@ -365,6 +386,11 @@ main(int argc, char **argv)
f_identify = 1;
}

if( f_readers )
{
fileusers_init();
}

if( optind < argc )
{
argc = 0;
Expand Down Expand Up @@ -397,6 +423,7 @@ main(int argc, char **argv)
cleanup:

globfree(&gb);
fileusers_quit();

return result;
}

0 comments on commit 6fe01fd

Please sign in to comment.