summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Szulecki <m.szulecki@libimobiledevice.org>2014-11-30 17:48:57 +0100
committerMartin Szulecki <m.szulecki@libimobiledevice.org>2014-11-30 17:48:57 +0100
commit562e4d8834317abd671e1598424264a8416219ff (patch)
tree52ba85d7c358e8c25f36ba9ad5346a51693b17d7
parent4bd7cd0d28e7f5920de51470b863f3aeee00409d (diff)
downloadusbmuxd-processname.tar.gz
Log process name of client if possible on Linuxprocessname
-rw-r--r--src/client.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/client.c b/src/client.c
index 4ec4025..f44317d 100644
--- a/src/client.c
+++ b/src/client.c
@@ -24,6 +24,7 @@
#define _GNU_SOURCE 1
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -142,6 +143,27 @@ int client_set_events(struct mux_client *client, short events)
return 0;
}
+#ifdef SO_PEERCRED
+static const char* client_get_process_name_by_pid(const int pid)
+{
+ char* name = (char*)calloc(1024, sizeof(char));
+ if(name) {
+ sprintf(name, "/proc/%d/cmdline", pid);
+ FILE* f = fopen(name, "r");
+ if(f) {
+ size_t size;
+ size = fread(name, sizeof(char), 1024, f);
+ if(size > 0) {
+ if('\n' == name[size-1])
+ name[size-1]='\0';
+ }
+ fclose(f);
+ }
+ }
+ return name;
+}
+#endif
+
/**
* Wait for an inbound connection on the usbmuxd socket
* and create a new mux_client instance for it, and store
@@ -196,9 +218,10 @@ int client_accept(int listenfd)
getsockopt(cfd, SOL_SOCKET, SO_PEERCRED, &cr, &len);
if (getpid() == cr.pid) {
- usbmuxd_log(LL_INFO, "New client on fd %d (self)", client->fd);
+ usbmuxd_log(LL_INFO, "New client on fd %d: %s (pid %d)", client->fd, PACKAGE_NAME, cr.pid);
} else {
- usbmuxd_log(LL_INFO, "New client on fd %d (pid %d)", client->fd, cr.pid);
+ const char* process_name = client_get_process_name_by_pid(cr.pid);
+ usbmuxd_log(LL_INFO, "New client on fd %d: %s (pid %d)", client->fd, process_name, cr.pid);
}
}
#else