paul@483 | 1 | /* |
paul@483 | 2 | * A process server providing a way of creating new processes. |
paul@483 | 3 | * |
paul@483 | 4 | * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> |
paul@483 | 5 | * |
paul@483 | 6 | * This program is free software; you can redistribute it and/or |
paul@483 | 7 | * modify it under the terms of the GNU General Public License as |
paul@483 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@483 | 9 | * the License, or (at your option) any later version. |
paul@483 | 10 | * |
paul@483 | 11 | * This program is distributed in the hope that it will be useful, |
paul@483 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@483 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@483 | 14 | * GNU General Public License for more details. |
paul@483 | 15 | * |
paul@483 | 16 | * You should have received a copy of the GNU General Public License |
paul@483 | 17 | * along with this program; if not, write to the Free Software |
paul@483 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@483 | 19 | * Boston, MA 02110-1301, USA |
paul@483 | 20 | */ |
paul@483 | 21 | |
paul@519 | 22 | #include <l4/sys/debugger.h> |
paul@483 | 23 | #include <l4/sys/err.h> |
paul@483 | 24 | |
paul@527 | 25 | #include <fsclient/client.h> |
paul@483 | 26 | #include <ipc/thread.h> |
paul@483 | 27 | |
paul@483 | 28 | #include <stdio.h> |
paul@483 | 29 | #include <stdlib.h> |
paul@483 | 30 | |
paul@483 | 31 | #include <exec/process_creator_resource.h> |
paul@483 | 32 | #include <fsserver/resource_server.h> |
paul@507 | 33 | #include <systypes/env.h> |
paul@527 | 34 | #include <systypes/fcntl.h> |
paul@483 | 35 | |
paul@483 | 36 | |
paul@483 | 37 | |
paul@483 | 38 | /* Server program. */ |
paul@483 | 39 | |
paul@483 | 40 | int main(int argc, char *argv[]) |
paul@483 | 41 | { |
paul@519 | 42 | l4_debugger_set_object_name(l4re_env()->main_thread, "process_server"); |
paul@519 | 43 | |
paul@483 | 44 | if (argc < 2) |
paul@483 | 45 | { |
paul@483 | 46 | printf("Need a region mapper.\n"); |
paul@483 | 47 | return 1; |
paul@483 | 48 | } |
paul@483 | 49 | |
paul@483 | 50 | char *rm_filename = argv[1]; |
paul@507 | 51 | const char *server_name = (argc > 2) ? argv[2] : ENV_PROCESS_SERVER_NAME; |
paul@483 | 52 | long err; |
paul@483 | 53 | |
paul@483 | 54 | /* Introduce concurrency control. */ |
paul@483 | 55 | |
paul@483 | 56 | err = ipc_thread_init(); |
paul@483 | 57 | |
paul@483 | 58 | if (err) |
paul@483 | 59 | { |
paul@483 | 60 | printf("Initialisation error: %s\n", l4sys_errtostr(err)); |
paul@483 | 61 | return 1; |
paul@483 | 62 | } |
paul@483 | 63 | |
paul@527 | 64 | file_t *rm_file = client_open(rm_filename, O_RDONLY); |
paul@527 | 65 | |
paul@527 | 66 | if (!client_opened(rm_file)) |
paul@527 | 67 | { |
paul@527 | 68 | err = (rm_file == NULL) ? -L4_ENOMEM : rm_file->error; |
paul@527 | 69 | printf("Could not open region mapper file: %s\n", l4sys_errtostr(err)); |
paul@527 | 70 | return 1; |
paul@527 | 71 | } |
paul@527 | 72 | |
paul@527 | 73 | ProcessCreatorResource creator(rm_filename, rm_file); |
paul@483 | 74 | |
paul@483 | 75 | /* Register a server associating it with the given object. */ |
paul@483 | 76 | |
paul@483 | 77 | ResourceServer server(&creator); |
paul@483 | 78 | err = server.bind(server_name); |
paul@483 | 79 | |
paul@483 | 80 | if (err) |
paul@483 | 81 | { |
paul@483 | 82 | printf("Could not bind server: %s\n", l4sys_errtostr(err)); |
paul@483 | 83 | return 1; |
paul@483 | 84 | } |
paul@483 | 85 | |
paul@483 | 86 | printf("Starting server...\n"); |
paul@483 | 87 | server.start(); |
paul@483 | 88 | return 0; |
paul@483 | 89 | } |
paul@483 | 90 | |
paul@483 | 91 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@483 | 92 | */ |