Back to index

texmacs  1.0.7.15
Classes | Defines | Functions | Variables
pipe_link.cpp File Reference
#include "basic.hpp"
#include "tm_link.hpp"
#include "socket_notifier.hpp"
#include "sys_utils.hpp"
#include "hashset.hpp"
#include "iterator.hpp"
#include "timer.hpp"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <malloc.h>

Go to the source code of this file.

Classes

struct  pipe_link_rep

Defines

#define STDIN   0
#define STDOUT   1
#define STDERR   2
#define IN   0
#define OUT   1
#define TERMCHAR   '\1'

Functions

void pipe_callback (void *obj, void *info)
tm_link make_pipe_link (string cmd)
void close_all_pipes ()
void process_all_pipes ()
void execute_shell (string s)
static string debug_io_string (string s)

Variables

hashset< pointerpipe_link_set
char ** environ

Define Documentation

#define IN   0

Definition at line 44 of file pipe_link.cpp.

#define OUT   1

Definition at line 45 of file pipe_link.cpp.

#define STDERR   2

Definition at line 43 of file pipe_link.cpp.

#define STDIN   0

Definition at line 41 of file pipe_link.cpp.

#define STDOUT   1

Definition at line 42 of file pipe_link.cpp.

#define TERMCHAR   '\1'

Definition at line 46 of file pipe_link.cpp.


Function Documentation

void close_all_pipes ( )

Definition at line 103 of file pipe_link.cpp.

                   {
#ifndef __MINGW32__
  iterator<pointer> it= iterate (pipe_link_set);
  while (it->busy()) {
    pipe_link_rep* con= (pipe_link_rep*) it->next();
    if (con->alive) {
      if (-1 != killpg(con->pid,SIGTERM)) {
       sleep(2);
       killpg(con->pid,SIGKILL);
      }
      con->alive= false;
    }
  }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string debug_io_string ( string  s) [static]

Definition at line 210 of file pipe_link.cpp.

                           {
  int i, n= N(s);
  string r;
  for (i=0; i<n; i++) {
    unsigned char c= (unsigned char) s[i];
    if (c == DATA_BEGIN) r << "[BEGIN]";
    else if (c == DATA_END) r << "[END]";
    else if (c == DATA_COMMAND) r << "[COMMAND]";
    else if (c == DATA_ESCAPE) r << "[ESCAPE]";
    else r << s[i];
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void execute_shell ( string  s)

Definition at line 134 of file pipe_link.cpp.

                         {
  char *_s= as_charp (s);
  char *argv[4];
  argv[0] = const_cast<char*> ("sh");
  argv[1] = const_cast<char*> ("-c");
  argv[2] = _s;
  argv[3] = NULL;
  execve ("/bin/sh", argv, environ);
  tm_delete_array (_s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file pipe_link.cpp.

                            {
  return tm_new<pipe_link_rep> (cmd);
}

Here is the caller graph for this function:

void pipe_callback ( void *  obj,
void *  info 
)

Definition at line 339 of file pipe_link.cpp.

                                           {
#ifndef __MINGW32__
  (void) info;
  pipe_link_rep* con= (pipe_link_rep*) obj;  
  bool busy= true;
  bool news= false;
  while (busy) {
    fd_set rfds;
    FD_ZERO (&rfds);
    int max_fd= max (con->err, con->out) + 1;
    FD_SET (con->out, &rfds);
    FD_SET (con->err, &rfds);
  
    struct timeval tv;
    tv.tv_sec  = 0;
    tv.tv_usec = 0;
    select (max_fd, &rfds, NULL, NULL, &tv);

    busy= false;
    if (con->alive && FD_ISSET (con->out, &rfds)) {
      //cout << "pipe_callback OUT" << LF;
      con->feed (LINK_OUT);
      busy= news= true;
    }
    if (con->alive && FD_ISSET (con->err, &rfds)) {
      //cout << "pipe_callback ERR" << LF;
      con->feed (LINK_ERR);
      busy= news= true;
    }
  }
  /* FIXME: find out the appropriate place to call the callback
     Currently, the callback is called in tm_server_rep::interpose_handler */
  if (!is_nil (con->feed_cmd) && news) {
    //cout << "pipe_callback APPLY" << LF;
    if (!is_nil (con->feed_cmd))
      con->feed_cmd->apply (); // call the data processor
  }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 120 of file pipe_link.cpp.

                     {
  iterator<pointer> it= iterate (pipe_link_set);
  while (it->busy()) {
    pipe_link_rep* con= (pipe_link_rep*) it->next();
    if (con->alive) con->apply_command ();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char** environ

Definition at line 34 of file tm_shell.cpp.

Definition at line 37 of file pipe_link.cpp.