struct mcast_data *pri = data;
struct sockaddr_in *sin = pri->mcast_addr;
struct ip_mreq mreq;
- int fd = -EINVAL, yes = 1, err = -EINVAL;;
+ int fd, yes = 1, err = 0;
if ((sin->sin_addr.s_addr == 0) || (sin->sin_port == 0))
if (fd < 0){
printk("mcast_open : data socket failed, errno = %d\n",
errno);
- fd = -errno;
+ err = -errno;
goto out;
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
printk("mcast_open: SO_REUSEADDR failed, errno = %d\n",
errno);
+ err = -errno;
goto out_close;
}
sizeof(pri->ttl)) < 0) {
printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n",
errno);
+ err = -errno;
goto out_close;
}
if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n",
errno);
+ err = -errno;
goto out_close;
}
/* bind socket to mcast address */
if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) {
printk("mcast_open : data bind failed, errno = %d\n", errno);
+ err = -errno;
goto out_close;
}
"interface on the host.\n");
printk("eth0 should be configured in order to use the "
"multicast transport.\n");
+ err = -errno;
goto out_close;
}
- out:
return fd;
out_close:
os_close_file(fd);
+ out:
return err;
}
if(notify_sock < 0){
notify_sock = socket(PF_UNIX, SOCK_DGRAM, 0);
if(notify_sock < 0){
- printk("mconsole_notify - socket failed, errno = %d\n",
- errno);
err = -errno;
+ printk("mconsole_notify - socket failed, errno = %d\n",
+ err);
}
}
unlock_notify();
n = sendto(notify_sock, &packet, len, 0, (struct sockaddr *) &target,
sizeof(target));
if(n < 0){
- printk("mconsole_notify - sendto failed, errno = %d\n", errno);
err = -errno;
+ printk("mconsole_notify - sendto failed, errno = %d\n", errno);
}
return(err);
}
fd = get_pty();
if(fd < 0){
+ err = -errno;
printk("open_pts : Failed to open pts\n");
- return(-errno);
+ return err;
}
if(data->raw){
CATCH_EINTR(err = tcgetattr(fd, &data->tt));
fd = mkstemp(file);
if(fd < 0){
+ err = -errno;
printk("xterm_open : mkstemp failed, errno = %d\n", errno);
- return(-errno);
+ return err;
}
if(unlink(file)){
+ err = -errno;
printk("xterm_open : unlink failed, errno = %d\n", errno);
- return(-errno);
+ return err;
}
os_close_file(fd);
data.fd = fds[1];
pid = clone(helper_child, (void *) sp, CLONE_VM | SIGCHLD, &data);
if(pid < 0){
- printk("run_helper : clone failed, errno = %d\n", errno);
ret = -errno;
+ printk("run_helper : clone failed, errno = %d\n", errno);
goto out_close;
}
unsigned long *stack_out, int stack_order)
{
unsigned long stack, sp;
- int pid, status;
+ int pid, status, err;
stack = alloc_stack(stack_order, um_in_interrupt());
if(stack == 0) return(-ENOMEM);
sp = stack + (page_size() << stack_order) - sizeof(void *);
pid = clone(proc, (void *) sp, flags | SIGCHLD, arg);
if(pid < 0){
+ err = -errno;
printk("run_helper_thread : clone failed, errno = %d\n",
errno);
- return(-errno);
+ return err;
}
if(stack_out == NULL){
CATCH_EINTR(pid = waitpid(pid, &status, 0));
if(pid < 0){
+ err = -errno;
printk("run_helper_thread - wait failed, errno = %d\n",
errno);
- pid = -errno;
+ pid = err;
}
if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
printk("run_helper_thread - thread returned status "
CATCH_EINTR(ret = waitpid(pid, NULL, WNOHANG));
if(ret < 0){
+ ret = -errno;
printk("helper_wait : waitpid failed, errno = %d\n", errno);
- return(-errno);
}
return(ret);
}
int err;
CATCH_EINTR(err = tcgetattr(fd, &tt));
- if (err < 0) {
- printk("tcgetattr failed, errno = %d\n", errno);
- return(-errno);
- }
+ if(err < 0)
+ return -errno;
cfmakeraw(&tt);
CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt));
- if (err < 0) {
- printk("tcsetattr failed, errno = %d\n", errno);
- return(-errno);
- }
+ if(err < 0)
+ return -errno;
/* XXX tcsetattr could have applied only some changes
* (and cfmakeraw() is a set of changes) */
int err;
if(io_setup(256, &ctx)){
+ err = -errno;
printk("aio_thread failed to initialize context, err = %d\n",
errno);
- return -errno;
+ return err;
}
err = run_helper_thread(aio_thread, NULL,
CLONE_FILES | CLONE_VM | SIGCHLD, &stack, 0);
if(err < 0)
- return -errno;
+ return err;
aio_pid = err;
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov;
- int pid, n;
+ int pid, n, err;
sprintf(version_buf, "%d", UML_NET_VERSION);
n = recvmsg(me, &msg, 0);
*used_out = n;
if(n < 0){
+ err = -errno;
printk("tuntap_open_tramp : recvmsg failed - errno = %d\n",
errno);
- return(-errno);
+ return err;
}
CATCH_EINTR(waitpid(pid, NULL, 0));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){
+ err = -errno;
printk("TUNSETIFF failed, errno = %d\n", errno);
os_close_file(pri->fd);
- return(-errno);
+ return err;
}
}
else {
int os_new_tty_pgrp(int fd, int pid)
{
- if(ioctl(fd, TIOCSCTTY, 0) < 0){
- printk("TIOCSCTTY failed, errno = %d\n", errno);
- return(-errno);
- }
+ if(ioctl(fd, TIOCSCTTY, 0) < 0)
+ return -errno;
- if(tcsetpgrp(fd, pid) < 0){
- printk("tcsetpgrp failed, errno = %d\n", errno);
- return(-errno);
- }
+ if(tcsetpgrp(fd, pid) < 0)
+ return -errno;
return(0);
}
int disc, sencap;
disc = N_SLIP;
- if(ioctl(fd, TIOCSETD, &disc) < 0){
- printk("Failed to set slip line discipline - "
- "errno = %d\n", errno);
- return(-errno);
- }
+ if(ioctl(fd, TIOCSETD, &disc) < 0)
+ return -errno;
sencap = 0;
- if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0){
- printk("Failed to set slip encapsulation - "
- "errno = %d\n", errno);
- return(-errno);
- }
+ if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0)
+ return -errno;
return(0);
}
int flags;
flags = fcntl(master, F_GETFL);
- if(flags < 0) {
- printk("fcntl F_GETFL failed, errno = %d\n", errno);
- return(-errno);
- }
+ if(flags < 0)
+ return errno;
if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) ||
- (fcntl(master, F_SETOWN, os_getpid()) < 0)){
- printk("fcntl F_SETFL or F_SETOWN failed, errno = %d\n",
- errno);
- return(-errno);
- }
+ (fcntl(master, F_SETOWN, os_getpid()) < 0))
+ return -errno;
- if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)){
- printk("fcntl F_SETFL failed, errno = %d\n", errno);
- return(-errno);
- }
+ if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0))
+ return -errno;
return(0);
}
int os_open_file(char *file, struct openflags flags, int mode)
{
- int fd, f = 0;
+ int fd, err, f = 0;
if(flags.r && flags.w) f = O_RDWR;
else if(flags.r) f = O_RDONLY;
return(-errno);
if(flags.cl && fcntl(fd, F_SETFD, 1)){
+ err = -errno;
os_close_file(fd);
- return(-errno);
+ return err;
}
return(fd);
return(fd);
}
if(ioctl(fd, BLKGETSIZE, &blocks) < 0){
+ err = -errno;
printk("Couldn't get the block size of \"%s\", "
"errno = %d\n", file, errno);
- err = -errno;
os_close_file(fd);
return(err);
}
int os_set_fd_async(int fd, int owner)
{
+ int err;
+
/* XXX This should do F_GETFL first */
if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){
+ err = -errno;
printk("os_set_fd_async : failed to set O_ASYNC and "
"O_NONBLOCK on fd # %d, errno = %d\n", fd, errno);
- return(-errno);
+ return err;
}
#ifdef notdef
if(fcntl(fd, F_SETFD, 1) < 0){
if((fcntl(fd, F_SETSIG, SIGIO) < 0) ||
(fcntl(fd, F_SETOWN, owner) < 0)){
+ err = -errno;
printk("os_set_fd_async : Failed to fcntl F_SETOWN "
"(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd,
owner, errno);
- return(-errno);
+ return err;
}
return(0);
if(blocking) flags &= ~O_NONBLOCK;
else flags |= O_NONBLOCK;
- if(fcntl(fd, F_SETFL, flags) < 0){
- printk("Failed to change blocking on fd # %d, errno = %d\n",
- fd, errno);
- return(-errno);
- }
+ if(fcntl(fd, F_SETFL, flags) < 0)
+ return -errno;
+
return(0);
}
int sock, err;
sock = socket(PF_UNIX, SOCK_DGRAM, 0);
- if (sock < 0){
- printk("create_unix_socket - socket failed, errno = %d\n",
- errno);
- return(-errno);
- }
+ if(sock < 0)
+ return -errno;
if(close_on_exec) {
err = os_set_exec_close(sock, 1);
snprintf(addr.sun_path, len, "%s", file);
err = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
- if (err < 0){
- printk("create_listening_socket at '%s' - bind failed, "
- "errno = %d\n", file, errno);
- return(-errno);
- }
+ if(err < 0)
+ return -errno;
return(sock);
}