From 5e017fbb36d4ccafb9be6859d90f2c04b20b3d06 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 11 Nov 2014 13:49:03 +0100 Subject: client: Log pid of connecting clients (if supported) --- src/client.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/client.c b/src/client.c index 67a29e8..d5f31e4 100644 --- a/src/client.c +++ b/src/client.c @@ -22,6 +22,8 @@ #include #endif +#define _GNU_SOURCE 1 + #include #include #include @@ -166,7 +168,21 @@ int client_accept(int listenfd) collection_add(&client_list, client); pthread_mutex_unlock(&client_list_mutex); +#ifdef SO_PEERCRED + if (log_level >= LL_INFO) { + struct ucred cr; + len = sizeof(struct ucred); + getsockopt(cfd, SOL_SOCKET, SO_PEERCRED, &cr, &len); + + if (getpid() == cr.pid) { + usbmuxd_log(LL_INFO, "New client on fd %d (self)", client->fd); + } else { + usbmuxd_log(LL_INFO, "New client on fd %d (pid %d)", client->fd, cr.pid); + } + } +#else usbmuxd_log(LL_INFO, "New client on fd %d", client->fd); +#endif return client->fd; } -- cgit v1.1-32-gdbae