aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/disk.c39
-rw-r--r--src/util/disk.h1
-rw-r--r--src/util/network.c4
-rw-r--r--src/util/server.c2
4 files changed, 27 insertions, 19 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index a3d5db097..ee327e03f 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -75,10 +75,7 @@ typedef struct
75 int include_sym_links; 75 int include_sym_links;
76} GetFileSizeData; 76} GetFileSizeData;
77 77
78struct GNUNET_DISK_PipeHandle 78
79{
80 struct GNUNET_DISK_FileHandle fd[2];
81};
82 79
83static int 80static int
84getSizeRec (void *ptr, const char *fn) 81getSizeRec (void *ptr, const char *fn)
@@ -1500,6 +1497,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1500 1497
1501/** 1498/**
1502 * Creates an interprocess channel 1499 * Creates an interprocess channel
1500 *
1503 * @param blocking creates an asynchronous pipe if set to GNUNET_NO 1501 * @param blocking creates an asynchronous pipe if set to GNUNET_NO
1504 * @return handle to the new pipe, NULL on error 1502 * @return handle to the new pipe, NULL on error
1505 */ 1503 */
@@ -1516,12 +1514,15 @@ GNUNET_DISK_pipe (int blocking)
1516 int fd[2]; 1514 int fd[2];
1517 int ret; 1515 int ret;
1518 int flags; 1516 int flags;
1517 int eno;
1519 1518
1520 ret = pipe (fd); 1519 ret = pipe (fd);
1521 if (ret != -1) 1520 if (ret != -1)
1522 { 1521 {
1523 p->fd[0].fd = fd[0]; 1522 p->fd[0] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
1524 p->fd[1].fd = fd[1]; 1523 p->fd[1] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
1524 p->fd[0]->fd = fd[0];
1525 p->fd[1]->fd = fd[1];
1525 1526
1526 if (!blocking) 1527 if (!blocking)
1527 { 1528 {
@@ -1536,10 +1537,14 @@ GNUNET_DISK_pipe (int blocking)
1536 } 1537 }
1537 if (ret == -1) 1538 if (ret == -1)
1538 { 1539 {
1540 eno = errno;
1539 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "fcntl"); 1541 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "fcntl");
1540 close (fd[0]); 1542 GNUNET_DISK_file_close (p->fd[0]);
1541 close (fd[1]); 1543 GNUNET_DISK_file_close (p->fd[1]);
1544 p->fd[0] = NULL;
1545 p->fd[1] = NULL;
1542 err = GNUNET_YES; 1546 err = GNUNET_YES;
1547 errno = eno;
1543 } 1548 }
1544 } 1549 }
1545 } 1550 }
@@ -1556,8 +1561,10 @@ GNUNET_DISK_pipe (int blocking)
1556 DWORD mode; 1561 DWORD mode;
1557 1562
1558 mode = PIPE_NOWAIT; 1563 mode = PIPE_NOWAIT;
1559 SetNamedPipeHandleState (p->fd[0].h, &mode, NULL, NULL); 1564 p->fd[0] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
1560 SetNamedPipeHandleState (p->fd[1].h, &mode, NULL, NULL); 1565 p->fd[1] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
1566 SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
1567 SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
1561 /* this always fails on Windows 95, so we don't care about error handling */ 1568 /* this always fails on Windows 95, so we don't care about error handling */
1562 } 1569 }
1563 } 1570 }
@@ -1586,13 +1593,13 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1586{ 1593{
1587 int ret = GNUNET_OK; 1594 int ret = GNUNET_OK;
1588#ifdef MINGW 1595#ifdef MINGW
1589 if (!CloseHandle (p->fd[0].h)) 1596 if (!CloseHandle (p->fd[0]->h))
1590 { 1597 {
1591 SetErrnoFromWinError (GetLastError ()); 1598 SetErrnoFromWinError (GetLastError ());
1592 ret = GNUNET_SYSERR; 1599 ret = GNUNET_SYSERR;
1593 } 1600 }
1594 1601
1595 if (!CloseHandle (p->fd[1].h)) 1602 if (!CloseHandle (p->fd[1]->h))
1596 { 1603 {
1597 SetErrnoFromWinError (GetLastError ()); 1604 SetErrnoFromWinError (GetLastError ());
1598 ret = GNUNET_SYSERR; 1605 ret = GNUNET_SYSERR;
@@ -1600,7 +1607,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1600#else 1607#else
1601 int save; 1608 int save;
1602 1609
1603 if (0 != close (p->fd[0].fd)) 1610 if (0 != close (p->fd[0]->fd))
1604 { 1611 {
1605 ret = GNUNET_SYSERR; 1612 ret = GNUNET_SYSERR;
1606 save = errno; 1613 save = errno;
@@ -1608,11 +1615,13 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1608 else 1615 else
1609 save = 0; 1616 save = 0;
1610 1617
1611 if (0 != close (p->fd[1].fd)) 1618 if (0 != close (p->fd[1]->fd))
1612 ret = GNUNET_SYSERR; 1619 ret = GNUNET_SYSERR;
1613 else 1620 else
1614 errno = save; 1621 errno = save;
1615#endif 1622#endif
1623 GNUNET_free (p->fd[0]);
1624 GNUNET_free (p->fd[1]);
1616 GNUNET_free (p); 1625 GNUNET_free (p);
1617 return ret; 1626 return ret;
1618} 1627}
@@ -1626,7 +1635,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1626const struct GNUNET_DISK_FileHandle * 1635const struct GNUNET_DISK_FileHandle *
1627GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, int n) 1636GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, int n)
1628{ 1637{
1629 return &p->fd[n]; 1638 return p->fd[n];
1630} 1639}
1631 1640
1632/** 1641/**
diff --git a/src/util/disk.h b/src/util/disk.h
index 9857a0fed..17ebe4a0a 100644
--- a/src/util/disk.h
+++ b/src/util/disk.h
@@ -41,6 +41,7 @@ struct GNUNET_DISK_FileHandle
41 41
42/** 42/**
43 * Retrieve OS file handle 43 * Retrieve OS file handle
44 *
44 * @internal 45 * @internal
45 * @param fh GNUnet file descriptor 46 * @param fh GNUnet file descriptor
46 * @param dst destination buffer 47 * @param dst destination buffer
diff --git a/src/util/network.c b/src/util/network.c
index 2e1d40c80..2278ae34b 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -155,11 +155,11 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
155 SetErrnoFromWinsockError (WSAGetLastError ()); 155 SetErrnoFromWinsockError (WSAGetLastError ());
156#else 156#else
157 ret = close (desc->fd); 157 ret = close (desc->fd);
158#endif 158#endif
159 eno = errno; 159 eno = errno;
160 GNUNET_free (desc); 160 GNUNET_free (desc);
161 errno = eno; 161 errno = eno;
162 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 162 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
163} 163}
164 164
165/** 165/**
diff --git a/src/util/server.c b/src/util/server.c
index 303c370db..a2d5551a4 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -459,11 +459,9 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
459 return NULL; 459 return NULL;
460 } 460 }
461 ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle)); 461 ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
462 ret->shutpipe = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileDescriptor *[2]));
463 if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO))) 462 if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO)))
464 { 463 {
465 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsock)); 464 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsock));
466 GNUNET_free (ret->shutpipe);
467 GNUNET_free (ret); 465 GNUNET_free (ret);
468 return NULL; 466 return NULL;
469 } 467 }