1 /* 2 * A resource offering support for creating processes. 3 * 4 * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <fsserver/resource_server.h> 23 #include <systypes/fcntl.h> 24 25 #include "opener_server.h" 26 #include "process_creating.h" 27 #include "process_creator_context_resource.h" 28 #include "process_creator_resource.h" 29 30 31 32 /* Support for creating processes. */ 33 34 ProcessCreatorResource::ProcessCreatorResource(const char *rm_filename) 35 : _creating(rm_filename) 36 { 37 } 38 39 ProcessCreatorResource::~ProcessCreatorResource() 40 { 41 } 42 43 ipc_server_default_config_type ProcessCreatorResource::config() 44 { 45 return config_Opener; 46 } 47 48 49 50 /* ProcessCreator interface methods. */ 51 52 long ProcessCreatorResource::start(int argc, const char *argv[], l4_cap_idx_t *process) 53 { 54 file_t *program_file = client_open(argv[0], O_RDONLY); 55 56 /* Start the new process, obtaining a reference to it. */ 57 58 return _creating.start(program_file, argc, argv, process); 59 } 60 61 /* Opener interface methods. */ 62 63 long ProcessCreatorResource::context(l4_cap_idx_t *context) 64 { 65 ProcessCreatorContextResource *resource = new ProcessCreatorContextResource(this); 66 67 /* Complete the initialisation and start a server in a new thread. 68 If the thread does not start, the resource will be finalised. */ 69 70 return ResourceServer(resource).start_thread(context); 71 } 72 73 // vim: tabstop=4 expandtab shiftwidth=4