Index: uspace/app/hrctl/hrctl.c
===================================================================
--- uspace/app/hrctl/hrctl.c	(revision 217d0fb82558ed2d41fafb35fa77968453c367b2)
+++ uspace/app/hrctl/hrctl.c	(revision fc265b4367687fc2dca4a6d18ca2b8a6c4885ddb)
@@ -229,5 +229,5 @@
 }
 
-static int handle_create(int argc, char **argv)
+static int handle_create(hr_t *hr, int argc, char **argv)
 {
 	if (optind >= argc) {
@@ -287,13 +287,5 @@
 	}
 
-	hr_t *hr;
-	errno_t rc = hr_sess_init(&hr);
-	if (rc != EOK) {
-		printf(NAME ": server session init failed: %s\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = hr_create(hr, vol_config);
+	errno_t rc = hr_create(hr, vol_config);
 	if (rc != EOK) {
 		printf(NAME ": creation failed: %s\n",
@@ -301,6 +293,4 @@
 		goto error;
 	}
-
-	hr_sess_destroy(hr);
 
 	free(vol_config);
@@ -311,9 +301,9 @@
 }
 
-static int handle_assemble(int argc, char **argv)
+static int handle_assemble(hr_t *hr, int argc, char **argv)
 {
 	if (optind >= argc) {
 		size_t cnt;
-		errno_t rc = hr_auto_assemble(&cnt);
+		errno_t rc = hr_auto_assemble(hr, &cnt);
 		if (rc != EOK) {
 			/* XXX: here have own error codes */
@@ -353,14 +343,6 @@
 	}
 
-	hr_t *hr;
-	errno_t rc = hr_sess_init(&hr);
-	if (rc != EOK) {
-		printf(NAME ": server session init failed: %s\n",
-		    str_error(rc));
-		goto error;
-	}
-
 	size_t cnt;
-	rc = hr_assemble(hr, vol_config, &cnt);
+	errno_t rc = hr_assemble(hr, vol_config, &cnt);
 	if (rc != EOK) {
 		printf(NAME ": assmeble failed: %s\n", str_error(rc));
@@ -369,6 +351,4 @@
 
 	printf("hrctl: auto assembled %zu volumes\n", cnt);
-
-	hr_sess_destroy(hr);
 
 	free(vol_config);
@@ -379,8 +359,8 @@
 }
 
-static int handle_disassemble(int argc, char **argv)
+static int handle_disassemble(hr_t *hr, int argc, char **argv)
 {
 	if (optind >= argc) {
-		errno_t rc = hr_stop_all();
+		errno_t rc = hr_stop_all(hr);
 		if (rc != EOK) {
 			printf(NAME ": stopping some volumes failed: %s\n",
@@ -398,5 +378,5 @@
 	const char *devname = argv[optind++];
 
-	errno_t rc = hr_stop(devname);
+	errno_t rc = hr_stop(hr, devname);
 	if (rc != EOK) {
 		printf(NAME ": disassembly of device \"%s\" failed: %s\n",
@@ -408,5 +388,5 @@
 }
 
-static int handle_modify(int argc, char **argv)
+static int handle_modify(hr_t *hr, int argc, char **argv)
 {
 	if (optind >= argc) {
@@ -432,5 +412,5 @@
 		optind++;
 		unsigned long extent = strtol(argv[optind++], NULL, 10);
-		errno_t rc = hr_fail_extent(volname, extent);
+		errno_t rc = hr_fail_extent(hr, volname, extent);
 		if (rc != EOK) {
 			printf(NAME ": failing extent failed: %s\n",
@@ -441,5 +421,5 @@
 	    str_cmp(argv[optind], "-h") == 0) {
 		optind++;
-		errno_t rc = hr_add_hotspare(volname, argv[optind++]);
+		errno_t rc = hr_add_hotspare(hr, volname, argv[optind++]);
 		if (rc != EOK) {
 			printf(NAME ": adding hotspare failed: %s\n",
@@ -455,10 +435,10 @@
 }
 
-static int handle_status(int argc, char **argv)
+static int handle_status(hr_t *hr, int argc, char **argv)
 {
 	(void)argc;
 	(void)argv;
 
-	errno_t rc = hr_print_status();
+	errno_t rc = hr_print_status(hr);
 	if (rc != EOK) {
 		printf(NAME ": status printing failed: %s\n", str_error(rc));
@@ -472,5 +452,5 @@
 {
 	int rc = EXIT_SUCCESS;
-	int c;
+	hr_t *hr = NULL;
 
 	if (argc < 2) {
@@ -479,5 +459,10 @@
 	}
 
-	c = 0;
+	if (hr_sess_init(&hr) != EOK) {
+		printf(NAME ": hr server session init failed: %s\n",
+		    str_error(rc));
+		return EXIT_FAILURE;
+	}
+
 	optreset = 1;
 	optind = 0;
@@ -493,31 +478,31 @@
 	};
 
-	while (c != -1) {
-		c = getopt_long(argc, argv, "hcadms", top_level_opts, NULL);
-		switch (c) {
-		case 'h':
-			usage();
-			return EXIT_SUCCESS;
-		case 'c':
-			rc = handle_create(argc, argv);
-			goto end;
-		case 'a':
-			rc = handle_assemble(argc, argv);
-			goto end;
-		case 'd':
-			rc = handle_disassemble(argc, argv);
-			goto end;
-		case 'm':
-			rc = handle_modify(argc, argv);
-			goto end;
-		case 's':
-			rc = handle_status(argc, argv);
-			goto end;
-		default:
-			goto end;
-		}
+	int c = getopt_long(argc, argv, "hcadms", top_level_opts, NULL);
+	switch (c) {
+	case 'h':
+		usage();
+		goto end;
+	case 'c':
+		rc = handle_create(hr, argc, argv);
+		goto end;
+	case 'a':
+		rc = handle_assemble(hr, argc, argv);
+		goto end;
+	case 'd':
+		rc = handle_disassemble(hr, argc, argv);
+		goto end;
+	case 'm':
+		rc = handle_modify(hr, argc, argv);
+		goto end;
+	case 's':
+		rc = handle_status(hr, argc, argv);
+		goto end;
+	default:
+		goto end;
 	}
 
 end:
+	hr_sess_destroy(hr);
+
 	if (rc != EXIT_SUCCESS)
 		printf(NAME ": use --help to see usage\n");
