Changeset 65c65bb in rtems-libbsd for rtemsbsd/telnetd
- Timestamp:
- 07/01/16 05:49:52 (7 years ago)
- Branches:
- 5, 5-freebsd-12, 6-freebsd-12, freebsd-9.3, master
- Children:
- 4dec435
- Parents:
- fc26479
- Location:
- rtemsbsd/telnetd
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtemsbsd/telnetd/telnetd.c
rfc26479 r65c65bb 88 88 89 89 /***********************************************************/ 90 static rtems_id telnetd_task_id = RTEMS_ID_NONE; 91 92 rtems_id (*telnetd_spawn_task)( 90 static rtems_telnetd_config_table* telnetd_config; 91 static rtems_id telnetd_task_id; 92 93 /* 94 * chrisj: this variable was global and with no declared interface in a header 95 * file and with no means to set it so I have stopped it being global; 96 * if this breaks any user they will have be to provide a formal 97 * interface to get this change reverted. 98 */ 99 static const rtems_id (*telnetd_spawn_task)( 93 100 const char *, 94 101 unsigned, … … 208 215 209 216 /* we don't redirect stdio as this probably 210 * was started from the console anyway s..217 * was started from the console anyway .. 211 218 */ 212 219 do { 213 if ( rtems_telnetd_config.keep_stdio) {220 if (telnetd_config->keep_stdio) { 214 221 bool start = true; 215 222 char device_name [32]; 216 223 217 224 ttyname_r( 1, device_name, sizeof( device_name)); 218 if ( rtems_telnetd_config.login_check != NULL) {225 if (telnetd_config->login_check != NULL) { 219 226 start = rtems_shell_login_prompt( 220 227 stdin, 221 228 stderr, 222 229 device_name, 223 rtems_telnetd_config.login_check230 telnetd_config->login_check 224 231 ); 225 232 } 226 233 if (start) { 227 rtems_telnetd_config.command( device_name, arg->arg);234 telnetd_config->command( device_name, arg->arg); 228 235 } else { 229 236 syslog( … … 245 252 246 253 arg->devname = devname; 247 arg->arg = rtems_telnetd_config.arg;254 arg->arg = telnetd_config->arg; 248 255 strncpy(arg->peername, peername, sizeof(arg->peername)); 249 256 250 257 telnetd_task_id = telnetd_spawn_task( 251 258 devname, 252 rtems_telnetd_config.priority,253 rtems_telnetd_config.stack_size,259 telnetd_config->priority, 260 telnetd_config->stack_size, 254 261 spawned_shell, 255 262 arg … … 288 295 } 289 296 290 rtems_status_code rtems_telnetd_ initialize( void)291 { 292 if (telnetd_ task_id != RTEMS_ID_NONE) {297 rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config) 298 { 299 if (telnetd_config != NULL) { 293 300 fprintf(stderr, "telnetd already started\n"); 294 301 return RTEMS_RESOURCE_IN_USE; 295 302 } 296 303 297 if ( rtems_telnetd_config.command == NULL) {304 if (config->command == NULL) { 298 305 fprintf(stderr, "telnetd setup with invalid command\n"); 299 306 return RTEMS_IO_ERROR; 300 307 } 301 308 309 telnetd_config = calloc(1, sizeof(*telnetd_config)); 310 if (telnetd_config == NULL) { 311 fprintf(stderr, "telnetd cannot alloc telnetd config table\n"); 312 return RTEMS_NO_MEMORY; 313 } 314 315 302 316 if ( !telnet_pty_initialize() ) { 303 317 fprintf(stderr, "telnetd cannot initialize PTY driver\n"); 318 free(telnetd_config); 319 telnetd_config = NULL; 304 320 return RTEMS_IO_ERROR; 305 321 } 306 322 323 *telnetd_config = *config; 324 307 325 /* Check priority */ 308 if ( rtems_telnetd_config.priority < 2) {309 rtems_telnetd_config.priority = 100;326 if (telnetd_config->priority < 2) { 327 telnetd_config->priority = 100; 310 328 } 311 329 312 330 /* Check stack size */ 313 if ( rtems_telnetd_config.stack_size <= 0) {314 rtems_telnetd_config.stack_size = (size_t)32 * 1024;331 if (telnetd_config->stack_size <= 0) { 332 telnetd_config->stack_size = (size_t)32 * 1024; 315 333 } 316 334 … … 318 336 telnetd_task_id = telnetd_spawn_task( 319 337 "TNTD", 320 rtems_telnetd_config.priority,321 rtems_telnetd_config.stack_size,338 telnetd_config->priority, 339 telnetd_config->stack_size, 322 340 rtems_task_telnetd, 323 341 0 324 342 ); 325 343 if (telnetd_task_id == RTEMS_ID_NONE) { 344 free(telnetd_config); 345 telnetd_config = NULL; 326 346 return RTEMS_IO_ERROR; 327 347 } 328 348 329 349 /* Print status */ 330 if (! rtems_telnetd_config.keep_stdio) {350 if (!telnetd_config->keep_stdio) { 331 351 fprintf( 332 352 stderr, 333 353 "telnetd started with stacksize = %u and priority = %d\n", 334 (unsigned) rtems_telnetd_config.stack_size,335 (unsigned) rtems_telnetd_config.priority354 (unsigned) telnetd_config->stack_size, 355 (unsigned) telnetd_config->priority 336 356 ); 337 357 } … … 387 407 388 408 /* call their routine */ 389 if ( rtems_telnetd_config.login_check != NULL) {409 if (telnetd_config->login_check != NULL) { 390 410 start = rtems_shell_login_prompt( 391 411 stdin, 392 412 stderr, 393 413 arg->devname, 394 rtems_telnetd_config.login_check414 telnetd_config->login_check 395 415 ); 396 416 login_failed = !start; 397 417 } 398 418 if (start) { 399 rtems_telnetd_config.command( arg->devname, arg->arg);419 telnetd_config->command( arg->devname, arg->arg); 400 420 } 401 421
Note: See TracChangeset
for help on using the changeset viewer.