コード例 #1
0
void close_unixsock(int fd, struct in_addr inetaddr) {
  struct sockaddr_un where;
  
  close(fd);
  callmgr_name_unixsock(&where, inetaddr, localbind);
  unlink(where.sun_path);
}
コード例 #2
0
int open_unixsock(struct in_addr inetaddr) {
  struct sockaddr_un where;
  struct stat st;
  char *dir;
  int s;

  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    warn("socket: %s", strerror(errno));
    return s;
  }

  callmgr_name_unixsock(&where, inetaddr, localbind);

  if (stat(where.sun_path, &st) >= 0) {
    warn("Call manager for %s is already running.", inet_ntoa(inetaddr));
    close(s); return -1;
  }

  /* Make sure path is valid. */
  dir = dirname(where.sun_path);
  if (!make_valid_path(dir, 0770))
    fatal("Could not make path to %s: %s", where.sun_path, strerror(errno));
  free(dir);

  if (bind(s, (struct sockaddr *) &where, sizeof(where)) < 0) {
    warn("bind: %s", strerror(errno));
    close(s); return -1;
  }

  chmod(where.sun_path, 0777);

  listen(s, 127);

  return s;
}
コード例 #3
0
ファイル: pptp.c プロジェクト: schidler/flyzjhz-rt-n56u
static int open_callmgr(int call_id,struct in_addr inetaddr, char *phonenr,int window)
{
    /* Try to open unix domain socket to call manager. */
    struct sockaddr_un where;
    const int NUM_TRIES = 3;
    int i, fd;
    pid_t pid;
    int status;
    /* Open socket */
    if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
    {
        fatal("Could not create unix domain socket: %s", strerror(errno));
    }
    /* Make address */
    callmgr_name_unixsock(&where, inetaddr, localbind);
    for (i = 0; i < NUM_TRIES; i++)
    {
        if (connect(fd, (struct sockaddr *) &where, sizeof(where)) < 0)
        {
            /* couldn't connect.  We'll have to launch this guy. */

            unlink (where.sun_path);

            /* fork and launch call manager process */
            switch (pid = fork())
            {
            case -1: /* failure */
                fatal("fork() to launch call manager failed.");
            case 0: /* child */
            {
                close (fd);
                close(pptp_fd);
                /* close the pty and gre in the call manager */
                //close(pty_fd);
                //close(gre_fd);
                launch_callmgr(call_id,inetaddr, phonenr,window);
            }
            default: /* parent */
                waitpid(pid, &status, 0);
                if (WIFEXITED(status))
                    status = WEXITSTATUS(status);
                if (status!= 0)
                {
                    close(fd);
                    error("Call manager exited with error %d", status);
                    return -1;
                }
                break;
            }
            sleep(1);
        }
        else return fd;
    }
    close(fd);
    error("Could not launch call manager after %d tries.", i);
    return -1;   /* make gcc happy */
}
コード例 #4
0
/*** start the call manager ***************************************************/
int open_callmgr(struct in_addr inetaddr, char *phonenr, int argc, char **argv,
                 char **envp, int pty_fd, int gre_fd)
{
    /* Try to open unix domain socket to call manager. */
    union {
        struct sockaddr a;
        struct sockaddr_un u;
    } where;
    const int NUM_TRIES = 3;
    int i, fd;
    pid_t pid;
    int status;
    /* Open socket */
    if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
        fatal("Could not create unix domain socket: %s", strerror(errno));
    }
    /* Make address */
    callmgr_name_unixsock(&where.u, inetaddr, localbind);
    for (i = 0; i < NUM_TRIES; i++) {
        if (connect(fd, &where.a, sizeof(where)) < 0) {
            /* couldn't connect.  We'll have to launch this guy. */

            unlink (where.u.sun_path); /* FIXME: potential race condition */

            /* fork and launch call manager process */
            switch (pid = fork()) {
            case -1: /* failure */
                fatal("fork() to launch call manager failed.");
            case 0: /* child */
            {
                close (fd);
                /* close the pty and gre in the call manager */
                close(pty_fd);
                close(gre_fd);
                launch_callmgr(inetaddr, phonenr, argc, argv, envp);
            }
            default: /* parent */
                waitpid(pid, &status, 0);
                if (WEXITSTATUS(status) != 0)
                    fatal("Call manager exited with error %d", status);
                break;
            }
            sleep(1);
        }
        else return fd;
    }
    close(fd);
    fatal("Could not launch call manager after %d tries.", i);
    return -1;   /* make gcc happy */
}