Example #1
0
int open_callmgr(struct in_addr inetaddr, int argc, char **argv, char **envp) {
  /* Try to open unix domain socket to call manager. */
  struct sockaddr_un where;
  const int NUM_TRIES = 3;
  int i, fd;

  /* Open socket */
  if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
    pptp_error("Could not create unix domain socket: %s", strerror(errno));
    return(-1);
  }

  /* Make sure the socket is closed if callmgr is launched */
  fcntl(fd, F_SETFD, FD_CLOEXEC);

  /* Make address */
  where.sun_family = AF_UNIX;
  snprintf(where.sun_path, sizeof(where.sun_path), 
	   PPTP_SOCKET_PREFIX "%s", inet_ntoa(inetaddr));

  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. */
      launch_callmgr(inetaddr, argc,argv,envp);
      sleep(3);
    }
    else return fd;
  }
  close(fd);
  pptp_error("Could not launch call manager after %d tries.", i);
  return -1;   /* make gcc happy */
}
Example #2
0
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 */
}
Example #3
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 */
}