lib/proxy: fix error code propagation
This commit is contained in:
parent
d9f26b70b0
commit
d04d98df91
10
eshi/proxy.c
10
eshi/proxy.c
|
@ -16,9 +16,15 @@ char fmt_buf[1024];
|
||||||
|
|
||||||
int evl_vprint_proxy(int proxyfd, const char *fmt, va_list ap)
|
int evl_vprint_proxy(int proxyfd, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
ssize_t len = vsnprintf(fmt_buf, sizeof(fmt_buf), fmt, ap);
|
ssize_t count, ret;
|
||||||
|
|
||||||
return write(proxyfd, fmt_buf, len);
|
count = vsnprintf(fmt_buf, sizeof(fmt_buf), fmt, ap);
|
||||||
|
if (count < 0)
|
||||||
|
return -errno; /* Assume POSIX beahvior. */
|
||||||
|
|
||||||
|
ret = write(proxyfd, fmt_buf, count);
|
||||||
|
|
||||||
|
return ret < 0 ? -errno : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int evl_print_proxy(int proxyfd, const char *fmt, ...)
|
int evl_print_proxy(int proxyfd, const char *fmt, ...)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <evl/uapi.h>
|
#include <evl/uapi.h>
|
||||||
|
@ -25,9 +26,10 @@ int evl_new_proxy(int fd, size_t bufsz, size_t granularity,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
ssize_t evl_send_proxy(int proxyfd, const void *buf, size_t len)
|
ssize_t evl_send_proxy(int proxyfd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
return write(proxyfd, buf, len);
|
ssize_t ret = write(proxyfd, buf, count);
|
||||||
|
return ret < 0 ? -errno : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int evl_vprint_proxy(int proxyfd,
|
int evl_vprint_proxy(int proxyfd,
|
||||||
|
@ -36,7 +38,11 @@ int evl_vprint_proxy(int proxyfd,
|
||||||
int evl_print_proxy(int proxyfd,
|
int evl_print_proxy(int proxyfd,
|
||||||
const char *fmt, ...);
|
const char *fmt, ...);
|
||||||
|
|
||||||
#define evl_printf(__fmt, __args...) printf(__fmt, ##__args)
|
#define evl_printf(__fmt, __args...) \
|
||||||
|
({ \
|
||||||
|
int __ret = printf(__fmt, ##__args); \
|
||||||
|
__ret < 0 ? -errno : __ret; \
|
||||||
|
})
|
||||||
|
|
||||||
#define proxy_outfd fileno(stdout)
|
#define proxy_outfd fileno(stdout)
|
||||||
#define proxy_errfd fileno(stderr)
|
#define proxy_errfd fileno(stderr)
|
||||||
|
|
|
@ -21,7 +21,7 @@ int evl_new_proxy(int targetfd, size_t bufsz,
|
||||||
const char *fmt, ...);
|
const char *fmt, ...);
|
||||||
|
|
||||||
ssize_t evl_send_proxy(int proxyfd,
|
ssize_t evl_send_proxy(int proxyfd,
|
||||||
const void *buf, size_t len);
|
const void *buf, size_t count);
|
||||||
|
|
||||||
int evl_vprint_proxy(int proxyfd,
|
int evl_vprint_proxy(int proxyfd,
|
||||||
const char *fmt, va_list ap);
|
const char *fmt, va_list ap);
|
||||||
|
|
25
lib/proxy.c
25
lib/proxy.c
|
@ -57,19 +57,26 @@ int evl_new_proxy(int targetfd, size_t bufsz, size_t granularity,
|
||||||
return efd;
|
return efd;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t evl_send_proxy(int proxyfd, const void *buf, size_t len)
|
ssize_t evl_send_proxy(int proxyfd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
if (evl_is_inband())
|
ssize_t ret;
|
||||||
return write(proxyfd, buf, len);
|
|
||||||
|
|
||||||
return oob_write(proxyfd, buf, len);
|
if (evl_is_inband())
|
||||||
|
ret = write(proxyfd, buf, count);
|
||||||
|
else
|
||||||
|
ret = oob_write(proxyfd, buf, count);
|
||||||
|
|
||||||
|
return ret < 0 ? -errno : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int evl_vprint_proxy(int proxyfd, const char *fmt, va_list ap)
|
int evl_vprint_proxy(int proxyfd, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
ssize_t len = vsnprintf(fmt_buf, sizeof(fmt_buf), fmt, ap);
|
ssize_t count = vsnprintf(fmt_buf, sizeof(fmt_buf), fmt, ap);
|
||||||
|
|
||||||
return evl_send_proxy(proxyfd, fmt_buf, len);
|
if (count < 0)
|
||||||
|
return -errno; /* assume POSIX behavior. */
|
||||||
|
|
||||||
|
return (int)evl_send_proxy(proxyfd, fmt_buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
int evl_print_proxy(int proxyfd, const char *fmt, ...)
|
int evl_print_proxy(int proxyfd, const char *fmt, ...)
|
||||||
|
@ -95,9 +102,11 @@ int evl_printf(const char *fmt, ...)
|
||||||
* If evl_init() has not run yet, we can resort to vprintf()
|
* If evl_init() has not run yet, we can resort to vprintf()
|
||||||
* since latency is not an issue.
|
* since latency is not an issue.
|
||||||
*/
|
*/
|
||||||
if (evl_ctlfd < 0)
|
if (evl_ctlfd < 0) {
|
||||||
ret = vprintf(fmt, ap);
|
ret = vprintf(fmt, ap);
|
||||||
else
|
if (ret < 0)
|
||||||
|
ret = -errno;
|
||||||
|
} else
|
||||||
ret = evl_vprint_proxy(proxy_outfd, fmt, ap);
|
ret = evl_vprint_proxy(proxy_outfd, fmt, ap);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
Loading…
Reference in New Issue