Changeset 012dd8e in mainline for uspace/srv/loader/main.c
- Timestamp:
- 2019-08-07T09:15:30Z (6 years ago)
- Children:
- e8747bd8
- Parents:
- 780c8ce
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-11-01 00:08:04)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:15:30)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/main.c
r780c8ce r012dd8e 35 35 * The program loader is a special init binary. Its image is used 36 36 * to create a new task upon a @c task_spawn syscall. It has a phone connected 37 * to the caller of t e syscall. The formal caller (taskman) performs a37 * to the caller of the syscall. The formal caller (taskman) performs a 38 38 * handshake with loader so that apparent caller can communicate with the 39 39 * loader. … … 60 60 #include <ipc/loader.h> 61 61 #include <loader/pcb.h> 62 #include <ns.h> 62 63 #include <str.h> 63 64 #include <sys/types.h> 65 #include <task.h> 64 66 #include <taskman.h> 65 67 #include <unistd.h> … … 72 74 #endif 73 75 76 #define NAME "loader" 74 77 #define DPRINTF(...) ((void) 0) 75 78 … … 80 83 /** The Program control block */ 81 84 static pcb_t pcb; 82 83 /** Primary IPC session */84 static async_sess_t *session_primary = NULL;85 86 /** Session to taskman (typically our spawner) */87 static async_sess_t *session_taskman = NULL;88 85 89 86 /** Current working directory */ … … 105 102 /** Used to limit number of connections to one. */ 106 103 static bool connected = false; 107 108 /** Ensure synchronization of handshake and connection fibrils. */109 static bool handshake_complete = false;110 FIBRIL_MUTEX_INITIALIZE(handshake_mtx);111 FIBRIL_CONDVAR_INITIALIZE(handshake_cv);112 104 113 105 static void ldr_get_taskid(ipc_call_t *req) … … 337 329 DPRINTF("PCB set.\n"); 338 330 339 pcb.session_primary = session_primary; 340 pcb.session_taskman = session_taskman; 331 pcb.session_taskman = taskman_get_session(); 341 332 342 333 pcb.cwd = cwd; … … 394 385 static void ldr_connection(ipc_call_t *icall, void *arg) 395 386 { 396 /* Wait for handshake */397 fibril_mutex_lock(&handshake_mtx);398 while (!handshake_complete) {399 fibril_condvar_wait(&handshake_cv, &handshake_mtx);400 }401 fibril_mutex_unlock(&handshake_mtx);402 403 387 /* Already have a connection? */ 404 388 if (connected) { … … 456 440 } 457 441 458 /** Handshake with taskman459 *460 * Taskman is our spawn parent, i.e. PHONE_INITIAL is connected to it.461 * Goal of the handshake is to obtain phone to naming service and also keep the462 * session to taskman.463 *464 * @return EOK on success, for errors see taskman_handshake()465 */466 static errno_t ldr_taskman_handshake(void)467 {468 assert(session_primary == NULL);469 assert(session_taskman == NULL);470 471 errno_t retval = EOK;472 473 fibril_mutex_lock(&handshake_mtx);474 session_primary = taskman_handshake();475 if (session_primary == NULL) {476 retval = errno;477 goto finish;478 }479 480 session_taskman = async_session_primary_swap(session_primary);481 482 handshake_complete = true;483 484 finish:485 fibril_condvar_signal(&handshake_cv);486 fibril_mutex_unlock(&handshake_mtx);487 488 return retval;489 }490 491 442 /** Program loader main function. 492 443 */ … … 496 447 async_set_fallback_port_handler(ldr_connection, NULL); 497 448 498 /* Handshake with taskman */ 499 int rc = ldr_taskman_handshake(); 500 if (rc != EOK) { 501 DPRINTF("Failed taskman handshake (%i).\n", errno); 449 /* Announce to taskman. */ 450 errno_t rc = taskman_intro_loader(); 451 if (rc != EOK) { 452 printf("%s: did not receive connectin from taskman (%i)\n", 453 NAME, rc); 502 454 return rc; 503 455 } 504 456 505 /* Handle client connections */ 457 /* 458 * We are not a regular server, thus no retval is set, just wait for 459 * forwarded connections by taskman. 460 */ 506 461 async_manager(); 507 //TODO retval?508 462 509 463 /* Never reached */
Note:
See TracChangeset
for help on using the changeset viewer.