Exemplo n.º 1
0
int main (int argc, char *argv[])
{
  char buff[1024];
  char *s;
  
  struct sig **lastsig = NULL;
  struct uid **lastuid = NULL;
  struct key *k = new_key();
  
  lastuid = &k->uids;

  if (argc == 2 && !strcmp (argv[1], "-S"))
    DontRequireSelfSig = 1;

  while (fgets (buff, sizeof (buff), stdin))
  {
    if ((s = strtok (buff, ":")))
    {
      if (!strcmp (s, "pub"))
      {
	do_key (k);
	k->rev = 0;
	k->uids = new_uid();

	lastuid = &k->uids->next;
	lastsig = &k->uids->sigs;

	strtok (NULL, ":");
	strtok (NULL, ":");
	strtok (NULL, ":");

	sprintf (k->id, "%s", strtok (NULL, ":"));
      }
      else if (!strcmp (s, "rev"))
	k->rev = 1;
      else if (!strcmp (s, "uid"))
      {
	struct uid *uid = *lastuid = new_uid();
	lastuid = &(*lastuid)->next;
	lastsig = &uid->sigs;
      }
      else if (!strcmp (s, "sig"))
      {
	struct sig *sig = *lastsig = new_sig();
	lastsig = &sig->next;
	sprintf (sig->id, "%s", strtok (NULL, ":"));
      }
    }
  }
  
  do_key (k);
  
  return 0;
}
Exemplo n.º 2
0
int dispatch_cmd(otts_synth_plugin_t *synth, char *cmd_line)
{
	char *cmd = NULL;
	size_t cmd_len;
	char *msg = NULL;

	cmd_len = strcspn(cmd_line, " \t\n\r\f");
	cmd = g_strndup(cmd_line, cmd_len);
	pthread_mutex_lock(&module_stdout_mutex);

	if (!strcasecmp("audio", cmd)) {
		msg = do_audio(synth);
	} else if (!strcasecmp("set", cmd)) {
		msg = do_set(synth);
	} else if (!strcasecmp("speak", cmd)) {
		msg = do_speak(synth);
	} else if (!strcasecmp("key", cmd)) {
		msg = do_key(synth);
	} else if (!strcasecmp("sound_icon", cmd)) {
		msg = do_sound_icon(synth);
	} else if (!strcasecmp("char", cmd)) {
		msg = do_char(synth);
	} else if (!strcasecmp("pause", cmd)) {
		do_pause(synth);
	} else if (!strcasecmp("stop", cmd)) {
		do_stop(synth);
	} else if (!strcasecmp("list_voices", cmd)) {
		msg = do_list_voices(synth);
	} else if (!strcasecmp("loglevel", cmd)) {
		msg = do_loglevel(synth);
	} else if (!strcasecmp("debug", cmd)) {
		msg = do_debug(synth, cmd_line);
	} else if (!strcasecmp("quit", cmd)) {
		do_quit(synth);
	} else {
/*should we log?*/
		printf("300 ERR UNKNOWN COMMAND\n");
		fflush(stdout);
	}

	if (msg != NULL) {
		if (0 > printf("%s\n", msg)) {
			log_msg(OTTS_LOG_CRIT, "Broken pipe, exiting...\n");
			synth->close(2);
		}
		fflush(stdout);
		g_free(msg);
	}

	pthread_mutex_unlock(&module_stdout_mutex);
	g_free(cmd);

	return (0);
}
Exemplo n.º 3
0
static int	fractol_core(t_fol *f)
{
	do_key(f);
	if (out_limits(f))
		exit(0);
	f->step = 1 / f->zoom;
	f->def_min.x = -f->mid.x / f->zoom;
	f->def_min.y = -f->mid.y / f->zoom;
	f->def_max.x = (WIN_H - f->mid.x) / f->zoom;
	f->def_max.y = (WIN_W - f->mid.y) / f->zoom;
	print_rules(f);
	print_param(f);
	if (f->type == 'j')
		julia(f);
	else if (f->type == 'b')
		buddha(f);
	else if (f->type == 'B')
		buddha2(f);
	else
		mandelbrot(f);
	mlx_put_image_to_window(f->mlx, f->win, f->im, 0, 0);
	return (1);
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    /* For select(2). */
    struct timeval tv;
    fd_set in;
    /* For parsing arguments. */
    char *cp;
    /* The key read in. */
    char c;

    struct sigaction sact;

    setlocale(LC_ALL, "");
    get_options();
    
    /* set to PCPU sorting */
    register_sort_function( -1, (cmp_t)pcpu_sort);
    
#ifdef HZ
    Hertz = HZ;
#endif

    /*
     * Parse arguments.
     */
    argv++;
    while (*argv) {
	cp = *argv++;
	while (*cp) {
	    switch (*cp) {
	      case 'd':
	        if (cp[1]) {
		    if (sscanf(++cp, "%f", &Sleeptime) != 1) {
			fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
			exit(1);
		    }
		    goto breakargv;
		} else if (*argv) { /* last char in an argv, use next as arg */
		    if (sscanf(cp = *argv++, "%f", &Sleeptime) != 1) {
			fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
			exit(1);
		    }
		    goto breakargv;
		} else {
		    fprintf(stderr, "-d requires an argument\n");
		    exit(1);
		}
		break;
	      case 'n':
		if (cp[1]) {
	   	    if (sscanf(++cp, "%d", &Loops) != 1) {
			fprintf(stderr, PROGNAME ": Bad value `%s'\n", cp);
			exit(1);
		    }
		    goto breakargv;
		} else if (*argv) { /* last char in an argv, use next as arg */
		    if (sscanf(cp = *argv++, "%d", &Loops) != 1) {
			fprintf(stderr, PROGNAME ": Bad value `%s'\n", cp);
			 exit(1);
	 	     }
		     goto breakargv;
		}
		break;
					
	      case 'q':
		if (!getuid())
		    /* set priority to -10 in order to stay above kswapd */
		    if (setpriority(PRIO_PROCESS, getpid(), -10)) {
			/* We check this just for paranoia.  It's not
			   fatal, and shouldn't happen. */
			perror(PROGNAME ": setpriority() failed");
		    }
		Sleeptime = 0;
		break;
	      case 'p':
		if (monpids_index >= monpids_max) {
		    fprintf(stderr, PROGNAME ": More than %u process ids specified\n",
			    monpids_max);
		    exit(1);
		}
		if (cp[1]) {
		    if (sscanf(++cp, "%d", &monpids[monpids_index]) != 1 ||
			monpids[monpids_index] < 0 || monpids[monpids_index] > 65535) {
			fprintf(stderr, PROGNAME ": Bad process id `%s'\n", cp);
			exit(1);
		    }
		} else if (*argv) { /* last char in an argv, use next as arg */
		    if (sscanf(cp = *argv++, "%d", &monpids[monpids_index]) != 1 ||
			monpids[monpids_index] < 0 || monpids[monpids_index] > 65535) {
			fprintf(stderr, PROGNAME ": Bad process id `%s'\n", cp);
			exit(1);
		    }
		} else {
		    fprintf(stderr, "-p requires an argument\n");
		    exit(1);
		}
		if (!monpids[monpids_index])
		    monpids[monpids_index] = getpid();
		/* default to no sorting when monitoring process ids */
		if (!monpids_index++) {
		    sort_type = S_NONE;
		    reset_sort_options();
		}
		cp = "_";
		break;
	      case 'b':
		Batch = 1;
	        break;
	      case 'c':
	        show_cmd = !show_cmd;
		break;
	      case 'S':
		Cumulative = 1;
		break;
	      case 'i':
		Noidle = 1;
		break;
	      case 's':
		  Secure = 1;
		  break;
	      case 'C':
		  CPU_states = 1;
		  break;
	      case '-':
		break;		/* Just ignore it */
 	      case 'v':
 	      case 'V':
 		fprintf(stdout, "top (%s)\n", procps_version);
 		exit(0);
	      case 'h':
 		fprintf(stdout, "usage: " PROGNAME " -hvbcisqS -d delay -p pid -n iterations\n");
		exit(0);
	      default:
		fprintf(stderr, PROGNAME ": Unknown argument `%c'\n", *cp);
 		fprintf(stdout, "usage: " PROGNAME " -hvbcisqS -d delay -p pid -n iterations\n");
 	        exit(1);
	    }
	    cp++;
	}
    breakargv:;
    }
    
    if (nr_cpu > 1 && CPU_states)
      header_lines++;

    setup_terminal();
    window_size(0);
    /*
     * Set up signal handlers.
     */
    sact.sa_handler = sig_end;
    sact.sa_flags = 0;
    sigemptyset(&sact.sa_mask);
    sigaction(SIGHUP, &sact, NULL);
    sigaction(SIGINT, &sact, NULL);
    sigaction(SIGQUIT, &sact, NULL);
    sact.sa_handler = sig_stop;
    sact.sa_flags = SA_RESTART;
    sigaction(SIGTSTP, &sact, NULL);
    sact.sa_handler = window_size;
    sigaction(SIGWINCH, &sact, NULL);
    sigaction(SIGCONT, &sact, NULL);

    /* loop, collecting process info and sleeping */
    while (1) {
	if (Loops > 0)
		Loops--;
	/* display the tasks */
	show_procs();
	/* sleep & wait for keyboard input */
	if (Loops == 0)
	    sig_end(0);
        if (!Batch)
        {
		tv.tv_sec = Sleeptime;
		tv.tv_usec = (Sleeptime - (int) Sleeptime) * 1000000;
		FD_ZERO(&in);
		FD_SET(0, &in);
		if (select(1, &in, 0, 0, &tv) > 0 && read(0, &c, 1) == 1)
	    		do_key(c);
        } else {
	   sleep(Sleeptime);
	}
    }
}
Exemplo n.º 5
0
void main()
{   
//    unsigned char i;         
    
    y8 = 1;
    
    reset_game();
    /*
    for (i = 0; i < 40; i++)
        if (minefield[i] == 0)
            drawval(i, count_mines(i));
   */
    
    while(1)
    {
        drawscore();
        readkeyboard(); 
        if (KEYDOWN(1)) do_key(0);
        if (KEYDOWN(2)) do_key(1);
        if (KEYDOWN(3)) do_key(2);
        if (KEYDOWN(4)) do_key(3);
        if (KEYDOWN(5)) do_key(4);
        if (KEYDOWN(6)) do_key(5);
        if (KEYDOWN(7)) do_key(6);
        if (KEYDOWN(8)) do_key(7);
        if (KEYDOWN(9)) do_key(8);
        if (KEYDOWN(0)) do_key(9);
        if (KEYDOWN(Q)) do_key(10);
        if (KEYDOWN(W)) do_key(11);
        if (KEYDOWN(E)) do_key(12);
        if (KEYDOWN(R)) do_key(13);
        if (KEYDOWN(T)) do_key(14);
        if (KEYDOWN(Y)) do_key(15);
        if (KEYDOWN(U)) do_key(16);
        if (KEYDOWN(I)) do_key(17);
        if (KEYDOWN(O)) do_key(18);
        if (KEYDOWN(P)) do_key(19);
        if (KEYDOWN(A)) do_key(20);
        if (KEYDOWN(S)) do_key(21);
        if (KEYDOWN(D)) do_key(22);
        if (KEYDOWN(F)) do_key(23);
        if (KEYDOWN(G)) do_key(24);
        if (KEYDOWN(H)) do_key(25);
        if (KEYDOWN(J)) do_key(26);
        if (KEYDOWN(K)) do_key(27);
        if (KEYDOWN(L)) do_key(28);
        if (KEYDOWN(ENTER)) do_key(29);
        if (KEYDOWN(SHIFT)) do_key(30);
        if (KEYDOWN(Z)) do_key(31);
        if (KEYDOWN(X)) do_key(32);
        if (KEYDOWN(C)) do_key(33);
        if (KEYDOWN(V)) do_key(34);
        if (KEYDOWN(B)) do_key(35);
        if (KEYDOWN(N)) do_key(36);
        if (KEYDOWN(M)) do_key(37);
        if (KEYDOWN(SYM)) do_key(38);
        if (KEYDOWN(SPACE)) do_key(39);

        framecounter++;
        do_halt();
        if (framecounter > 500)
        {
            framecounter = 0;
                     // 12345678901234567890123456789012
            switch (infoloop)
            {
            case 0:
                drawstring("Welcome to \"Rotten Egg Mines\"   ", 0, 176);
                drawstring("By Jari Komppa http://iki.fi/sol", 0, 184);
                break;
            case 1:
                drawstring("How to play:                    ", 0, 176);
                drawstring("Press keys to find mines.       ", 0, 184);
                break;
            case 2:
            case 4:
            case 6:
            case 8:
                drawstring(". . . . . . . . . . . . . . . . ", 0, 176);
                drawstring(" . . . . . . . . . . . . . . . .", 0, 184);
                break;   
            case 3:
                drawstring("Sound effects played via        ", 0, 176);
                drawstring("BeepFX by Shiru                 ", 0, 184);
                break;   
            case 5:
                drawstring("Art made by using the           ", 0, 176);
                drawstring("Image Spectrumizer              ", 0, 184);
                break;   
            case 7:
                drawstring("Sources can be found at         ", 0, 176);
                drawstring("github.com/jarikomppa/speccy    ", 0, 184);
                break;   
            case 12:
                drawstring("    [ . . . . . . . . . . .]    ", 0, 176);
                drawstring("    [. . . . . . . . . . . ]    ", 0, 184);
                break;         
            case 13:
                drawstring("        [ . . . . . . .]        ", 0, 176);
                drawstring("        [. . . . . . . ]        ", 0, 184);
                break;         
            case 14:
                drawstring("            [ . . .]            ", 0, 176);
                drawstring("            [. . . ]            ", 0, 184);
                break;         
            case 15:
                drawstring("                                ", 0, 176);
                drawstring("                                ", 0, 184);
                break;         
            }
            infoloop++;
            if (infoloop == 16)
                infoloop = 0;
        }
    }       
}
Exemplo n.º 6
0
/* Build a packet and write it to the stream OUT.
 * Returns: 0 on success or on an error code.  */
int
build_packet (IOBUF out, PACKET *pkt)
{
  int rc = 0;
  int new_ctb = 0;
  int ctb, pkttype;

  if (DBG_PACKET)
    log_debug ("build_packet() type=%d\n", pkt->pkttype);
  log_assert (pkt->pkt.generic);

  switch ((pkttype = pkt->pkttype))
    {
    case PKT_PUBLIC_KEY:
      if (pkt->pkt.public_key->seckey_info)
        pkttype = PKT_SECRET_KEY;
      break;
    case PKT_PUBLIC_SUBKEY:
      if (pkt->pkt.public_key->seckey_info)
        pkttype = PKT_SECRET_SUBKEY;
      break;
    case PKT_PLAINTEXT:
      new_ctb = pkt->pkt.plaintext->new_ctb;
      break;
    case PKT_ENCRYPTED:
    case PKT_ENCRYPTED_MDC:
    case PKT_ENCRYPTED_AEAD:
      new_ctb = pkt->pkt.encrypted->new_ctb;
      break;
    case PKT_COMPRESSED:
      new_ctb = pkt->pkt.compressed->new_ctb;
      break;
    case PKT_USER_ID:
      if (pkt->pkt.user_id->attrib_data)
        pkttype = PKT_ATTRIBUTE;
      break;
    default:
      break;
    }

  if (new_ctb || pkttype > 15) /* new format */
    ctb = (0xc0 | (pkttype & 0x3f));
  else
    ctb = (0x80 | ((pkttype & 15)<<2));
  switch (pkttype)
    {
    case PKT_ATTRIBUTE:
    case PKT_USER_ID:
      rc = do_user_id (out, ctb, pkt->pkt.user_id);
      break;
    case PKT_OLD_COMMENT:
    case PKT_COMMENT:
      /* Ignore these.  Theoretically, this will never be called as we
       * have no way to output comment packets any longer, but just in
       * case there is some code path that would end up outputting a
       * comment that was written before comments were dropped (in the
       * public key?) this is a no-op. 	*/
      break;
    case PKT_PUBLIC_SUBKEY:
    case PKT_PUBLIC_KEY:
    case PKT_SECRET_SUBKEY:
    case PKT_SECRET_KEY:
      rc = do_key (out, ctb, pkt->pkt.public_key);
      break;
    case PKT_SYMKEY_ENC:
      rc = do_symkey_enc (out, ctb, pkt->pkt.symkey_enc);
      break;
    case PKT_PUBKEY_ENC:
      rc = do_pubkey_enc (out, ctb, pkt->pkt.pubkey_enc);
      break;
    case PKT_PLAINTEXT:
      rc = do_plaintext (out, ctb, pkt->pkt.plaintext);
      break;
    case PKT_ENCRYPTED:
      rc = do_encrypted (out, ctb, pkt->pkt.encrypted);
      break;
    case PKT_ENCRYPTED_MDC:
      rc = do_encrypted_mdc (out, ctb, pkt->pkt.encrypted);
      break;
    case PKT_ENCRYPTED_AEAD:
      rc = do_encrypted_aead (out, ctb, pkt->pkt.encrypted);
      break;
    case PKT_COMPRESSED:
      rc = do_compressed (out, ctb, pkt->pkt.compressed);
      break;
    case PKT_SIGNATURE:
      rc = do_signature (out, ctb, pkt->pkt.signature);
      break;
    case PKT_ONEPASS_SIG:
      rc = do_onepass_sig (out, ctb, pkt->pkt.onepass_sig);
      break;
    case PKT_RING_TRUST:
      /* Ignore it (only written by build_packet_and_meta)  */
      break;
    case PKT_MDC:
      /* We write it directly, so we should never see it here. */
    default:
      log_bug ("invalid packet type in build_packet()\n");
      break;
    }

  return rc;
}
Exemplo n.º 7
0
void
main( int argc, char *argv[], char *envp[] )
{
	int 	i;
/* 	-----	evnt_multi return parameters */
	int		event, msg[8], key, nclicks;
	MRETS	mrets;
	int  	rez;
/*
 * Initialize global arguments
 */
	if( (nargs = argc) != 1)
		args = argv;
	env = envp;

/*
 * See if we were run from the AUTO folder...
 */
	if( (gl_apid = appl_init()) == -1 ) {
		Cconws("\r\nError initializing GEM, hit a key...");
		Cconin();
		exit( gl_apid );
	}
	rez = Getrez() + 2;
	if(( rez != 2 ) && ( rez != 6 ) )
	{
	   /* Ensure that we run ONLY in ST LOW or TT MED - 640x480 16 colors */
	   form_alert( 1, "[3][ | This program runs in| ST LOW or TT MED Only][ OK ]" );
	   appl_exit();
	   exit( -1 );
	}
/*
 * Set up work_in to initialize VDI functions to useful values,
 * Get the physical workstation handle from the AES, then
 * open a virtual workstation and get our AES work area's extent.
 */
	work_in[0] = Getrez()+2; /* let's not gag GDOS */
	for( i = 1; i < 10; work_in[i++] = 1 )
	;
	work_in[10] = 2; /* raster coordinates */
	vhandle = graf_handle( &gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox );
	v_opnvwk( work_in, &vhandle, work_out );
	xres = work_out[0];
	yres = work_out[1];

/*
 * Call initialization hooks
 */
	Wind_get( 0, WF_WORKXYWH, ( WARGS *)&desk );
	if( !rsrc_init() ) {
		form_alert( 1, "[3][ RSC ERROR ][ OK ]" );
		v_clsvwk( vhandle );
		appl_exit();
		exit( -1 );
	}

	wind_init();
	evnt_init();

/*
 * Main event loop
 */
	do {

		event = Evnt_multi( ev_mask, ev_clicks, ev_bmask, ev_bstate,
							&ev_m1, &ev_m2, ( WORD *)msg, ev_time,
							&mrets, ( WORD *)&key, ( WORD *)&nclicks );
		wind_update( BEG_UPDATE );
	/*
	 * call pre-event-processing hook
	 */
		if( evnt_hook( event, msg, &mrets, &key, &nclicks ) )
			continue;

	/* Dispatch events.
	 * It is possible to get more than one event at a time, so if the
	 * order of event handling is important to you, change the order
	 * in which they're handled here.
	 */
		if( event & MU_TIMER )
			do_timer( &event );

		if( event & MU_KEYBD )
			do_key( mrets.kstate, key, &event );

		if( event & MU_BUTTON )
			do_button( &mrets, nclicks, &event );

		if( event & MU_M1 )
			do_m1( &mrets, &event );

		if( event & MU_M2 )
			do_m2( &mrets, &event );

		if( event & MU_MESAG )
			switch( msg[0] ) {

				case MN_SELECTED:
					do_menu( msg, &event );
				break;

				case WM_REDRAW:
				case WM_TOPPED:
				case WM_CLOSED:
				case WM_FULLED:
				case WM_ARROWED:
				case WM_HSLID:
				case WM_VSLID:
				case WM_SIZED:
				case WM_MOVED:
				case WM_NEWTOP:
					do_windows( msg, &event );
				break;

				case AC_OPEN:
					acc_open( msg );
				break;

				case AC_CLOSE:
					acc_close( msg );
				break;

				default:
					msg_hook( msg, &event );
			} /* switch */
		/* MU_MESAG */

		wind_update( END_UPDATE );

	/*
	 * Event handling routines zero out the event variable
	 * to exit the application.
	 */
	} while( event );

	gem_exit( 0 );
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
	int rc;
	int opcount = 0;
	int insert_count = 0;
	int delete_count = 0;
	int ncount;
	int done = 0;
	char command[COMMAND + 1];
	int error;

	t = cp_multimap_create_by_option(COLLECTION_MODE_NOSYNC | 
								     COLLECTION_MODE_COPY |
					                 COLLECTION_MODE_DEEP, 
									 Employee_name, 
								     (cp_compare_fn) strcmp, 
									 (cp_copy_fn) Employee_dup, free);
	if (t == NULL)
	{
		perror("create");
		exit(1);
	}

	number_index = 
		cp_multimap_create_index(t, CP_UNIQUE, Employee_number, numcmp, &rc);
	if (number_index == NULL)
	{
		fprintf(stderr, "received error %d\n", rc);
		exit(rc);
	}

	title_index = 
		cp_multimap_create_index(t, CP_MULTIPLE, Employee_title, 
		                         (cp_compare_fn) strcmp, &rc);
	if (title_index == NULL)
	{
		fprintf(stderr, "received error %d\n", rc);
		exit(rc);
	}

	print_command_summary(argv[0]);
	while (!done)
	{
		error = 1;
		printf("> ");
		fgets(command, COMMAND, stdin);
		ltrim(command);
		chomp(command);
		if (strlen(command) == 0) continue;
		if (strcmp(command, "q") == 0 || strcmp(command, "Q") == 0) break;
		if (command[1] == 0x20 || command[1] == '\0')
		{
			error = 0;
			switch (tolower(command[0]))
			{
				case 'a': do_add(command); break;
				case 'd': do_delete(command); break;
				case 'e': do_edit(command); break;
				case 'h': print_command_summary(argv[0]); break;
				case 'k': do_key(command); break;
				case 'l': do_list(command); break;
				default: error = 1;
			}
		}
		if (error)
			printf("unrecognized command: [%s]. Enter 'h' for a list of commands or 'q' to quit.\n", command);
	}

	cp_multimap_destroy(t);
	return 0;
}
Exemplo n.º 9
0
Arquivo: top.c Projeto: AnthraX1/rk
int main(int argc, char **argv)
{
    /* For select(2). */
    struct timeval tv;
    fd_set in;
    /* For parsing arguments. */
    char *cp;
    /* The key read in. */
    char c;

    get_options();
    /*
     * Parse arguments.
     */
    argv++;
    while (*argv) {
	cp = *argv++;
	while (*cp) {
	    switch (*cp) {
	      case 'd':
	        if (cp[1]) {
		    if (sscanf(++cp, "%f", &Sleeptime) != 1) {
			fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
			exit(1);
		    }
		    goto breakargv;
		} else if (*argv) { /* last char in an argv, use next as arg */
		    if (sscanf(cp = *argv++, "%f", &Sleeptime) != 1) {
			fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
			exit(1);
		    }
		    goto breakargv;
		} else {
		    fprintf(stderr, "-d requires an argument\n");
		    exit(1);
		}
		break;
	      case 'q':
		if (!getuid())
		    /* set priority to -10 in order to stay above kswapd */
		    if (setpriority(PRIO_PROCESS, getpid(), -10)) {
			/* We check this just for paranoia.  It's not
			   fatal, and shouldn't happen. */
			perror(PROGNAME ": setpriority() failed");
		    }
		Sleeptime = 0;
		break;
	      case 'c':
	        show_cmd = !show_cmd;
		break;
	      case 'S':
		Cumulative = 1;
		break;
	      case 'i':
		Noidle = 1;
		break;
	      case 's':
		Secure = 1;
		break;
	      case '-':
		break;		/* Just ignore it */
#if defined (SHOWFLAG)
              case '/': showall++;
#endif
	      default:
		fprintf(stderr, PROGNAME ": Unknown argument `%c'\n", *cp);
		exit(1);
	    }
	    cp++;
	}
    breakargv:
    }
    
    /* set to PCPU sorting */
    register_sort_function( -1, (cmp_t)pcpu_sort);
    
    /* for correct handling of some fields, we have to do distinguish 
  * between kernel versions */
    set_linux_version();
    /* get kernel symbol table, if needed */
    if (!CL_wchan_nout) {
	if (open_psdb()) {
	    CL_wchan_nout = 1;
	} else {
	    psdbsucc = 1;
	}
    }

    setup_terminal();
    window_size();
    /*
     * calculate header size, length of cmdline field ...
     */
    Numfields = make_header();
    /*
     * Set up signal handlers.
     */
    signal(SIGHUP, (void *) (int) end);
    signal(SIGINT, (void *) (int) end);
    signal(SIGQUIT, (void *) (int) end);
    signal(SIGTSTP, (void *) (int) stop);
    signal(SIGWINCH, (void *) (int) window_size);

    /* loop, collecting process info and sleeping */
    while (1) {
	if (setjmp(redraw_jmp))
	    clear_screen();

	/* display the tasks */
	show_procs();
	/* sleep & wait for keyboard input */
	tv.tv_sec = Sleeptime;
	tv.tv_usec = (Sleeptime - (int) Sleeptime) * 1000000;
	FD_ZERO(&in);
	FD_SET(0, &in);
	if (select(16, &in, 0, 0, &tv) > 0 && read(0, &c, 1) == 1)
	    do_key(c);
    }
}

/*#######################################################################
 *#### Signal handled routines: error_end, end, stop, window_size     ###
 *#### Small utilities: make_header, getstr, getint, getfloat, getsig ###
 *#######################################################################
 */


	/*
	 *  end when exiting with an error.
	 */
void error_end(int rno)
{
    if (psdbsucc)
        close_psdb();
    ioctl(0, TCSETAF, &Savetty);
    PUTP(tgoto(cm, 0, Lines - 1));
    fputs("\r\n", stdout);
    exit(rno);
}
/*
	 * Normal end of execution.
	 */
void end(void)
{
    if (psdbsucc)
	close_psdb();
    ioctl(0, TCSETAF, &Savetty);
    PUTP(tgoto(cm, 0, Lines - 1));
    fputs("\r\n", stdout);
    exit(0);
}

/*
	 * SIGTSTP catcher.
	 */
void stop(void)
{
    /* Reset terminal. */
    if (psdbsucc)
	close_psdb();
    ioctl(0, TCSETAF, &Savetty);
    PUTP(tgoto(cm, 0, Lines - 3));
    fflush(stdout);
    raise(SIGTSTP);
    /* Later... */
    ioctl(0, TCSETAF, &Rawtty);
    signal(SIGTSTP, (void *) (int) stop);
    longjmp(redraw_jmp, 1);
}

/*
       * Reads the window size and clear the window.  This is called on setup,
       * and also catches SIGWINCHs, and adjusts Maxlines.  Basically, this is
       * the central place for window size stuff.
       */
void window_size(void)
{
    struct winsize ws;

    if (ioctl(1, TIOCGWINSZ, &ws) != -1) {
	Cols = ws.ws_col;
	Lines = ws.ws_row;
    } else {
	Cols = tgetnum("co");
	Lines = tgetnum("li");
    }
    clear_screen();
}
/*
       * this adjusts the lines needed for the header to the current value
       */
int make_header(void)
{
    int i, j;

    j = 0;
    for (i = 0; i < strlen(Fields); i++) {
	if (isupper(Fields[i])) {
	    pflags[j++] = Fields[i] - 'A';
	}
    }
    strcpy(Header, "");
    for (i = 0; i < j; i++)
	strcat(Header, headers[pflags[i]]);
    /* readjust window size ... */
    Maxcmd = Cols - strlen(Header) + 7;
    Maxlines = Display_procs ? Display_procs : Lines - header_lines;
    if (Maxlines > Lines - header_lines)
	Maxlines = Lines - header_lines;
    return (j);
}
Exemplo n.º 10
0
int
do_filename(const char *filename, int quiet_open)
{
	FILE *f;
	char line[SSH_MAX_PUBKEY_BYTES];
	char *cp;
	u_long linenum = 0;
	Key *key;
	char *comment = NULL;
	int found = 0, ret = 1;

	/* Copy much of key_load_public's logic here so that we can read
	 * several keys from a single file (e.g. authorized_keys).
	 */

	if (strcmp(filename, "-") != 0) {
		f = fopen(filename, "r");
		if (!f) {
			char pubfile[MAXPATHLEN];
			if (strlcpy(pubfile, filename, sizeof pubfile) <
			    sizeof(pubfile) &&
			    strlcat(pubfile, ".pub", sizeof pubfile) <
			    sizeof(pubfile))
				f = fopen(pubfile, "r");
		}
		if (!f) {
			if (!quiet_open)
				perror(filename);
			return -1;
		}
	} else
		f = stdin;
	while (read_keyfile_line(f, filename, line, sizeof(line),
		    &linenum) != -1) {
		int i;
		char *space;
		int type;

		/* Chop trailing newline. */
		i = strlen(line) - 1;
		if (line[i] == '\n')
			line[i] = '\0';

		/* Skip leading whitespace, empty and comment lines. */
		for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
			;
		if (!*cp || *cp == '\n' || *cp == '#')
			continue;

		/* Cope with ssh-keyscan output and options in
		 * authorized_keys files.
		 */
		space = strchr(cp, ' ');
		if (!space)
			continue;
		*space = '\0';
		type = key_type_from_name(cp);
		*space = ' ';
		/* Leading number (RSA1) or valid type (RSA/DSA) indicates
		 * that we have no host name or options to skip.
		 */
		if (atoi(cp) == 0 && type == KEY_UNSPEC) {
			int quoted = 0;

			for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
				if (*cp == '\\' && cp[1] == '"')
					cp++;	/* Skip both */
				else if (*cp == '"')
					quoted = !quoted;
			}
			/* Skip remaining whitespace. */
			for (; *cp == ' ' || *cp == '\t'; cp++)
				;
			if (!*cp)
				continue;
		}

		/* Read and process the key itself. */
		key = key_new(KEY_RSA1);
		if (key_read(key, &cp) == 1) {
			while (*cp == ' ' || *cp == '\t')
				cp++;
			if (!do_key(key, *cp ? cp : filename))
				ret = 0;
			found = 1;
		} else {
			key_free(key);
			key = key_new(KEY_UNSPEC);
			if (key_read(key, &cp) == 1) {
				while (*cp == ' ' || *cp == '\t')
					cp++;
				if (!do_key(key, *cp ? cp : filename))
					ret = 0;
				found = 1;
			}
		}
		key_free(key);
	}
	if (f != stdin)
		fclose(f);

	if (!found && filename) {
		key = key_load_public(filename, &comment);
		if (key) {
			if (!do_key(key, comment))
				ret = 0;
			found = 1;
		}
		if (comment)
			xfree(comment);
	}

	return ret;
}