Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
fishdescriptor-donate.so: donate.o
fishdescriptor-donate.so: donate.o
- $(CC) -shared -soname $(LIBCANON) -o $@ $< $(LIBS)
+ $(CC) -shared -Wl,-soname $(LIBCANON) -o $@ $< $(LIBS)
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* return conventions: functions here return 0 on success,
- * or -1 setting errno */
+#include <stdlib.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
static int fishdescriptor_sendmsg_fds(int carrier,
int nfds, const int fds[]) {
static int fishdescriptor_sendmsg_fds(int carrier,
int nfds, const int fds[]) {
+ /* return convention: like a syscall */
struct msghdr msg = { 0 };
struct cmsghdr *cmsg;
size_t spaceneeded = nfds * sizeof(fds[0]);
struct msghdr msg = { 0 };
struct cmsghdr *cmsg;
size_t spaceneeded = nfds * sizeof(fds[0]);
-static int fishdescriptor_donate(const char *path, const int *fds) {
+int fishdescriptor_donate(const char *path, const int *fds) {
+ /* return convention: returns errno value */
+ /* within function: r is like syscall return, errno value is in errno */
int carrier=-1;
carrier = socket(AF_UNIX, SOCK_STREAM, 0);
if (carrier < 0) goto out;
struct sockaddr_un suna;
int carrier=-1;
carrier = socket(AF_UNIX, SOCK_STREAM, 0);
if (carrier < 0) goto out;
struct sockaddr_un suna;
+ memset(&suna,0,sizeof(suna));
suna.sun_family = AF_UNIX;
suna.sun_family = AF_UNIX;
- if (strlen(path) >= sizeof(suna.sun_path)) { outno = E2BIG; goto out; }
+ if (strlen(path) >= sizeof(suna.sun_path)) { errno = E2BIG; goto out; }
strcpy(suna.sun_path, path);
strcpy(suna.sun_path, path);
- int r = connect(carrier, &suna, sizeof(suna));
+ r = connect(carrier, (const struct sockaddr*)&suna, sizeof(suna));
if (r) goto out;
int nfds;
if (r) goto out;
int nfds;
r = 0;
out:
if (carrier >= 0) close(carrier);
r = 0;
out:
if (carrier >= 0) close(carrier);
+ r = !r ? 0 : !errno ? EIO : errno;
+ esave = errno;