Changeset 4132


Ignore:
Timestamp:
Jan 17, 2014, 10:27:20 PM (11 years ago)
Author:
ldelgass
Message:

Restore the rest of r4114

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanoscale/server.c

    r4131 r4132  
    1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     1/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2/* ======================================================================
     3 *  Copyright (c) 2004-2014  HUBzero Foundation, LLC
     4 * ----------------------------------------------------------------------
     5 *  See the file "license.terms" for information on usage and
     6 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
     7 * ======================================================================
     8 */
    29#define _GNU_SOURCE
    310#include <sys/socket.h>
     
    492499#ifdef HAVE_ACCEPT4
    493500            sock = accept4(serverPtr->listenerFd, (struct sockaddr *)&newaddr,
    494                         &length, SOCK_CLOEXEC);
     501                           &length, SOCK_CLOEXEC);
    495502#else
    496503            sock = accept(serverPtr->listenerFd, (struct sockaddr *)&newaddr,
    497                        &length);
     504                          &length);
    498505#endif
    499506            if (sock < 0) {
     
    600607                    }
    601608                }
    602                 /* Dup the socket to descriptors, normally 3 and 4 */
    603                 if (dup2(sock, serverPtr->inputFd) < 0)  { /* Stdin */
    604                     ERROR("%s: can't dup stdin: %s", serverPtr->name,
    605                         strerror(errno));
    606                     exit(1);
    607                 }
    608                 if (dup2(sock, serverPtr->outputFd) < 0) { /* Stdout */
    609                     ERROR("%s: can't dup stdout: %s", serverPtr->name,
     609                /* Dup the socket to descriptors, e.g. 3 and 4 */
     610                if (dup2(sock, serverPtr->inputFd) < 0)  { /* input */
     611                    ERROR("%s: can't dup socket to fd %d: %s",
     612                          serverPtr->name, serverPtr->inputFd,
    610613                          strerror(errno));
    611614                    exit(1);
    612615                }
    613                 for(i = serverPtr->outputFd + 1; i <= FD_SETSIZE; i++) {
     616                if (serverPtr->outputFd != serverPtr->inputFd) {
     617                    if (dup2(sock, serverPtr->outputFd) < 0) { /* output */
     618                        ERROR("%s: can't dup socket to fd %d: %s",
     619                              serverPtr->name, serverPtr->outputFd,
     620                              strerror(errno));
     621                        exit(1);
     622                    }
     623                }
     624                for (i = serverPtr->outputFd + 1; i <= FD_SETSIZE; i++) {
    614625                    close(i);           /* Close all the other descriptors. */
    615626                }
Note: See TracChangeset for help on using the changeset viewer.