示例#1
0
int addUserT(char *args, pBackbone BackboneAux, int nArgs, unsigned long len)
{
    pInbound in = malloc(sizeof(Inbound));
    char *temp[2];
    char msg[150];
    
    argsSep(temp,args,nArgs);
    
    if(addUserv2(BackboneAux, temp[0], temp[1]))
    {
        sprintf(msg,"%d | User %s added.",BackboneAux->date,temp[0]);
        writeLog(msg,BackboneAux->logger->pid);
        in->valid = 1;
    } else
    {
        sprintf(msg,"%d | Error: adding user.",BackboneAux->date);
        writeLog(msg,BackboneAux->logger->pid);
        in->valid = 0;
    }
    
    if(writePipe(npAdmin,in))
        return 1;
    else
        return 0;
    
}
示例#2
0
void *ip232_thread(void *arg)
{
  modem_config *cfg = (modem_config *) arg;
  int accept_pending = FALSE;
  int rc;
  int res = 0;
  char buf[256];

  fd_set readfs;
  int max_fd = 0;
  int cSocket;


  LOG_ENTER();
  for (;;) {
    FD_ZERO(&readfs);
    FD_SET(cfg->dce_data.dp[1][0], &readfs);
    max_fd = cfg->dce_data.dp[1][0];
    if (accept_pending == FALSE) {
      FD_SET(cfg->dce_data.sSocket, &readfs);
      max_fd = MAX(max_fd, cfg->dce_data.sSocket);
    }
    LOG(LOG_ALL, "Waiting for incoming ip232 connections");
    rc = select(max_fd + 1, &readfs, NULL, NULL, NULL);
    if (rc < 0) {

      // handle error
    }
    else {
      if (FD_ISSET(cfg->dce_data.dp[1][0], &readfs)) {  // pipe
        res = read(cfg->dce_data.dp[1][0], buf, sizeof(buf) - 1);
        LOG(LOG_DEBUG, "ip232 thread notified");
        accept_pending = FALSE;
      }
      if (FD_ISSET(cfg->dce_data.sSocket, &readfs)) {   // ip connection
        if (cfg->dce_data.ip232_is_connected) {
          LOG(LOG_DEBUG, "Already have ip232 connection, rejecting new");

          // already have a connection... accept and close
          cSocket = ip_accept(cfg->dce_data.sSocket);
          if (cSocket > -1) {
            close(cSocket);
          }
        }
        else {
          LOG(LOG_DEBUG, "Incoming ip232 connection");
          writePipe(cfg->dce_data.dp[0][1], MSG_ACCEPT);
          accept_pending = TRUE;
        }
      }
    }
  }
  LOG_EXIT();
}
示例#3
0
文件: npopen.c 项目: ricksladkey/vile
void
npclose(FILE *fp)
{
#if SYS_MSDOS
    if (myWrtr != 0 && myPipe == 0)
        writePipe(myCmds);
#endif
    closePipe(&myRead);
    closePipe(&myWrtr);
    closePipe(&myPipe);
    deleteTemp();
}
示例#4
0
int logoutAT(int pid, pBackbone BackboneAux)
{
    pAdmin adAux = BackboneAux->admin;
    pInbound in = malloc(sizeof(Inbound));
    char msg[150];
    
    adAux->pid = 0;
    
    sprintf(msg,"%d | Admin logged out.",BackboneAux->date);
    writeLog(msg,BackboneAux->logger->pid);
    in->valid = 1;
    if(writePipe(npAdmin,in))
        return 1;
    else
        return 0;
}
示例#5
0
int main(void)
{
	PIPE * pipe = NULL;
	int ret;
	pid_t pid;

	ret = createPipe(&pipe);
	if (ret == -1) {
		printf("create fail!\n");
		return -1;
	}

	pid = fork();
	if (pid == 0) {
		setRDWRflag(pipe, WRITE);
		ret = writePipe(pipe, "Hello world!\n", 
			13);
		if (ret == -1) {
			printf("write pipe fail!\n");
			closePipe(pipe);
			exit(1);
		}	
		closePipe(pipe);
		exit(0);
	}

	if (pid > 0) {
		wait(NULL);
		setRDWRflag(pipe, READ);
		char buf[32];
		bzero(buf, 32);
		ret = readPipe(pipe, buf, 13);
		if (ret == -1) {
			printf("read pipe fail!\n");
			closePipe(pipe);
			exit(1);
		}
		printf("%s", buf);
		closePipe(pipe);
		exit(0);
	}
}
示例#6
0
int alertServerUp(char *filename)
{
    int len=0;
    int job=1;
    int userlevel=3;
    int pid=getpid();
    
    pOutbound out = malloc(sizeof(Outbound));

    out->len = len;
    out->pid = pid;
    out->userLevel = userlevel;
    out->jobRef = job;

    if(!writePipe(out))
        return 0;
    else
        return 1;
    
}
示例#7
0
文件: utils.cpp 项目: KDE/snoretoast
bool writePipe(const std::filesystem::path &pipe, const std::wstring &data, bool wait)
{
    HANDLE hPipe = CreateFile(pipe.wstring().c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0,
                              nullptr);
    if (hPipe != INVALID_HANDLE_VALUE) {
        DWORD written;
        const DWORD toWrite = static_cast<DWORD>(data.size() * sizeof(wchar_t));
        WriteFile(hPipe, data.c_str(), toWrite, &written, nullptr);
        const bool success = written == toWrite;
        tLog << (success ? L"Wrote: " : L"Failed to write: ") << data << " to " << pipe;
        WriteFile(hPipe, nullptr, sizeof(wchar_t), &written, nullptr);
        CloseHandle(hPipe);
        return success;
    } else if (wait) {
        // wait and retry
        Sleep(20000);
        return writePipe(pipe, data);
    }
    tLog << L"Failed to open pipe: " << pipe << L" data: " << data;
    return false;
}
示例#8
0
int getDate(pBackbone BackboneAux)
{
    pInbound in = malloc(sizeof(Inbound));
    char msg[150];
    
    if(BackboneAux->date > 0)
    {
        in->valid = BackboneAux->date;
        sprintf(msg,"%d | Admin requesting system date.",BackboneAux->date);
        writeLog(msg,BackboneAux->logger->pid);
    }
    else
    {
        in->valid = 0;
        sprintf(msg,"%d | Error occured: system date request.",BackboneAux->date);
        writeLog(msg,BackboneAux->logger->pid);
    }
    if(writePipe(npAdmin,in))
        return 1;
    else
        return 0;
}
示例#9
0
qword sys_write(qword file, qword buffer, qword size, qword r8, qword r9){

    char* charbuffer=(char*)buffer;
    if(file==1){
        while(size--){
            printChar(*charbuffer++);
        }
    }else if(file==2){

        Color col={col.r=0xFF,col.b=00,col.g=00};
        Color aux=getColor();
        _setColor(col);
        while(size--){
            printChar(*charbuffer++);

        }
        _setColor(aux);
    }else if(file>2 && file<8){
        pipe_t pipe=(getMyProcessData())->fd[file-3];
        writePipe(pipe,buffer,size);
    }

return 1;
}
示例#10
0
int delCityT(char *args, pBackbone BackboneAux, int nArgs, unsigned long len)
{
    pInbound in = malloc(sizeof(Inbound));
    char *temp[1];
    char msg[150];
    
    argsSep(temp,args,nArgs);
    
    if(delCity(BackboneAux, temp[0]))
    {
        sprintf(msg,"%d | City : %s removed.",BackboneAux->date,temp[0]);
        writeLog(msg,BackboneAux->logger->pid);
        in->valid = 1;
    } else {
        sprintf(msg,"%d | Error: removing city. Invalid city?",BackboneAux->date);
        writeLog(msg,BackboneAux->logger->pid);
        in->valid = 0;
    }
    if(writePipe(npAdmin,in))
        return 1;
    else
        return 0;
    
}
示例#11
0
文件: tcpser.c 项目: ansi88/tcpser
int main(int argc, char *argv[]) {
  modem_config cfg[64];
  int modem_count;
  int port=0;

  char *ip_addr = NULL; /* gwb */

  unsigned char all_busy[255];

  pthread_t thread_id;
  int i;
  int rc;

  int sSocket = 0;
  fd_set readfs; 
  int max_fd=0;
  int accept_pending=FALSE;

  int res=0;
  unsigned char buf[255];

  int cSocket;

  log_init();

  LOG_ENTER();

  log_set_level(LOG_FATAL);

  mdm_init();

  pb_init();
  
  signal(SIGIO,SIG_IGN); /* Some Linux variant term on SIGIO by default */

  modem_count = init(argc, argv, cfg, 64, &ip_addr, &port,all_busy,sizeof(all_busy)); /* gwb */

  sSocket = ip_init_server_conn(ip_addr, port);


  for(i=0;i<modem_count;i++) {
    if( -1 == pipe(cfg[i].data.mp[0])) {
      ELOG(LOG_FATAL,"Bridge task incoming IPC pipe could not be created");
      exit(-1);
    }
    if( -1 == pipe(cfg[i].data.mp[1])) {
      ELOG(LOG_FATAL,"Bridge task outgoing IPC pipe could not be created");
      exit(-1);
    }
    if(dce_init_conn(&cfg[i]) < 0) {
      LOG(LOG_FATAL,"Could not open serial port %s",cfg->dce_data.tty);
      exit(-1);
    }
    cfg[i].line_data.sfd=sSocket;

    rc=pthread_create(&thread_id,NULL,*run_bridge,(void *)&cfg[i]);
    if(rc < 0) {
        ELOG(LOG_FATAL,"IP thread could not be started");
        exit(-1);
    }

  }
  for(;;) {
    FD_ZERO(&readfs);
    max_fd=0;
    for(i=0;i<modem_count;i++) {
      FD_SET(cfg[i].data.mp[0][0], &readfs); 
      max_fd=MAX(max_fd,cfg[i].data.mp[0][0]);
    }
    if(accept_pending==FALSE) {
      max_fd=MAX(max_fd,sSocket);
      FD_SET(sSocket, &readfs); 
    }
    LOG(LOG_ALL,"Waiting for incoming connections and/or indicators");
    select(max_fd+1, &readfs, NULL, NULL, NULL);
    for(i=0;i<modem_count;i++) {
      if (FD_ISSET(cfg[i].data.mp[0][0],&readfs)) {  // child pipe
        res = read(cfg[i].data.mp[0][0],buf,sizeof(buf) -1);
        if(res > -1) {
          buf[res]=0;
          LOG(LOG_DEBUG,"modem core #%d sent response '%c'",i,buf[0]);
          accept_pending=FALSE;
        }
      }
    }
    if (FD_ISSET(sSocket,&readfs)) {  // IP traffic
      if(!accept_pending) {
        LOG(LOG_DEBUG,"Incoming connection pending");
        // first try for a modem that is listening.
        for(i=0;i<modem_count;i++) {
          if(cfg[i].s[0] != 0 && cfg[i].off_hook == FALSE) {
            // send signal to pipe saying pick up...
            LOG(LOG_DEBUG,"Sending incoming connection to listening modem #%d",i);
            writePipe(cfg[i].data.mp[1][1],MSG_ACCEPT);  
            accept_pending=TRUE;
            break;
          }
        }
        // now, send to any non-active modem.
        for(i=0;i<modem_count;i++) {
          if(cfg[i].off_hook== FALSE) {
            // send signal to pipe saying pick up...
            LOG(LOG_DEBUG,"Sending incoming connection to non-connected modem #%d",i);
            writePipe(cfg[i].data.mp[1][1],MSG_ACCEPT);  
            accept_pending=TRUE;
            break;
          }
        }
        if(i==modem_count) {
          LOG(LOG_DEBUG,"No open modem to send to, send notice and close");
          // no connections.., accept and print error
          cSocket=ip_accept(sSocket);
          if(cSocket > -1) {
            if(strlen(all_busy) < 1) {
              ip_write(cSocket,(unsigned char*)MDM_BUSY,strlen(MDM_BUSY));
            } else {
              writeFile(all_busy,cSocket);
            }
            close(cSocket);
          }
        }
      }
    }
  }
  LOG_EXIT();
  return rc;
}
示例#12
0
void executePipe(char *line, char *cmd) {
	int bgFg = getFgBg(cmd);	/* fg(0) or bg(1) */
	int status;

	pid_t pid = fork();

	if(pid < 0) {
		perror("Fork error, pid < 0");
	/* parent */
	} else if(pid > 0) {
		/* set process group ID of child to self pid */
		/* will suspend when receive SIGTTIN and SIGTTOU signals */
		setpgid(pid, pid);

		/* set terminal control to new process group with child */
		tcsetpgrp(STDIN_FILENO, pid);

		/* insert process in the list */
		insertProcess(pid, bgFg, cmd);


		if(processList.current->process.status == FOREGROUND) {
			/* wait child finish */
			waitpid(pid, &status, WUNTRACED);
		}

		/* parent regains terminal control */
		tcsetpgrp(STDIN_FILENO, getpgid(0));
	/* child */
	} else {
		/* signals SIGTSTP and SIGINT will show default behavior in child */
		defaultSignals();
		
		/* set group id of child to self pid */
		/* suspend when receive signals SIGTTIN and SIGTTOUT */
		/* the child could go through exec before the parent set the group */
		setpgid(0, 0);

        int startLine = 0;	/* search begin of next expression */
        int start, end;		/* expression delimiters */
        char *previousCmd;
		
		/* while find commands between pipes */
        while(setExpressionDelimiters(line + startLine,
        	"[^| ]([^|]*[^| ])?", &start, &end)) {
        	
            previousCmd = cmd;
            
            /* get current command */
            cmd = getExpression(line + startLine, start, end, 0);
            
            /* go to next search */
            startLine += end;

			/* file input and output of pipe */
            int file[2];
            pid_t pid;

            newPipe(file, &pid);

			/* parent */
			if(pid > 0) {
				readPipe(file);
			/* child */
			} else {
				writePipe(file);
				internalExternalPipe(previousCmd, NO_JOBS_CONTROL);
			}
        }

		/* execute last command */
        internalExternalPipe(cmd, NO_JOBS_CONTROL);
    }
}
示例#13
0
bool notify(PIPE_PTR fd)
{
    char byte = '\n';
    return writePipe(fd, &byte, 1) == 1;
}
示例#14
0
static void triggerCommand(THREAD_PTR cmd)
{
    THREAD_PTR flg = INVALID_THREAD_PTR;
    writePipe(srvSettings.commPipe[WRITE], &flg, sizeof(THREAD_PTR));
    writePipe(srvSettings.commPipe[WRITE], &cmd, sizeof(THREAD_PTR));
}
示例#15
0
int ip232_read(modem_config *cfg, char *data, int len)
{
  int res;
  int rc;
  char buf[256];
  int i = 0;
  int ch;
  int text_len = 0;


  LOG_ENTER();
  if (len > sizeof(buf)) {
    LOG(LOG_FATAL, "ip232_read: len > sizeof(buf)");
    exit(-1);
  }
  if (cfg->dce_data.ip232_is_connected) {
    res = recv(cfg->dce_data.fd, buf, len, 0);
    if (0 >= res) {
      LOG(LOG_INFO, "No ip232 socket data read, assume closed peer");
      ip_disconnect(cfg->dce_data.fd);
      cfg->dce_data.fd = cfg->dce_data.dp[0][0];
      cfg->dce_data.ip232_is_connected = FALSE;
    }
    else {
      LOG(LOG_DEBUG, "Read %d bytes from ip232 socket", res);
      log_trace(TRACE_MODEM_IN, buf, res);
      while (i < res) {
        ch = buf[i];
        if (cfg->dce_data.ip232_iac) {
          cfg->dce_data.ip232_iac = FALSE;
          switch (ch) {
          case 0:
            cfg->dce_data.ip232_dtr = FALSE;
            break;
          case 1:
            cfg->dce_data.ip232_dtr = TRUE;
            break;
          case 255:
            data[text_len++] = 255;
            break;
          }
        }
        else {
          if (255 == ch) {
            cfg->dce_data.ip232_iac = TRUE;
          }
          else {
            data[text_len++] = ch;
          }
        }
        i++;
      }
    }
  }
  else {
    // not connected
    res = read(cfg->dce_data.dp[0][0], buf, sizeof(buf));
    switch (buf[0]) {
    case MSG_ACCEPT:   // accept connection.
      LOG(LOG_INFO, "Accepting ip232 connection...");
      rc = ip_accept(cfg->dce_data.sSocket);
      if (res > -1) {
        cfg->dce_data.fd = rc;
        cfg->dce_data.ip232_is_connected = TRUE;
        cfg->dce_data.ip232_dtr = FALSE;
        cfg->dce_data.ip232_dcd = FALSE;
        writePipe(cfg->dce_data.dp[1][1], MSG_ACCEPTED);
      }
      break;
    }
  }

  LOG_EXIT();
  return text_len;
}
示例#16
0
ssize_t __pwrite(int fd, const void *data, size_t size) {
    idStream *is = getStreamData(getpid(), fd);
    if(!is)
        return -1;
    return writePipe(is->fd, data, size);
}