Index: uspace/srv/loader/main.c
===================================================================
--- uspace/srv/loader/main.c	(revision 1be7bee8078be21f432895af4f51f96ea24ceda6)
+++ uspace/srv/loader/main.c	(revision 2df7d82445fd27fa3d7738624e0591a3d59ae237)
@@ -35,5 +35,5 @@
  * The program loader is a special init binary. Its image is used
  * to create a new task upon a @c task_spawn syscall. It has a phone connected
- * to the caller of te syscall. The formal caller (taskman) performs a
+ * to the caller of the syscall. The formal caller (taskman) performs a
  * handshake with loader so that apparent caller can communicate with the
  * loader.
@@ -60,6 +60,8 @@
 #include <ipc/loader.h>
 #include <loader/pcb.h>
+#include <ns.h>
 #include <str.h>
 #include <sys/types.h>
+#include <task.h>
 #include <taskman.h>
 #include <unistd.h>
@@ -72,4 +74,5 @@
 #endif
 
+#define NAME "loader"
 #define DPRINTF(...) ((void) 0)
 
@@ -80,10 +83,4 @@
 /** The Program control block */
 static pcb_t pcb;
-
-/** Primary IPC session */
-static async_sess_t *session_primary = NULL;
-
-/** Session to taskman (typically our spawner) */
-static async_sess_t *session_taskman = NULL;
 
 /** Current working directory */
@@ -105,9 +102,4 @@
 /** Used to limit number of connections to one. */
 static bool connected = false;
-
-/** Ensure synchronization of handshake and connection fibrils. */
-static bool handshake_complete = false;
-FIBRIL_MUTEX_INITIALIZE(handshake_mtx);
-FIBRIL_CONDVAR_INITIALIZE(handshake_cv);
 
 static void ldr_get_taskid(ipc_call_t *req)
@@ -337,6 +329,5 @@
 	DPRINTF("PCB set.\n");
 
-	pcb.session_primary = session_primary;
-	pcb.session_taskman = session_taskman;
+	pcb.session_taskman = taskman_get_session();
 
 	pcb.cwd = cwd;
@@ -394,11 +385,4 @@
 static void ldr_connection(ipc_call_t *icall, void *arg)
 {
-	/* Wait for handshake */
-	fibril_mutex_lock(&handshake_mtx);
-	while (!handshake_complete) {
-		fibril_condvar_wait(&handshake_cv, &handshake_mtx);
-	}
-	fibril_mutex_unlock(&handshake_mtx);
-
 	/* Already have a connection? */
 	if (connected) {
@@ -456,37 +440,4 @@
 }
 
-/** Handshake with taskman
- *
- * Taskman is our spawn parent, i.e. PHONE_INITIAL is connected to it.
- * Goal of the handshake is to obtain phone to naming service and also keep the
- * session to taskman.
- *
- * @return EOK on success, for errors see taskman_handshake()
- */
-static errno_t ldr_taskman_handshake(void)
-{
-	assert(session_primary == NULL);
-	assert(session_taskman == NULL);
-
-	errno_t retval = EOK;
-
-	fibril_mutex_lock(&handshake_mtx);
-	session_primary = taskman_handshake();
-	if (session_primary == NULL) {
-		retval = errno;
-		goto finish;
-	}
-
-	session_taskman = async_session_primary_swap(session_primary);
-
-	handshake_complete = true;
-
-finish:
-	fibril_condvar_signal(&handshake_cv);
-	fibril_mutex_unlock(&handshake_mtx);
-
-	return retval;
-}
-
 /** Program loader main function.
  */
@@ -496,14 +447,17 @@
 	async_set_fallback_port_handler(ldr_connection, NULL);
 	
-	/* Handshake with taskman */
-	int rc = ldr_taskman_handshake();
-	if (rc != EOK) {
-		DPRINTF("Failed taskman handshake (%i).\n", errno);
+	/* Announce to taskman. */
+	errno_t rc = taskman_intro_loader();
+	if (rc != EOK) {
+		printf("%s: did not receive connectin from taskman (%i)\n",
+		    NAME, rc);
 		return rc;
 	}
 
-	/* Handle client connections */
+	/*
+	 * We are not a regular server, thus no retval is set, just wait for
+	 * forwarded connections by taskman.
+	 */
 	async_manager();
-	//TODO retval?
 	
 	/* Never reached */
