From f419fa900c751b765210829397deea331bf34796 Mon Sep 17 00:00:00 2001 From: dchansen06 Date: Fri, 20 Dec 2024 15:33:10 -0800 Subject: [PATCH] Fix things --- src/client_functions.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/client_functions.cpp b/src/client_functions.cpp index fb2fb9f..32461ba 100644 --- a/src/client_functions.cpp +++ b/src/client_functions.cpp @@ -41,10 +41,21 @@ int getInformation(string& path, string& dir, int argc, char* argv[]) int setupServer(string path, string directory) { - int server = fork(); + pid_t server = fork(); + + if (server == 0) { + pid_t sid = setsid(); + + if (sid < 0) { + cerr << "Failed to start server! Could not setsid\n"; + exit(-1); + } - if (server == 0) execl(path.c_str(), path.c_str(), directory.c_str(), nullptr); + } else if (server < 0) { + cerr << "Failed to start server! Could not fork\n"; + exit(-1); + } return server; }