paul@483 | 1 | /* |
paul@483 | 2 | * A resource offering support for creating 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@491 | 22 | #include <fsserver/resource_server.h> |
paul@483 | 23 | |
paul@491 | 24 | #include "opener_server.h" |
paul@483 | 25 | #include "process_creating.h" |
paul@491 | 26 | #include "process_creator_context_resource.h" |
paul@483 | 27 | #include "process_creator_resource.h" |
paul@483 | 28 | |
paul@483 | 29 | |
paul@483 | 30 | |
paul@483 | 31 | /* Support for creating processes. */ |
paul@483 | 32 | |
paul@527 | 33 | ProcessCreatorResource::ProcessCreatorResource(const char *rm_filename, file_t *rm_file) |
paul@527 | 34 | : _creating(rm_filename, rm_file) |
paul@483 | 35 | { |
paul@483 | 36 | } |
paul@483 | 37 | |
paul@483 | 38 | ProcessCreatorResource::~ProcessCreatorResource() |
paul@483 | 39 | { |
paul@483 | 40 | } |
paul@483 | 41 | |
paul@483 | 42 | ipc_server_default_config_type ProcessCreatorResource::config() |
paul@483 | 43 | { |
paul@491 | 44 | return config_Opener; |
paul@483 | 45 | } |
paul@483 | 46 | |
paul@483 | 47 | |
paul@483 | 48 | |
paul@483 | 49 | /* ProcessCreator interface methods. */ |
paul@483 | 50 | |
paul@505 | 51 | /* Start the new process, obtaining a reference to it. */ |
paul@505 | 52 | |
paul@491 | 53 | long ProcessCreatorResource::start(int argc, const char *argv[], l4_cap_idx_t *process) |
paul@483 | 54 | { |
paul@505 | 55 | return _creating.start(argc, argv, process); |
paul@491 | 56 | } |
paul@491 | 57 | |
paul@505 | 58 | |
paul@505 | 59 | |
paul@491 | 60 | /* Opener interface methods. */ |
paul@491 | 61 | |
paul@505 | 62 | /* Return a context, through which program arguments must be communicated. */ |
paul@505 | 63 | |
paul@491 | 64 | long ProcessCreatorResource::context(l4_cap_idx_t *context) |
paul@491 | 65 | { |
paul@491 | 66 | ProcessCreatorContextResource *resource = new ProcessCreatorContextResource(this); |
paul@491 | 67 | |
paul@491 | 68 | /* Complete the initialisation and start a server in a new thread. |
paul@491 | 69 | If the thread does not start, the resource will be finalised. */ |
paul@491 | 70 | |
paul@491 | 71 | return ResourceServer(resource).start_thread(context); |
paul@483 | 72 | } |
paul@483 | 73 | |
paul@483 | 74 | // vim: tabstop=4 expandtab shiftwidth=4 |