Exemple #1
0
unsigned char source_readByte()
{
	int ret_val;
	int sample;

	ret_val = fscanf(input, "%i\n", &sample);

	if(ret_val != 1)
	{
		close_all();
		exit(0);
	}

	return (unsigned char) sample;
}
Exemple #2
0
void bt_push_shutdown()
{
    bt_push_t *push = g_registry;
    REPORT_INFO(LC_PUSH, "Shutting down Bluetooth PushRegistry.");
    while (push != NULL) {
        bt_push_t *next = push->next;
        javacall_bt_sddb_remove_record(push->record.id);
        pcsl_mem_free(push->record.data);
        close_all(push);
        pcsl_mem_free(push);
        push = next;
    }
    g_registry = NULL;
    javacall_bt_sddb_finalize();
}
 /**
  * Signals the endpoint to call the io_service stop member function. If 
  * clean is true the endpoint will be put into an intermediate state where
  * it signals all connections to close cleanly and only calls stop once that
  * process is complete. Otherwise stop is called immediately and all 
  * io_service operations will be aborted.
  * 
  * If clean is true stop will use code and reason for the close code and 
  * close reason when it closes open connections. The default code is 
  * 1001/Going Away and the default reason is blank.
  * 
  * Visibility: public
  * State: Valid from RUNNING only
  * Concurrency: Callable from anywhere
  * 
  * @param clean Whether or not to wait until all connections have been
  * cleanly closed to stop io_service operations.
  * @param code The WebSocket close code to send to remote clients as the
  * reason that the connection is being closed.
  * @param reason The WebSocket close reason to send to remote clients as the
  * text reason that the connection is being closed. Must be valid UTF-8.
  */
 void stop(bool clean = true, 
           close::status::value code = close::status::GOING_AWAY, 
           const std::string& reason = "")
 {        
     boost::lock_guard<boost::recursive_mutex> lock(m_lock);
     
     if (clean) {
         m_alog->at(log::alevel::ENDPOINT) 
             << "Endpoint is stopping cleanly" << log::endl;
         
         m_state = STOPPING;
         close_all(code,reason);
     } else {
         m_alog->at(log::alevel::ENDPOINT) 
             << "Endpoint is stopping immediately" << log::endl;
         
         endpoint_base::m_io_service.stop();
         m_state = STOPPED;
     }
 }
// close out after Cancel clicked
void US_NoiseLoader::cancelled()
{
   close_all();
}
Exemple #5
0
 ~command() override  { close_all(); }
Exemple #6
0
/**
 * Eventually calls exit(), passing @p code, therefore does not return.
 *
 * @param code one of the RERR_* codes from errcode.h.
 **/
NORETURN void _exit_cleanup(int code, const char *file, int line)
{
	static int switch_step = 0;
	static int exit_code = 0, exit_line = 0;
	static const char *exit_file = NULL;
	static int first_code = 0;

	SIGACTION(SIGUSR1, SIG_IGN);
	SIGACTION(SIGUSR2, SIG_IGN);

	if (!exit_code) { /* Preserve first error exit info when recursing. */
		exit_code = code;
		exit_file = file;
		exit_line = line < 0 ? -line : line;
	}

	/* If this is the exit at the end of the run, the server side
	 * should not attempt to output a message (see log_exit()). */
	if (am_server && code == 0)
		am_server = 2;

	/* Some of our actions might cause a recursive call back here, so we
	 * keep track of where we are in the cleanup and never repeat a step. */
	switch (switch_step) {
#include "case_N.h" /* case 0: */
		switch_step++;

		first_code = code;

		if (output_needs_newline) {
			fputc('\n', stdout);
			output_needs_newline = 0;
		}

		if (DEBUG_GTE(EXIT, 2)) {
			rprintf(FINFO,
				"[%s] _exit_cleanup(code=%d, file=%s, line=%d): entered\n",
				who_am_i(), code, file, line);
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (cleanup_child_pid != -1) {
			int status;
			int pid = wait_process(cleanup_child_pid, &status, WNOHANG);
			if (pid == cleanup_child_pid) {
				status = WEXITSTATUS(status);
				if (status > exit_code)
					exit_code = status;
			}
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (cleanup_got_literal && (cleanup_fname || cleanup_fd_w != -1)) {
			if (cleanup_fd_r != -1) {
				close(cleanup_fd_r);
				cleanup_fd_r = -1;
			}
			if (cleanup_fd_w != -1) {
				flush_write_file(cleanup_fd_w);
				close(cleanup_fd_w);
				cleanup_fd_w = -1;
			}
			if (cleanup_fname && cleanup_new_fname && keep_partial
			 && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
				int tweak_modtime = 0;
				const char *fname = cleanup_fname;
				cleanup_fname = NULL;
				if (!partial_dir) {
				    /* We don't want to leave a partial file with a modern time or it
				     * could be skipped via --update.  Setting the time to something
				     * really old also helps it to stand out as unfinished in an ls. */
				    tweak_modtime = 1;
				    cleanup_file->modtime = 0;
				}
				finish_transfer(cleanup_new_fname, fname, NULL, NULL,
						cleanup_file, tweak_modtime, !partial_dir);
			}
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (flush_ok_after_signal) {
			flush_ok_after_signal = False;
			if (code == RERR_SIGNAL)
				io_flush(FULL_FLUSH);
		}
		if (!exit_code && !code)
			io_flush(FULL_FLUSH);

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (cleanup_fname)
			do_unlink(cleanup_fname);
		if (exit_code)
			kill_all(SIGUSR1);
		if (cleanup_pid && cleanup_pid == getpid()) {
			char *pidf = lp_pid_file();
			if (pidf && *pidf)
				unlink(lp_pid_file());
		}

		if (exit_code == 0) {
			if (code)
				exit_code = code;
			if (io_error & IOERR_DEL_LIMIT)
				exit_code = RERR_DEL_LIMIT;
			if (io_error & IOERR_VANISHED)
				exit_code = RERR_VANISHED;
			if (io_error & IOERR_GENERAL || got_xfer_error)
				exit_code = RERR_PARTIAL;
		}

		/* If line < 0, this exit is after a MSG_ERROR_EXIT event, so
		 * we don't want to output a duplicate error. */
		if ((exit_code && line > 0)
		 || am_daemon || (logfile_name && (am_server || !INFO_GTE(STATS, 1))))
			log_exit(exit_code, exit_file, exit_line);

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (DEBUG_GTE(EXIT, 1)) {
			rprintf(FINFO,
				"[%s] _exit_cleanup(code=%d, file=%s, line=%d): "
				"about to call exit(%d)\n",
				who_am_i(), first_code, exit_file, exit_line, exit_code);
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (exit_code && exit_code != RERR_SOCKETIO && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
		 && exit_code != RERR_TIMEOUT && !shutting_down && (protocol_version >= 31 || am_receiver)) {
			if (line > 0) {
				if (DEBUG_GTE(EXIT, 3)) {
					rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n",
						who_am_i(), exit_code);
				}
				send_msg_int(MSG_ERROR_EXIT, exit_code);
			}
			noop_io_until_death();
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (am_server && exit_code)
			msleep(100);
		close_all();

		/* FALLTHROUGH */
	default:
		break;
	}

	exit(exit_code);
}
Exemple #7
0
void
runcmd(char *s)
{
	char *argv[MAXARGS], *t;
	int argc, c, i, r, p[2], fd, rightpipe;

	rightpipe = 0;
	gettoken(s, 0);
again:
	argc = 0;
	for(;;){
		c = gettoken(0, &t);
		switch(c){
		case 0:
			goto runit;
		case 'w':
			if(argc == MAXARGS){
				printf("too many arguments\n");
				exit();
			}
			argv[argc++] = t;
			break;
		case '<':
			if(gettoken(0, &t) != 'w'){
				printf("syntax error: < not followed by word\n");
				exit();
			}
			// Your code here -- open t for reading,
			// dup it onto fd 0, and then close the fd you got.
			//demo2s_code_start;
			if((fd=open(t,O_RDONLY))<0) {
				panic("%e\t%s",fd,t);
				break;
			}
			if((r=dup(fd,0))<0) {
				panic("can not dup! %e",r);
				break;
			}
			if((r=close(fd))<0) {
				panic("can not close %d! %e",fd,r);
				break;
			}

			break;
		case '>':
			if(gettoken(0, &t) != 'w'){
				printf("syntax error: > not followed by word\n");
				exit();
			}
			// Your code here -- open t for writing,
			// dup it onto fd 1, and then close the fd you got.
			if((fd=open(t,O_WRONLY))<0) {
				panic("%e\t%s",fd,t);
				break;
			}
			/*if((r=ftruncate(fd,0))<0) {
				printf("can not truncate! %e",r);
				break;
			}
			if((r=close(fd))<0) {
				panic("can not close %d! %e",fd,r);
				break;
			}
			*/
			if((fd=open(t,O_WRONLY))<0) {
				panic("%e\t%s",fd,t);
				break;
			}
			if((r=dup(fd,1))<0) {
				panic("can not dup! %e",r);
				break;
			}
			if((r=close(fd))<0) {
				panic("can not close %d! %e",fd,r);
				break;
			}
			break;
		case '|':
			// Your code here.
			// 	First, allocate a pipe.
			if((r=pipe(p))<0) {
				panic("can not pipe! %e",r);
				break;
			}
			//	Then fork.
			if((r=fork())<0) {
				panic("fork %e",r);
				break;
			}
			//	the child runs the right side of the pipe:
			//		dup the read end of the pipe onto 0
			//		close the read end of the pipe
			//		close the write end of the pipe
			//		goto again, to parse the rest of the command line
			if(r==0) {
				if((r=dup(p[0],0))<0) {
					panic("dup %e",r);
					break;
				}
				if((r=close(p[0]))<0) {
					panic("close read end %e",r);
					break;
				}
				if((r=close(p[1]))<0) {
					panic("close write end %e",r);
					break;
				}
				goto again;
			}
			//	the parent runs the left side of the pipe:
			//		dup the write end of the pipe onto 1
			//		close the write end of the pipe
			//		close the read end of the pipe
			//		set "rightpipe" to the child envid
			//		goto runit, to execute this piece of the pipeline
			//			and then wait for the right side to finish
			rightpipe=r;
			if((r=dup(p[1],1))<0) {
				panic("dup %e",r);
				break;
			}
			if((r=close(p[0]))<0) {
				panic("close write end %e",r);
				break;
			}
			if((r=close(p[1]))<0) {
				panic("close read end %e",r);
				break;
			}
			goto runit;
			//demo2s_code_end;
			break;
		}
	}

runit:
	if(argc == 0) {
		if (debug) printf("EMPTY COMMAND\n");
		return;
	}
	argv[argc] = 0;
	if (debug) {
		printf("[%08x] SPAWN:", env->env_id);
		for (i=0; argv[i]; i++)
			printf(" %s", argv[i]);
		printf("\n");
	}
	if ((r = spawn(argv[0], argv)) < 0)
		printf("spawn %s: %e\n", argv[0], r);
	close_all();
	if (r >= 0) {
		if (debug) printf("[%08x] WAIT %s %08x\n", env->env_id, argv[0], r);
		wait(r);
		if (debug) printf("[%08x] wait %08x finished\n", env->env_id,r);
	}
	if (rightpipe) {
		if (debug) printf("[%08x] WAIT right-pipe %08x\n", env->env_id, rightpipe);
		wait(rightpipe);
		if (debug) printf("[%08x] wait finished\n", env->env_id);
	}
	exit();
}
Exemple #8
0
void ecriture(gpointer data, gint source, GdkInputCondition condition)
{
    static gchar buffer[BUFFER_EMISSION];
    static gchar *current_buffer;
    static gint bytes_to_write;
    gint bytes_written;
    gchar *car;

    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), (gfloat)car_written/(gfloat)nb_car );

    if(car_written < nb_car)
    {
	/* Read the file only if buffer totally sent or if buffer empty */
	if(current_buffer_position == bytes_read)
	{
	    bytes_read = read(Fichier, buffer, BUFFER_EMISSION);

	    current_buffer_position = 0;
	    current_buffer = buffer;
	    bytes_to_write = bytes_read;
	}

	car = current_buffer;

	if(config.delai != 0 || config.car != -1)
	{
	    /* search for next LF */
	    bytes_to_write = current_buffer_position;
	    while(*car != LINE_FEED && bytes_to_write < bytes_read)
	    {
		car++;
		bytes_to_write++;
	    }
	    if(*car == LINE_FEED)
		bytes_to_write++;
	}

	/* write to serial port */
	bytes_written = send_serial(current_buffer, bytes_to_write - current_buffer_position);

	if(bytes_written == -1)
	{
	    /* Problem while writing, stop file transfer */
	    g_free(str);
	    str = g_strdup_printf(_("Cannot write file %s\n"), strerror(errno));
	    show_message(str, MSG_ERR);
	    close_all();
	    return;
	}

	car_written += bytes_written;
	current_buffer_position += bytes_written;
	current_buffer += bytes_written;

	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), (gfloat)car_written/(gfloat)nb_car );

	if(config.delai != 0 && *car == LINE_FEED)
	{
	    remove_input();
	    g_timeout_add(config.delai, (GSourceFunc)timer, NULL);
	    waiting_for_timer = TRUE;
	}
	else if(config.car != -1 && *car == LINE_FEED)
	{
	    remove_input();
	    waiting_for_char = TRUE;
	}
    }
    else
    {
	close_all();
	return;
    }
    return;
}
Exemple #9
0
main()
{
  FILE *td;
  short j    = 0,
        hwix = 0;
  char kernel_check[12],
       command[80],
       h_type[4],
       tmpname[16];

  memset(kernel_check, 0x0, 12);
  memset(command, 0x0, 80);
  memset(tmpname, 0x0, 16);

  putenv("_=hw_dump");                  /* name to environ   */
  chdir(getenv("HOME"));                /* to home directory  */

  tmp_name(tmpname);
  sprintf(command, "%s > %s",
          "ps -ef|grep -v grep|grep ' bin/kernel'|cut -c54-63",
          tmpname);
  system(command);

  td = fopen(tmpname, "r");
  if (td == 0)
     {
       exit(-1);
     }

  fgets(kernel_check, 11, td);

  if (td)
     {
       fclose(td);
       unlink(tmpname);
     }

  if (strcmp(kernel_check, KERNELNAME) != 0)
     {
       printf("System not started.\n");
       exit(4);
     }

  ss_open();
  co_open();

  if (sp->sp_config_status != 'y')
     {
       printf("System is running.\n");
       close_all();
       exit(2);
     }

  hwf = fopen(DUMPFILE, "w");

  if (hwf == 0)
     {
       printf("Cannot open sql/hw_dump.dat for writing.\n");
       close_all();
       exit(3);
     }

  for (j = 0; j < coh->co_light_cnt; j++)
      {
         memset(h_type, 0x0, 4);

         switch (hw[j].hw_type)
                {
                   case BL:   strcpy(h_type, "BL");
                              break;

                   case ZC:   strcpy(h_type, "ZC");
                              break;

                   case PM:   strcpy(h_type, "PM");
                              break;

                   case PI:   strcpy(h_type, "PI");
                              break;

                   case ZC2:  strcpy(h_type, "ZC2");
                              break;

                   case PM2:  strcpy(h_type, "PM2");
                              break;

                   case PM4:  strcpy(h_type, "PM4");
                              break;

                   case PM6:  strcpy(h_type, "PM6");
                              break;

                   case BF:   strcpy(h_type, "BF");
                              break;

                   case IO:   strcpy(h_type, "IO");
                              break;

                   default:   break;
                }  /* end of switch statement for hardware type */

         hwix = j + 1;

         fprintf(hwf, "%d|%d|%d|%d|%d|%d|%s|\n",
                 j,
                 hwix,
                 hw[j].hw_mod,
                 hw[j].hw_mod_address,
                 hw[j].hw_bay,
                 hw[j].hw_controller,
                 h_type);
         fflush(hwf);

      }  /* end of for loop to read hw table */

  fclose(hwf);

  memset(command, 0x0, 80);

  sprintf(command, "%s%s",
          "/u/mfc/script/ld_hw_dump_file ",
          "1>/u/mfc/dat/log/ld_hdf.log 2>&1");

  system(command);

  sleep(5);

  unlink(DUMPFILE);

  close_all();

  exit(0);
} /* end of main() */
VDevice1394::~VDevice1394()
{
	close_all();
}
Exemple #11
0
main()
{
  long pid, status;
  short rm,ret,i,si,n;
  unsigned char t;
  char buf[NUM_PROMPTS][BUF_SIZE];
  long order_num=0;
  short pickline;
  short all_pl=0;

  putenv("_=stockout_input");
  chdir(getenv("HOME"));
  
  open_all();

        /* set order length into fld_parms structure */

  LORDER = rf->rf_on;

        /* determine operator status */

  rm = 0; si = 1;
  if (SUPER_OP && !IS_ONE_PICKLINE) {rm = 1; si = 0;}
  pickline = op_pl;
  sprintf(buf[0], "%d", pickline);
  
  fix(stockout_input);
  sd_clear_screen();
  sd_screen_off();
  sd_text(stockout_input);
  sd_screen_on();

  for(i=0;i<NUM_PROMPTS;i++)
  for(n=0;n<BUF_SIZE;n++)
  buf[i][n] = 0;

  for(i = si; i < LAST_PROMPT; i++)
  sd_prompt(&fld[i],rm);                  /* display prompts                 */
  i = si;


        /* main loop to gather input */

  while(1)
  {
    t = sd_input(&fld[i],rm,&rm,buf[i],0);

    if(t == EXIT) leave();
    else if(t == UP_CURSOR && i > si) i--;
    
    else if(t == DOWN_CURSOR || t == TAB)
    {
      if(i == (LAST_PROMPT - 1)) i = 0;
      else i++;
    }
    else if (t == RETURN)
    {
                        /* validate proper pickline */

      if (si == 0)                        /* have pickline input             */
      {
        n = pl_lookup(buf[0], pickline);  /* numeric of pickline             */

        if (n <= 0)          
        {
          eh_post(ERR_CODE,buf[0]);       /* invalid pickline                */
          i=0;
          continue;
        }
        pickline = n;
        sprintf(buf[0], "%d", pickline);
        chng_pkln(buf[0]);
      }          
                        /* validate entered order number */

      if(!(*buf[1]) && !(*buf[2]))        /* nothing entered                 */
      {
        eh_post(ERR_REQ_ORDER, 0);
        i=1;
        continue;
      }
      if(*buf[2])                         /* if order number entered         */
      {
        order_num=atol(buf[2]);
        ret = oc_find(pickline, order_num);
        if(!ret)
        {
          eh_post(ERR_ORDER,buf[2]);
          i=2;
          continue;
        }
      }
      break;
    }
  }

        /* process print request */

  for(i=1;i<3;i++)                        /* fill non-entered with zero      */
  {
    if(*buf[i])
    ;
    else
    strcpy(buf[i],"0");
  }

  sd_prompt(&fld[4],rm);
  while(1)
  {
    t = sd_input(&fld[4],rm,&rm,buf[4],0);
    switch(sd_early(t, code_to_caps(*buf[4]))) /* F041897 */
    {
      case (0):
        leave();

      case (4):                           /* print == y                      */
        if(!(*buf[0]))                    /* no pickline entered             */
        {
          strcpy(buf[0], getenv("PICKLINE"));/* set current                  */
        }
        sd_wait();
        close_all();
        execlp("stockout_create", "stockout_create",
          buf[0], buf[1], buf[2], "", "print",  0);

        krash("main", "stockout_create load", 1);

      case (5):                           /* print == n                      */
        
        sd_wait();
        if(!(*buf[0]))                    /* no pickline entered             */
        {
          strcpy(buf[0], getenv("PICKLINE"));/* set current                  */
        }
        close_all();
        execlp("stockout_create", "stockout_create",
          buf[0], buf[1], buf[2], "", "report",  0);

        krash("main", "stockout_create load", 1);

      case (6):
        eh_post(ERR_YN,0);
        break;
      }
  }
}
Exemple #12
0
leave()
{
  close_all();
  execlp("syscomm", "syscomm", 0);
  krash("leave", "syscomm load", 1);
}
Exemple #13
0
/**
 * Eventually calls exit(), passing @p code, therefore does not return.
 *
 * @param code one of the RERR_* codes from errcode.h.
 **/
NORETURN void _exit_cleanup(int code, const char *file, int line)
{
	static int switch_step = 0;
	static int exit_code = 0, exit_line = 0;
	static const char *exit_file = NULL;
	static int unmodified_code = 0;

	SIGACTION(SIGUSR1, SIG_IGN);
	SIGACTION(SIGUSR2, SIG_IGN);

	if (exit_code) { /* Preserve first exit info when recursing. */
		code = exit_code;
		file = exit_file;
		line = exit_line;
	}

	/* If this is the exit at the end of the run, the server side
	 * should not attempt to output a message (see log_exit()). */
	if (am_server && code == 0)
		am_server = 2;

	/* Some of our actions might cause a recursive call back here, so we
	 * keep track of where we are in the cleanup and never repeat a step. */
	switch (switch_step) {
#include "case_N.h" /* case 0: */
		switch_step++;

		exit_code = unmodified_code = code;
		exit_file = file;
		exit_line = line;

		if (verbose > 3) {
			rprintf(FINFO,
				"[%s] _exit_cleanup(code=%d, file=%s, line=%d): entered\n",
				who_am_i(), code, file, line);
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (cleanup_child_pid != -1) {
			int status;
			int pid = wait_process(cleanup_child_pid, &status, WNOHANG);
			if (pid == cleanup_child_pid) {
				status = WEXITSTATUS(status);
				if (status > code)
					code = exit_code = status;
			}
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (cleanup_got_literal && cleanup_fname && cleanup_new_fname
		 && keep_partial && handle_partial_dir(cleanup_new_fname, PDIR_CREATE)) {
			const char *fname = cleanup_fname;
			cleanup_fname = NULL;
			if (cleanup_fd_r != -1)
				bpc_close(cleanup_fd_r);
			if (cleanup_fd_w != -1) {
				flush_write_file(cleanup_fd_w);
				bpc_close(cleanup_fd_w);
			}
			finish_transfer(cleanup_new_fname, fname, NULL, NULL,
					cleanup_file, 0, !partial_dir);
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (!code || am_server || am_receiver)
			io_flush(FULL_FLUSH);

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

                bpc_sysCall_cleanup();

		if (cleanup_fname)
			do_unlink(cleanup_fname);
		if (code)
			kill_all(SIGUSR1);
		if (cleanup_pid && cleanup_pid == getpid()) {
			char *pidf = lp_pid_file();
			if (pidf && *pidf)
				unlink(lp_pid_file());
		}

		if (code == 0) {
			if (io_error & IOERR_DEL_LIMIT)
				code = exit_code = RERR_DEL_LIMIT;
			if (io_error & IOERR_VANISHED)
				code = exit_code = RERR_VANISHED;
			if (io_error & IOERR_GENERAL || got_xfer_error)
				code = exit_code = RERR_PARTIAL;
		}

		if (code || am_daemon || (logfile_name && (am_server || !verbose)))
			log_exit(code, file, line);

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (verbose > 2) {
			rprintf(FINFO,
				"[%s] _exit_cleanup(code=%d, file=%s, line=%d): "
				"about to call exit(%d)\n",
				who_am_i(), unmodified_code, file, line, code);
		}

		/* FALLTHROUGH */
#include "case_N.h"
		switch_step++;

		if (am_server && code)
			msleep(100);
		close_all();

		/* FALLTHROUGH */
	default:
		break;
	}

	exit(code);
}
Exemple #14
0
int main(void) {

    struct sockaddr_in serv_addr;
    int listen_sock = socket(AF_INET, SOCK_STREAM, 0);
    linked_fd * fdlist = new_linked_fd();
    
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family=AF_INET;
    serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
    serv_addr.sin_port=htons(5058);
    
    int bind_result = bind(listen_sock,
                           (struct sockaddr*)&serv_addr, sizeof(serv_addr));
    if(bind_result == -1) {
        perror("Failed to bind.");
        return EXIT_FAILURE;
    }
    
    listen(listen_sock, 100);

    fd_set fdset;
    highest_fd = listen_sock;

    do {
        FD_ZERO(&fdset);
        // Add the listening socket to the fdset.
        FD_SET(listen_sock, &fdset);
        // Add stdin to the fileset.
        FD_SET(STDIN_FILENO, &fdset);

        // Add each fd in our fdlist to the set.
        linked_fd_node *current = linked_fd_head(fdlist);
        while(current) {
            int fd = fd_at(current);
            if(fd < 0) {
                return EXIT_FAILURE;
            }
            FD_SET(fd, &fdset);
            current = linked_fd_next(current);
        }

        // Select on every fd in the fdset.
        int x = select(highest_fd + 1, &fdset, NULL, NULL, NULL);
        if(x < 0) {
            return EXIT_FAILURE;
        }

        // If we got something on stdin, close all sockets
        // And exit.
        if(FD_ISSET(STDIN_FILENO, &fdset)) {
            printf("Closing all sockets.\n");
            close(listen_sock);
            close_all(fdlist);
        }

        // If the listen_sock is 'ready', accept a socket and
        // add it to our fd list.
        if(FD_ISSET(listen_sock, &fdset)) {
            accept_sock(listen_sock, fdlist);
        }

        //Handle other fds.
        current = linked_fd_head(fdlist);
        while(current) {
            int fd = fd_at(current);
            // This should never happen. Just precautionary.
            if(fd < 0) {
                return EXIT_FAILURE;
            }
            if(FD_ISSET(fd, &fdset)) {
                do_echo(fd, fdlist);
            }
            current = linked_fd_next(current);
        }
        
    } while(1);
}
// close out after Load clicked: load noise(s)
void US_NoiseLoader::selected()
{
   bool isDB = ( db != (US_DB2*)0 );  // flag DB or Local
   int  nti  = 0;
   int  nri  = 0;
   US_Noise t2_noise;

   for ( int ii = 0; ii < lw_selects->count(); ii++ )
   {  // browse select list
      QString selntext = lw_selects->item( ii )->text();
      QString snumtext = selntext.section( " ", 1, 1 );
      QString styptext = selntext.left( 2 );
      QString noisGUID = "";

      for ( int jj = 0; jj < nieGUIDs.size(); jj++ )
      {  // examine noises-in-edit list
         QString nie   = nieGUIDs.at( jj );
         QString typ   = nie.section( ":", 1, 1 );
         QString mdx   = nie.section( ":", 2, 2 );

         if ( typ == styptext  &&   mdx == snumtext )
         {  // found the selected noise: break with its GUID
            noisGUID      = nie.section( ":", 0, 0 );
            break;
         }
      }

      if ( styptext == "ti" )
      {
         if ( nti == 0 )
            ti_noise.load( isDB, noisGUID, db );    // load ti noise

         else
         {
            t2_noise.load( isDB, noisGUID, db );
            ti_noise.sum_noise( t2_noise, true );   // sum multiple ti noises
         }

         nti++;
      }

      else
      {
         if ( nri == 0 )
            ri_noise.load( isDB, noisGUID, db );    // load ri noise

         else
         {
            t2_noise.load( isDB, noisGUID, db );
            ri_noise.sum_noise( t2_noise, true );   // sum multiple ri noises
         }

         nri++;
      }
   }

   // Verify that noise(s) values not beyond reasonable data range
   if ( darange > 0.0 )
   {
      int nurnois    = 0;

      if ( nti > 0 )
      {
         double noimin  = ti_noise.values[ 0 ];
         double noimax  = noimin;

         for ( int ii = 0; ii < ti_noise.values.size(); ii++ )
         {
            double noival  = ti_noise.values[ ii ];
            noimin         = qMin( noimin, noival );
            noimax         = qMax( noimax, noival );
         }

         if ( ( noimax - noimin ) > darange )  nurnois++;
      }

      if ( nri > 0 )
      {
         double noimin  = ri_noise.values[ 0 ];
         double noimax  = noimin;

         for ( int ii = 0; ii < ri_noise.values.size(); ii++ )
         {
            double noival  = ri_noise.values[ ii ];
            noimin         = qMin( noimin, noival );
            noimax         = qMax( noimax, noival );
         }

         if ( ( noimax - noimin ) > darange )  nurnois++;
      }

      if ( nurnois > 0 )
      {
         QString msg = tr(
            "Noise values exceed the range of experimental data.<br/>"
            "Do you still want to honor the current noise selection(s)?<br/>"
            "<ul><li><b>Yes</b> to proceed, anyway, with selected noise;</li>"
            "<li><b>No </b> to retry with a new noise selection></li></ul>" );
         QMessageBox msgBox     ( this );
         msgBox.setWindowTitle  ( tr( "Noise Value Problems" ) );
         msgBox.setTextFormat   ( Qt::RichText );
         msgBox.setText         ( msg );
         msgBox.addButton       ( QMessageBox::No  );
         msgBox.addButton       ( QMessageBox::Yes );
         msgBox.setDefaultButton( QMessageBox::Yes );

         if ( msgBox.exec() == QMessageBox::No )
         {
            ti_noise.values.clear();
            ri_noise.values.clear();
            return;
         }
      }
   }

   close_all();
}
Exemple #16
0
int main(int argc, char *argv[])
{
    int found = UNKNOWN;
    int i = 0;
    int id;
    int failed = 0;
    char *text_string;
    char *prefix_string;
    char *trail_string;
    char *text_string_orig;

    if (argc != 2) {
        return 1;
    }

    infile = fopen(argv[1], "rb");
    if (infile == NULL) {
        close_all();
        return 1;
    }

    for (i = 0; files[i].filename != NULL; i++) {
        files[i].filehandle = fopen(files[i].filename, "wb");
        if (files[i].filehandle == NULL) {
            failed = 1;
        }
    }

    if (failed == 1) {
        close_all();
        return 1;
    }

    while (found != FOUND_STRINGTABLE && found != FOUND_EOF) {
        found = genrc_getline(infile);
        if (found != FOUND_EOF) {
            fwrite(line_buffer, 1, strlen(line_buffer), files[0].filehandle);
        }
    }
    if (found != FOUND_EOF) {
        for (i = 1; files[i].filename != NULL; i++) {
            fprintf(files[i].filehandle, "%s\n\n", files[i].title);
            if (files[i].pragma != NULL) {
                fprintf(files[i].filehandle, "#ifndef WINDRES_CP_IGNORE\n");
                fprintf(files[i].filehandle, "#pragma code_page(%s)\n", files[i].pragma);
                fprintf(files[i].filehandle, "#endif\n");
            }
            fprintf(files[i].filehandle, "STRINGTABLE\n");
            fprintf(files[i].filehandle, "LANGUAGE %s, %s\n", files[i].lang, files[i].sublang);
            fprintf(files[i].filehandle, "BEGIN\n");
        }
        while (found != FOUND_BEGIN) {
            found = genrc_getline(infile);
            fwrite(line_buffer, 1, strlen(line_buffer), files[0].filehandle);
        }
        found = genrc_getline(infile);
        while (found != FOUND_END) {
            if (found == FOUND_IFDEF || found == FOUND_ENDIF || found == FOUND_ELSE) {
                for (i = 0; files[i].filename != NULL; i++) {
                    fwrite(line_buffer, 1, strlen(line_buffer), files[i].filehandle);
                }
            } else {
                i = 0;
                while (line_buffer[i] != '"') {
                    i++;
                }
                line_buffer[i++] = 0;
                text_string = line_buffer + i;
                i += strlen(text_string);
                while (line_buffer[i] != '"') {
                    i--;
                }
                line_buffer[i] = 0;
                fprintf(files[0].filehandle, "%s\"", line_buffer);
                write_converted_text(text_string, files[0].filehandle, NULL, NULL);
                fprintf(files[0].filehandle, "\"\n");

                text_string_orig = strdup(text_string);

                prefix_string = prefix_test(text_string);
                trail_string = trailtest(text_string);

                for (id = 0; text[id].msgid != NULL; id++) {
                    if (!strcmp(text[id].msgid, text_string)) {
                        break;
                    }
                    if (!strcmp(text[id].msgid, text_string_orig)) {
                        prefix_string = NULL;
                        trail_string = NULL;
                        break;
                    }
                }
                for (i = 1; files[i].filename != NULL; i++) {
                    fprintf(files[i].filehandle, "%s\"", line_buffer);
                    switch (i) {
                        case 1:
                            if (strlen(text[id].msgstr_da) != 0) {
                                write_converted_text(text[id].msgstr_da, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 2:
                            if (strlen(text[id].msgstr_de) != 0) {
                                write_converted_text(text[id].msgstr_de, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 3:
                            if (strlen(text[id].msgstr_es) != 0) {
                                write_converted_text(text[id].msgstr_es, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 4:
                            if (strlen(text[id].msgstr_fr) != 0) {
                                write_converted_text(text[id].msgstr_fr, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 5:
                            if (strlen(text[id].msgstr_hu) != 0) {
                                write_converted_text(text[id].msgstr_hu, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 6:
                            if (strlen(text[id].msgstr_it) != 0) {
                                write_converted_text(text[id].msgstr_it, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 7:
                            if (strlen(text[id].msgstr_ko) != 0) {
                                write_converted_text(text[id].msgstr_ko, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 8:
                            if (strlen(text[id].msgstr_nl) != 0) {
                                write_converted_text(text[id].msgstr_nl, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 9:
                            if (strlen(text[id].msgstr_pl) != 0) {
                                write_converted_text(text[id].msgstr_pl, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 10:
                            if (strlen(text[id].msgstr_ru) != 0) {
                                write_converted_text(text[id].msgstr_ru, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 11:
                            if (strlen(text[id].msgstr_sv) != 0) {
                                write_converted_text(text[id].msgstr_sv, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                        case 12:
                            if (strlen(text[id].msgstr_tr) != 0) {
                                write_converted_text(text[id].msgstr_tr, files[i].filehandle, prefix_string, trail_string);
                            } else {
                                write_converted_text(text_string, files[i].filehandle, prefix_string, trail_string);
                            }
                            break;
                    }
                    fprintf(files[i].filehandle, "\"\n");
                }
                free(text_string_orig);
            }
            found = genrc_getline(infile);
        }
        for (i = 0; files[i].filename != NULL; i++) {
            fprintf(files[i].filehandle, "END\n");
            if (files[i].pragma != NULL) {
                fprintf(files[i].filehandle, "#ifndef WINDRES_CP_IGNORE\n");
                fprintf(files[i].filehandle, "#pragma code_page(28591)\n");
                fprintf(files[i].filehandle, "#endif\n");
            }
            fprintf(files[i].filehandle, "\n\n");
        }
    }
    close_all();
    return 0;
}
Exemple #17
0
leave()
{
  close_all();
  execlp("operm", "operm", 0);
  krash("leave", "operm load", 1);
}
Exemple #18
0
/*-------------------------------------------------------------------------*
 *  Graceful Exit
 *-------------------------------------------------------------------------*/
long leave()
{
  close_all();
  execlp("pfead", "pfead", 0);
  krash("leave", "pfead load", 0);
}
int main(int argc, char *argv[])
{
    int found = UNKNOWN;
    int i;
    int id_start;
    int text_start;
    char *id_string;
    char *text_string;
    char *prefix_string;
    char *trail_string;
    char *text_string_orig;

    infile = fopen("../src/arch/amigaos/intl_text.c", "rb");
    if (infile == NULL) {
        close_all();
        return 1;
    }

    outfile = fopen("../src/arch/amigaos/temp_intl.h", "wb");
    if (outfile == NULL) {
        close_all();
        return 1;
    }

    fprintf(outfile, "/*\n");
    fprintf(outfile, " * intl_text.c - Translation texts to be included in intl.c\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " * Written by\n");
    fprintf(outfile, " *  Marco van den Heuvel <*****@*****.**>\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " * This file is part of VICE, the Versatile Commodore Emulator.\n");
    fprintf(outfile, " * See README for copyright notice.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " *  This program is free software; you can redistribute it and/or modify\n");
    fprintf(outfile, " *  it under the terms of the GNU General Public License as published by\n");
    fprintf(outfile, " *  the Free Software Foundation; either version 2 of the License, or\n");
    fprintf(outfile, " *  (at your option) any later version.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " *  This program is distributed in the hope that it will be useful,\n");
    fprintf(outfile, " *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
    fprintf(outfile, " *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
    fprintf(outfile, " *  GNU General Public License for more details.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " *  You should have received a copy of the GNU General Public License\n");
    fprintf(outfile, " *  along with this program; if not, write to the Free Software\n");
    fprintf(outfile, " *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n");
    fprintf(outfile, " *  02111-1307  USA.\n");
    fprintf(outfile, " *\n");
    fprintf(outfile, " */\n\n");
    fprintf(outfile, "intl_translate_t intl_string_table[] = {\n\n");

    while (found != FOUND_EMPTY_LINE) {
        found = genintl_getline(infile);
    }
    found = genintl_getline(infile);
    found = genintl_getline(infile);
    while (found != FOUND_END_OF_TABLE) {
        found = UNKNOWN;
        while (found != FOUND_EN && found != FOUND_END_OF_TABLE) {
            fwrite(line_buffer, 1, strlen(line_buffer), outfile);
            found = genintl_getline(infile);
        }
        if (found != FOUND_END_OF_TABLE) {
            i = 0;
            while (line_buffer[i] != '{') {
                i++;
            }
            id_start = i + 1;
            while (line_buffer[i] != ',') {
                i++;
            }
            line_buffer[i] = 0;
            while (line_buffer[i] != '"') {
                i++;
            }
            i++;
            text_start = i;
            while (!(line_buffer[i] == '"' && line_buffer[i + 1] == ' ' && line_buffer[i + 2] == '}' && line_buffer[i + 3] == ',')) {
                i++;
            }
            line_buffer[i] = 0;
            id_string = strdup(line_buffer + id_start);
            text_string = strdup(line_buffer + text_start);
            fprintf(outfile, "/* en */ {%s,    \"", line_buffer + id_start);
            write_converted_text(text_string, NULL, NULL);
            fprintf(outfile, "\" },\n/* da */ {%s_DA, \"", id_string);

            text_string_orig = strdup(text_string);

            prefix_string = prefix_test(text_string);
            trail_string = trailtest(text_string);

            for (i = 0; text[i].msgid != NULL; i++) {
                if (!strcmp(text[i].msgid, text_string)) {
                    break;
                }
                if (!strcmp(text[i].msgid, text_string_orig)) {
                    prefix_string = NULL;
                    trail_string = NULL;
                    break;
                }
            }
            if (strlen(text[i].msgstr_da) != 0) {
                write_converted_text(text[i].msgstr_da, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_da) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* de */ {%s_DE, \"", id_string);

            if (strlen(text[i].msgstr_de) != 0) {
                write_converted_text(text[i].msgstr_de, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_de) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* fr */ {%s_FR, \"", id_string);

            if (strlen(text[i].msgstr_fr) != 0) {
                write_converted_text(text[i].msgstr_fr, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_fr) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* hu */ {%s_HU, \"", id_string);

            if (strlen(text[i].msgstr_hu) != 0) {
                write_converted_text(text[i].msgstr_hu, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_hu) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* it */ {%s_IT, \"", id_string);

            if (strlen(text[i].msgstr_it) != 0) {
                write_converted_text(text[i].msgstr_it, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_it) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* ko */ {%s_KO, \"", id_string);

            if (strlen(text[i].msgstr_ko) != 0) {
                write_converted_text(text[i].msgstr_ko, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_ko) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* nl */ {%s_NL, \"", id_string);

            if (strlen(text[i].msgstr_nl) != 0) {
                write_converted_text(text[i].msgstr_nl, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_nl) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* ru */ {%s_RU, \"", id_string);

            if (strlen(text[i].msgstr_ru) != 0) {
                write_converted_text(text[i].msgstr_ru, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_ru) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* sv */ {%s_SV, \"", id_string);

            if (strlen(text[i].msgstr_sv) != 0) {
                write_converted_text(text[i].msgstr_sv, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_sv) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n/* tr */ {%s_TR, \"", id_string);

            if (strlen(text[i].msgstr_tr) != 0) {
                write_converted_text(text[i].msgstr_tr, prefix_string, trail_string);
            }
            fprintf(outfile, "\" },");
            if (strlen(text[i].msgstr_tr) == 0) {
                fprintf(outfile, "  /* fuzzy */");
            }
            fprintf(outfile, "\n");
            while (found != FOUND_EMPTY_LINE) {
                found = genintl_getline(infile);
            }
            free(id_string);
            free(text_string);
            free(text_string_orig);
        }
    }
    fprintf(outfile, "};\n");
    close_all();
    return 0;
}
Exemple #20
0
main()
{
  unsigned char t;
  
  putenv("_=pff_inquiry_input");
  chdir(getenv("HOME"));
  
  open_all();                             /* open ss, eh, co                 */

  /* initialize and show screen display */

  fix(pff_inquiry_input);
  sd_screen_off();
  sd_clear_screen();                      /* clear entire screen             */
  sd_text(pff_inquiry_input);
  sd_screen_on();
  
  sd_cursor(0, 6, 10);
  sd_text("F = Family Group                       L = CAPS Stock Location");
  sd_cursor(0, 7, 10);
  sd_text("P = Pick Module Number                 S = SKU");

  while(1)
  {
    memset(buf, 0, NUM_PROMPTS * BUF_SIZE); /* clear buffers                 */

    get_parms();                            /* get all parmeters             */

    sd_prompt(&fld[4], 0);
    memset(yn0, 0, 2);
    
    while(1)
    {
      t = sd_input(&fld[4], 0, 0, yn0, 0);
      if (t == EXIT) leave();
      
      *buf[4] = code_to_caps(*yn0);

      if (*buf[4] == 'y')
      {
        sd_wait();
        close_all();
        execlp("pff_inquiry_create", "pff_inquiry_create",
                buf[0], buf[1], sort_buf, rng_buf[0], rng_buf[1],
                "", "print", 0);

        krash("main", "pff_inquiry_create load", 1);
      }
      else if (*buf[4] == 'n')
      {
        sd_wait();
        close_all();
        execlp("pff_inquiry_create","pff_inquiry_create",
                buf[0], buf[1], sort_buf, rng_buf[0], rng_buf[1],
                "", "report", 0);

        krash("main", "pff_inquiry_create load", 1);
      }
      eh_post(ERR_YN,0);
    }
  }
}
int main (int argc, char *argv[]) {
	const char *options = "VHaslpmfe:v:hin:o:";
	char *endptr;
	int opt;
	int votes = 0;
	int ret = 0;
	uint32_t nodeid = 0;
	uint32_t nodeid_set = 0;
	nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL;
	name_format_t address_format = ADDRESS_FORMAT_NAME;
	command_t command_opt = CMD_SHOWSTATUS;
	sorttype_t sort_opt = SORT_ADDR;
	char sortchar;
	long int l;

	if (init_all()) {
		close_all();
		exit(1);
	}

	while ( (opt = getopt(argc, argv, options)) != -1 ) {
		switch (opt) {
		case 'f':
			if (using_votequorum() > 0) {
				command_opt = CMD_UNREGISTER_QDEVICE;
			} else {
				fprintf(stderr, "You cannot unregister quorum device, corosync is not using votequorum\n");
				exit(2);
			}
			break;
		case 's':
			command_opt = CMD_SHOWSTATUS;
			break;
		case 'a':
			g_show_all_addrs = 1;
			break;
		case 'm':
			command_opt = CMD_MONITOR;
			break;
		case 'i':
			address_format = ADDRESS_FORMAT_IP;
			break;
		case 'H':
			nodeid_format = NODEID_FORMAT_HEX;
			break;
		case 'l':
			command_opt = CMD_SHOWNODES;
			break;
		case 'p':
			machine_parsable = 1;
			break;
		case 'e':
			if (using_votequorum() > 0) {
				votes = strtol(optarg, &endptr, 0);
				if ((votes == 0 && endptr == optarg) || votes <= 0) {
					fprintf(stderr, "New expected votes value was not valid, try a positive number\n");
				} else {
					command_opt = CMD_SETEXPECTED;
				}
			} else {
				fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n");
				exit(2);
			}
			break;
		case 'n':
			l = strtol(optarg, &endptr, 0);
			if ((l == 0 && endptr == optarg) || l < 0) {
				fprintf(stderr, "The nodeid was not valid, try a positive number\n");
				exit(2);
			}
			nodeid = l;
			nodeid_set = 1;
			break;
		case 'v':
			if (using_votequorum() > 0) {
				votes = strtol(optarg, &endptr, 0);
				if ((votes == 0 && endptr == optarg) || votes < 0) {
					fprintf(stderr, "New votes value was not valid, try a positive number or zero\n");
					exit(2);
				} else {
					command_opt = CMD_SETVOTES;
				}
			}
			else {
				fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n");
				exit(2);
			}
			break;
		case 'o':
			sortchar = optarg[0];
			switch (sortchar) {
			        case 'a': sort_opt = SORT_ADDR;
					break;
			        case 'i': sort_opt = SORT_NODEID;
					break;
			        case 'n': sort_opt = SORT_NODENAME;
					break;
			        default:
					fprintf(stderr, "Invalid ordering option. valid orders are a(address), i(node ID) or n(name)\n");
					exit(2);
					break;
			}
			break;
		case 'V':
			printf("corosync-quorumtool version: %s\n", VERSION);
			exit(0);
		case ':':
		case 'h':
		case '?':
		default:
			command_opt = CMD_UNKNOWN;
			break;
		}
	}

	switch (command_opt) {
	case CMD_UNKNOWN:
		show_usage(argv[0]);
		ret = -1;
		break;
	case CMD_SHOWNODES:
		ret = show_nodes(nodeid_format, address_format, sort_opt);
		break;
	case CMD_SHOWSTATUS:
		ret = show_status(nodeid_format, address_format, sort_opt);
		break;
	case CMD_SETVOTES:
		if (!nodeid_set) {
			nodeid = our_nodeid;
		}
		ret = set_votes(nodeid, votes);
		break;
	case CMD_SETEXPECTED:
		ret = set_expected(votes);
		break;
	case CMD_MONITOR:
		ret = monitor_status(nodeid_format, address_format, sort_opt);
		break;
	case CMD_UNREGISTER_QDEVICE:
		ret = unregister_qdevice();
		break;
	}

	close_all();

	return (ret);
}
Exemple #22
0
void shutdown(int a) 
{
	close_all();
	exit(0);
}
Exemple #23
0
void
exit(int retcode)
{
	close_all();
	sys_env_destroy(0, retcode);
}
Exemple #24
0
void
exit(void)
{
  close_all();
  sys_env_destroy(0);
}
Exemple #25
0
void
runcmd(char* s)
{
	char *argv[MAXARGS], *t, argv0buf[BUFSIZ];
	int argc, c, i, r, p[2], fd, pipe_child;

	pipe_child = 0;
	gettoken(s, 0);
	
again:
	argc = 0;
	while (1) {
		switch ((c = gettoken(0, &t))) {

		case 'w':	// Add an argument
			if (argc == MAXARGS) {
				cprintf("too many arguments\n");
				exit();
			}
			argv[argc++] = t;
			break;
			
		case '<':	// Input redirection
			// Grab the filename from the argument list
			if (gettoken(0, &t) != 'w') {
				cprintf("syntax error: < not followed by word\n");
				exit();
			}
			// Open 't' for reading as file descriptor 0
			// (which environments use as standard input).
			// We can't open a file onto a particular descriptor,
			// so open the file as 'fd',
			// then check whether 'fd' is 0.
			// If not, dup 'fd' onto file descriptor 0,
			// then close the original 'fd'.
			
			// LAB 5: Your code here.
			
                        if((fd = open(t, O_RDONLY)) < 0) {
                            cprintf("file could not be opened: %s\n", t);
                            exit();
                        }
                        if(fd!=0) {
                            if (dup(fd, 0) < 0) {
                                cprintf("dup failed\n");
                                close(fd);
                                exit();
                            }
                            close(fd);
                        }   
			break;
			
		case '>':	// Output redirection
			// Grab the filename from the argument list
			if (gettoken(0, &t) != 'w') {
				cprintf("syntax error: > not followed by word\n");
				exit();
			}
			// Open 't' for writing as file descriptor 1
			// (which environments use as standard output).
			// We can't open a file onto a particular descriptor,
			// so open the file as 'fd',
			// then check whether 'fd' is 1.
			// If not, dup 'fd' onto file descriptor 1,
			// then close the original 'fd'.
			
			// LAB 5: Your code here.
			
                        if((fd = open(t, O_WRONLY | O_CREAT | O_TRUNC)) < 0) {
                            cprintf("file could not be opened: %s\n", t);
                            exit();
                        }
                        if(fd!=1) {
                            if (dup(fd, 1) < 0) {
                                cprintf("dup failed\n");
                                close(fd);
                                exit();
                            }
                            close(fd);
                        }   
			break;
			
		case '|':	// Pipe
			// Set up pipe redirection.
			
			// Allocate a pipe by calling 'pipe(p)'.
			// Like the Unix version of pipe() (man 2 pipe),
			// this function allocates two file descriptors;
			// data written onto 'p[1]' can be read from 'p[0]'.
			// Then fork.
			// The child runs the right side of the pipe:
			//	Use dup() to duplicate the read end of the pipe
			//	(p[0]) onto file descriptor 0 (standard input).
			//	Then close the pipe (both p[0] and p[1]).
			//	(The read end will still be open, as file
			//	descriptor 0.)
			//	Then 'goto again', to parse the rest of the
			//	command line as a new command.
			// The parent runs the left side of the pipe:
			//	Set 'pipe_child' to the child env ID.
			//	dup() the write end of the pipe onto
			//	file descriptor 1 (standard output).
			//	Then close the pipe.
			//	Then 'goto runit', to execute this piece of
			//	the pipeline.

			// LAB 5: Your code here.
                        
                        if (pipe(p) < 0) {
                            cprintf("pipe failed\n");
                            exit();
                        }
                        if ((r = fork()) < 0) {
                            cprintf("fork failed\n");
                            close(p[0]);
                            close(p[1]);
                            exit();
                        }
                        if(r == 0) {
                            if (dup(p[0], 0) < 0) {
                                cprintf("dup failed\n");
                                exit();
                            }
                            close(p[0]);
                            close(p[1]);
                            goto again;
                        }else {
                            pipe_child = r;
                            if (dup(p[1], 1) < 0) {
                                cprintf("dup failed\n");
                                exit();
                            }
                            close(p[0]);
                            close(p[1]);
                            goto runit;
                        }                    
			break;

		case 0:		// String is complete
			// Run the current command!
			goto runit;
			
		default:
			panic("bad return %d from gettoken", c);
			break;
			
		}
	}

runit:
	// Return immediately if command line was empty.
	if(argc == 0) {
		if (debug)
			cprintf("EMPTY COMMAND\n");
		return;
	}

	// Clean up command line.
	// Read all commands from the filesystem: add an initial '/' to
	// the command name.
	// This essentially acts like 'PATH=/'.
	if (argv[0][0] != '/') {
		argv0buf[0] = '/';
		strcpy(argv0buf + 1, argv[0]);
		argv[0] = argv0buf;
	}
	argv[argc] = 0;
	
	// Print the command.
	if (debug) {
		cprintf("[%08x] SPAWN:", env->env_id);
		for (i = 0; argv[i]; i++)
			cprintf(" %s", argv[i]);
		cprintf("\n");
	}

	// Spawn the command!
	if ((r = spawn(argv0buf, (const char**) argv)) < 0)
		cprintf("spawn %s: %e\n", argv[0], r);

	// In the parent, close all file descriptors and wait for the
	// spawned command to exit.
	close_all();
	if (r >= 0) {
		if (debug)
			cprintf("[%08x] WAIT %s %08x\n", env->env_id, argv[0], r);
		wait(r);
		if (debug)
			cprintf("[%08x] wait finished\n", env->env_id);
	}

	// If we were the left-hand part of a pipe,
	// wait for the right-hand part to finish.
	if (pipe_child) {
		if (debug)
			cprintf("[%08x] WAIT pipe_child %08x\n", env->env_id, pipe_child);
		wait(pipe_child);
		if (debug)
			cprintf("[%08x] wait finished\n", env->env_id);
	}

	// Done!
	exit();
}
Exemple #26
0
main()
{
    FILE *td;
    char kernel_check[12],
         command[80],
         tmpname[16];

    memset(kernel_check, 0x0, 12);
    memset(command, 0x0, 80);
    memset(tmpname, 0x0, 16);

    putenv("_=check_caps");                  /* name to environ   */
    chdir(getenv("HOME"));                  /* to home directory  */

    tmp_name(tmpname);
    sprintf(command, "%s > %s",
            "ps -ef|grep -v grep|grep ' bin/kernel'|cut -c54-63",
            tmpname);
    system(command);

    td = fopen(tmpname, "r");
    if (td == 0)
    {
        exit(-1);
    }

    fgets(kernel_check, 11, td);

    if (td)
    {
        fclose(td);
        unlink(tmpname);
    }

    if (strcmp(kernel_check, KERNELNAME) != 0)
    {
        printf("System not started\n");
        exit(4);
    }

    ss_open();

    if (sp->sp_running_status == 'n')
    {
        printf("Markplace\n");
        close_all();
        exit(3);
    }
    else
    {
        if (sp->sp_in_process_status != 'x')
        {
            printf("System is Busy\n");
            close_all();
            exit(1);
        }
        else
        {
            if (sp->sp_config_status == 'y')
            {
                printf("System is running\n");
                close_all();
                exit(2);
            }
        }
    }

    close_all();

    exit(0);
} /* end of main() */
Exemple #27
0
SqlPool::~SqlPool()
{
    stop_monitor_thread();
    monitor_.wait();
    close_all();
}
Exemple #28
0
void socket_close_all()
{
    close_all(clients);
    close_all(servers);
}
Exemple #29
0
void
runcmd(char* s)
{
	char *argv[MAXARGS], *t, argv0buf[BUFSIZ];
	int argc, c, i, r, p[2], fd, pipe_child;

	pipe_child = 0;
	gettoken(s, 0);
	
again:
	argc = 0;
	while (1) {
		switch ((c = gettoken(0, &t))) {

		case 'w':	// Add an argument
			if (argc == MAXARGS) {
				cprintf("too many arguments\n");
				exit();
			}
			argv[argc++] = t;
			break;
			
		case '<':	// Input redirection
			// Grab the filename from the argument list
			if (gettoken(0, &t) != 'w') {
				cprintf("syntax error: < not followed by word\n");
				exit();
			}
			if ((fd = open(t, O_RDONLY)) < 0) {
				cprintf("open %s for read: %e", t, fd);
				exit();
			}
			if (fd != 0) {
				dup(fd, 0);
				close(fd);
			}
			break;
			
		case '>':	// Output redirection
			// Grab the filename from the argument list
			if (gettoken(0, &t) != 'w') {
				cprintf("syntax error: > not followed by word\n");
				exit();
			}
			if ((fd = open(t, O_WRONLY|O_CREAT|O_TRUNC)) < 0) {
				cprintf("open %s for write: %e", t, fd);
				exit();
			}
			if (fd != 1) {
				dup(fd, 1);
				close(fd);
			}
			break;
			
		case '|':	// Pipe
			if ((r = pipe(p)) < 0) {
				cprintf("pipe: %e", r);
				exit();
			}
			if (debug)
				cprintf("PIPE: %d %d\n", p[0], p[1]);
			if ((r = fork()) < 0) {
				cprintf("fork: %e", r);
				exit();
			}
			if (r == 0) {
				if (p[0] != 0) {
					dup(p[0], 0);
					close(p[0]);
				}
				close(p[1]);
				goto again;
			} else {
				pipe_child = r;
				if (p[1] != 1) {
					dup(p[1], 1);
					close(p[1]);
				}
				close(p[0]);
				goto runit;
			}
			panic("| not implemented");
			break;

		case 0:		// String is complete
			// Run the current command!
			goto runit;
			
		default:
			panic("bad return %d from gettoken", c);
			break;
			
		}
	}

runit:
	// Return immediately if command line was empty.
	if(argc == 0) {
		if (debug)
			cprintf("EMPTY COMMAND\n");
		return;
	}

	// Clean up command line.
	// Read all commands from the filesystem: add an initial '/' to
	// the command name.
	// This essentially acts like 'PATH=/'.
	if (argv[0][0] != '/') {
		argv0buf[0] = '/';
		strcpy(argv0buf + 1, argv[0]);
		argv[0] = argv0buf;
	}
	argv[argc] = 0;
	
	// Print the command.
	if (debug) {
		cprintf("[%08x] SPAWN:", env->env_id);
		for (i = 0; argv[i]; i++)
			cprintf(" %s", argv[i]);
		cprintf("\n");
	}

	// Spawn the command!
	if ((r = spawn(argv[0], (const char**) argv)) < 0)
		cprintf("spawn %s: %e\n", argv[0], r);

	// In the parent, close all file descriptors and wait for the
	// spawned command to exit.
	close_all();
	if (r >= 0) {
		if (debug)
			cprintf("[%08x] WAIT %s %08x\n", env->env_id, argv[0], r);
		wait(r);
		if (debug)
			cprintf("[%08x] wait finished\n", env->env_id);
	}

	// If we were the left-hand part of a pipe,
	// wait for the right-hand part to finish.
	if (pipe_child) {
		if (debug)
			cprintf("[%08x] WAIT pipe_child %08x\n", env->env_id, pipe_child);
		wait(pipe_child);
		if (debug)
			cprintf("[%08x] wait finished\n", env->env_id);
	}

	// Done!
	exit();
}
Exemple #30
0
leave()
{
  close_all();
  execlp("picker_acctability","picker_acctability",0);
  krash("leave", "picker_acctability load", 1);
}