/*1* Copyright 2016 Jakub Klama <[email protected]>2* All rights reserved3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted providing that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED15* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY17* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,21* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING22* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE23* POSSIBILITY OF SUCH DAMAGE.24*25*/2627#include <stdio.h>28#include <stdlib.h>29#include <fcntl.h>30#include <err.h>31#include <unistd.h>32#include "../lib9p.h"33#include "../backend/fs.h"34#include "../transport/socket.h"3536int37main(int argc, char **argv)38{39struct l9p_backend *fs_backend;40struct l9p_server *server;41char *host = "0.0.0.0";42char *port = "564";43char *path;44bool ro = false;45int rootfd;46int opt;4748while ((opt = getopt(argc, argv, "h:p:r")) != -1) {49switch (opt) {50case 'h':51host = optarg;52break;53case 'p':54port = optarg;55break;56case 'r':57ro = true;58break;59case '?':60default:61goto usage;62}63}6465if (optind >= argc) {66usage:67errx(1, "Usage: server [-h <host>] [-p <port>] [-r] <path>");68}6970path = argv[optind];71rootfd = open(path, O_DIRECTORY);7273if (rootfd < 0)74err(1, "cannot open root directory");7576if (l9p_backend_fs_init(&fs_backend, rootfd, ro) != 0)77err(1, "cannot init backend");7879if (l9p_server_init(&server, fs_backend) != 0)80err(1, "cannot create server");8182server->ls_max_version = L9P_2000L;83if (l9p_start_server(server, host, port))84err(1, "l9p_start_server() failed");8586/* XXX - we never get here, l9p_start_server does not return */87exit(0);88}899091