Revision e0a45fb4 client/client.c

View differences:

client/client.c
25 25
#include "client/client.h"
26 26
#include "sysdep/unix/unix.h"
27 27

  
28
static char *opt_list = "s:v";
28
static char *opt_list = "s:vr";
29 29
static int verbose;
30
static char *init_cmd;
31
static int once;
30 32

  
31 33
static char *server_path = PATH_CONTROL_SOCKET;
32 34
static int server_fd;
......
49 51
static void
50 52
usage(void)
51 53
{
52
  fprintf(stderr, "Usage: birdc [-s <control-socket>] [-v]\n");
54
  fprintf(stderr, "Usage: birdc [-s <control-socket>] [-v] [-r]\n");
53 55
  exit(1);
54 56
}
55 57

  
......
67 69
      case 'v':
68 70
	verbose++;
69 71
	break;
72
      case 'r':
73
	init_cmd = "restrict";
74
	break;
70 75
      default:
71 76
	usage();
72 77
      }
78

  
79
  /* If some arguments are not options, we take it as commands */
73 80
  if (optind < argc)
74
    usage();
81
    {
82
      char *tmp;
83
      int i;
84
      int len = 0;
85

  
86
      if (init_cmd)
87
	usage();
88

  
89
      for (i = optind; i < argc; i++)
90
	len += strlen(argv[i]) + 1;
91

  
92
      tmp = init_cmd = malloc(len);
93
      for (i = optind; i < argc; i++)
94
	{
95
	  strcpy(tmp, argv[i]);
96
	  tmp += strlen(tmp);
97
	  *tmp++ = ' ';
98
	}
99

  
100
      once = 1;
101
    }
75 102
}
76 103

  
77 104
/*** Input ***/
......
267 294
  if (nstate == cstate)
268 295
    return;
269 296

  
297
  if (init_cmd)
298
    {
299
      /* First transition - client received hello from BIRD
300
	 and there is waiting initial command */
301
      submit_server_command(init_cmd);
302
      init_cmd = NULL;
303
      return;
304
    }
305

  
306
  if (!init_cmd && once)
307
    {
308
      /* Initial command is finished and we want to exit */
309
      cleanup();
310
      exit(0);
311
    }
312

  
270 313
  if (nstate == STATE_PROMPT)
271 314
    if (input_initialized)
272 315
      input_reveal();

Also available in: Unified diff