#include "espp_service_priv.h"
#include <gio/gio.h>
+#define __USE_GNU /* define for ucred in socket.h */
#include <sys/socket.h>
#include <sys/un.h>
#include <pthread.h>
typedef struct {
espp_service_s *svc;
int fd;
+ unsigned int pid;
} work_thread_userdata_s;
static int __event_ret_msg_handling(int fd, espp_service_s *svc)
pthread_exit(NULL);
}
+static unsigned int get_pid_from_fd(int fd)
+{
+ struct ucred cred;
+ socklen_t len = (socklen_t)sizeof(struct ucred);
+ char str_error[MAX_ERROR_LEN] = {'\0',};
+
+ if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0) {
+ strerror_r(errno, str_error, sizeof(str_error));
+ LOG_ERROR("failed to getsockopt(), err: %s", str_error);
+ return 0;
+ }
+
+ LOG_INFO("fd[%d] pid[%u]", fd, cred.pid);
+
+ return cred.pid;
+}
+
static void *__listen_thread_func(void *data)
{
espp_service_s *svc = (espp_service_s *)data;
userdata = g_new0(work_thread_userdata_s, 1);
userdata->svc = svc;
userdata->fd = client_fd;
+ userdata->pid = get_pid_from_fd(client_fd);
if (pthread_create(&work_thread_id, &attr, (void *)__work_thread_func, (void *)userdata)) {
LOG_ERROR("failed to pthread_create(), client_fd[%d]", client_fd);