Example #1
0
int main(int argc, char *argv[])
{
    char *control;
    int c, err, nodaemon;
    FILE *out;

    control = NULL;
    nodaemon = 0;

    while ((c = getopt(argc, argv, "Dh")) != -1) {
        switch (c) {
        case 'D':
            nodaemon = 1;
            break;
        case 'h':
            usage(argv[0], 0);
            break;
        default:
            usage(argv[0], EINVAL);
        }
    }

    if (optind != argc)
        usage(argv[0], EINVAL);

    err = tapdisk_server_init();
    if (err) {
        DPRINTF("failed to initialize server: %d\n", err);
        goto out;
    }

    out = fdup(stdout, "w");
    if (!out) {
        err = -errno;
        DPRINTF("failed to dup stdout: %d\n", err);
        goto out;
    }

    if (!nodaemon) {
        err = daemon(0, 0);
        if (err) {
            DPRINTF("failed to daemonize: %d\n", errno);
            goto out;
        }
    }

    tapdisk_start_logging("tapdisk", NULL);

    err = tapdisk_control_open(&control);
    if (err) {
        DPRINTF("failed to open control socket: %d\n", err);
        goto out;
    }

    err = tapdisk_server_complete();
    if (err) {
        DPRINTF("failed to complete server: %d\n", err);
        goto out;
    }

    fprintf(out, "%s\n", control);
    fclose(out);

    err = tapdisk_server_run();

  out:
    tapdisk_control_close();
    tapdisk_stop_logging();
    return -err;
}
Example #2
0
int
main(int argc, char *argv[])
{
	char *control;
	int c, err, nodaemon;
	FILE *out;

	control  = NULL;
	nodaemon = 0;

	while ((c = getopt(argc, argv, "Dh")) != -1) {
		switch (c) {
		case 'D':
			nodaemon = 1;
			break;
		case 'h':
			usage(argv[0], 0);
			break;
		default:
			usage(argv[0], EINVAL);
		}
	}

	if (optind != argc)
		usage(argv[0], EINVAL);

	err = tapdisk_server_init();
	if (err) {
		DPRINTF("failed to initialize server: %d\n", err);
		goto out;
	}

	out = fdup(stdout, "w");
	if (!out) {
		err = -errno;
		DPRINTF("failed to dup stdout: %d\n", err);
		goto out;
	}

	if (!nodaemon) {
		err = daemon(0, 0);
		if (err) {
			DPRINTF("failed to daemonize: %d\n", errno);
			goto out;
		}
	}

	tapdisk_start_logging("tapdisk", NULL);

	err = tapdisk_control_open(&control);
	if (err) {
		DPRINTF("failed to open control socket: %d\n", err);
		goto out;
	}

	err = tapdisk_server_complete();
	if (err) {
		DPRINTF("failed to complete server: %d\n", err);
		goto out;
	}

	fprintf(out, "%s\n", control);
	fclose(out);

	err = td_metrics_start();
	if (err) {
		DPRINTF("failed to create metrics folder: %d\n", err);
		goto out;
	}
	/*
	 * NB: We're unconditionally starting the FD receiver here - this is 
	 * for the block-nbd driver. In the future we may want to start this as 
	 * a response to a tap-ctl message
	 */
	tdnbd_fdreceiver_start();

	err = tapdisk_server_run();

out:
	td_metrics_stop();
	tdnbd_fdreceiver_stop();
	tapdisk_control_close();
	tapdisk_stop_logging();
	return -err;
}