Changeset 012dd8e in mainline for uspace/srv/loader/main.c


Ignore:
Timestamp:
2019-08-07T09:15:30Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

taskman: Handle INIT_TASKS as tasks spawned by loader

  • everyone is connected to its spawner, except for INIT_TASKS, they are connected to taskman (first binary)
  • taskman is now aware even of INIT_TASKS and taskman itself
  • refactored taskman handshake — NS session is created lazily
  • refactored async.c with usage of create_session
  • changed EINVAL to EINTR on lost waits
  • removed TODOs from taskman and related libc TODOs

Conflicts:

abi/include/abi/ipc/methods.h
boot/Makefile.common
uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/loader.c
uspace/lib/c/generic/ns.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/generic/private/taskman.h
uspace/lib/c/generic/task.c
uspace/lib/c/include/async.h
uspace/lib/c/include/task.h
uspace/srv/loader/main.c
uspace/srv/ns/ns.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loader/main.c

    r780c8ce r012dd8e  
    3535 * The program loader is a special init binary. Its image is used
    3636 * to create a new task upon a @c task_spawn syscall. It has a phone connected
    37  * to the caller of te syscall. The formal caller (taskman) performs a
     37 * to the caller of the syscall. The formal caller (taskman) performs a
    3838 * handshake with loader so that apparent caller can communicate with the
    3939 * loader.
     
    6060#include <ipc/loader.h>
    6161#include <loader/pcb.h>
     62#include <ns.h>
    6263#include <str.h>
    6364#include <sys/types.h>
     65#include <task.h>
    6466#include <taskman.h>
    6567#include <unistd.h>
     
    7274#endif
    7375
     76#define NAME "loader"
    7477#define DPRINTF(...) ((void) 0)
    7578
     
    8083/** The Program control block */
    8184static 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;
    8885
    8986/** Current working directory */
     
    105102/** Used to limit number of connections to one. */
    106103static 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);
    112104
    113105static void ldr_get_taskid(ipc_call_t *req)
     
    337329        DPRINTF("PCB set.\n");
    338330
    339         pcb.session_primary = session_primary;
    340         pcb.session_taskman = session_taskman;
     331        pcb.session_taskman = taskman_get_session();
    341332
    342333        pcb.cwd = cwd;
     
    394385static void ldr_connection(ipc_call_t *icall, void *arg)
    395386{
    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 
    403387        /* Already have a connection? */
    404388        if (connected) {
     
    456440}
    457441
    458 /** Handshake with taskman
    459  *
    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 the
    462  * 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 
    491442/** Program loader main function.
    492443 */
     
    496447        async_set_fallback_port_handler(ldr_connection, NULL);
    497448       
    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);
    502454                return rc;
    503455        }
    504456
    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         */
    506461        async_manager();
    507         //TODO retval?
    508462       
    509463        /* Never reached */
Note: See TracChangeset for help on using the changeset viewer.