Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/exec/kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <errno.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>

#include "../../mem/shm_mem.h"
#include "../../dprint.h"
Expand Down
17 changes: 15 additions & 2 deletions pass_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ int send_all(int socket, void* data, int data_len)
return n;
}

/* gcc does the right thing */
static inline int get_unaligned_int(const void *p)
{
const struct { int d; } __attribute__((packed)) *pp = p;
return pp->d;
}

/* gcc does the right thing */
static inline void put_unaligned_int(void *p, int value)
{
struct { int d; } __attribute__((packed, may_alias)) *pp = p;
pp->d = value;
}

/* at least 1 byte must be sent! */
int send_fd(int unix_socket, void* data, int data_len, int fd)
Expand All @@ -129,7 +142,7 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
*(int*)CMSG_DATA(cmsg)=fd;
put_unaligned_int(CMSG_DATA(cmsg), fd);
msg.msg_flags=0;
#else
msg.msg_accrights=(caddr_t) &fd;
Expand Down Expand Up @@ -237,7 +250,7 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
ret=-1;
goto error;
}
*fd=*((int*) CMSG_DATA(cmsg));
*fd = get_unaligned_int(CMSG_DATA(cmsg));
}else{
/*
LM_ERR("no descriptor passed, cmsg=%p,len=%d\n",
Expand Down