Expose linux call over bridge, so we can set the flag Signed-off-by: falkTX <falktx@falktx.com>tags/v2.1-alpha2
| @@ -29,7 +29,6 @@ | |||||
| #ifdef CARLA_OS_LINUX | #ifdef CARLA_OS_LINUX | ||||
| # include <sched.h> | # include <sched.h> | ||||
| # include <signal.h> | # include <signal.h> | ||||
| # include <sys/prctl.h> | |||||
| # define SCHED_RESET_ON_FORK 0x40000000 | # define SCHED_RESET_ON_FORK 0x40000000 | ||||
| #endif | #endif | ||||
| @@ -442,12 +441,7 @@ int main(int argc, char* argv[]) | |||||
| rtClientBaseName[6] = '\0'; | rtClientBaseName[6] = '\0'; | ||||
| nonRtClientBaseName[6] = '\0'; | nonRtClientBaseName[6] = '\0'; | ||||
| nonRtServerBaseName[6] = '\0'; | nonRtServerBaseName[6] = '\0'; | ||||
| #ifdef CARLA_OS_LINUX | |||||
| // terminate ourselves if main carla dies | |||||
| ::prctl(PR_SET_PDEATHSIG, SIGTERM); | |||||
| // TODO, osx version too, see https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits | |||||
| #endif | |||||
| jackbridge_parent_deathsig(false); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * Carla Bridge UI | * Carla Bridge UI | ||||
| * Copyright (C) 2011-2017 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2011-2019 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * This program is free software; you can redistribute it and/or | * This program is free software; you can redistribute it and/or | ||||
| * modify it under the terms of the GNU General Public License as | * modify it under the terms of the GNU General Public License as | ||||
| @@ -19,13 +19,9 @@ | |||||
| #include "CarlaBridgeToolkit.hpp" | #include "CarlaBridgeToolkit.hpp" | ||||
| #include "CarlaBase64Utils.hpp" | #include "CarlaBase64Utils.hpp" | ||||
| #include "CarlaMIDI.h" | |||||
| #include "CarlaProcessUtils.hpp" | |||||
| // FIXME move this into utils | |||||
| #ifdef CARLA_OS_LINUX | |||||
| # include <signal.h> | |||||
| # include <sys/prctl.h> | |||||
| #endif | |||||
| #include "CarlaMIDI.h" | |||||
| // needed for atom-util | // needed for atom-util | ||||
| #ifndef nullptr | #ifndef nullptr | ||||
| @@ -336,12 +332,7 @@ void CarlaBridgeFormat::exec(const bool showUI) | |||||
| { | { | ||||
| CARLA_SAFE_ASSERT_RETURN(fToolkit != nullptr,); | CARLA_SAFE_ASSERT_RETURN(fToolkit != nullptr,); | ||||
| #ifdef CARLA_OS_LINUX | |||||
| // kill ourselves if main carla dies | |||||
| ::prctl(PR_SET_PDEATHSIG, SIGKILL); | |||||
| // TODO, osx version too, see https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits | |||||
| #endif | |||||
| carla_terminateProcessOnParentExit(true); | |||||
| fToolkit->exec(showUI); | fToolkit->exec(showUI); | ||||
| } | } | ||||
| @@ -407,4 +407,6 @@ JACKBRIDGE_API void jackbridge_shm_close(void* shm) noexcept; | |||||
| JACKBRIDGE_API void* jackbridge_shm_map(void* shm, uint64_t size) noexcept; | JACKBRIDGE_API void* jackbridge_shm_map(void* shm, uint64_t size) noexcept; | ||||
| JACKBRIDGE_API void jackbridge_shm_unmap(void* shm, void* ptr) noexcept; | JACKBRIDGE_API void jackbridge_shm_unmap(void* shm, void* ptr) noexcept; | ||||
| JACKBRIDGE_API void jackbridge_parent_deathsig(bool kill) noexcept; | |||||
| #endif // JACKBRIDGE_HPP_INCLUDED | #endif // JACKBRIDGE_HPP_INCLUDED | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * JackBridge (Part 2, Semaphore + Shared memory functions) | |||||
| * Copyright (C) 2013-2015 Filipe Coelho <falktx@falktx.com> | |||||
| * JackBridge (Part 2, Semaphore + Shared memory and other misc functions) | |||||
| * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
| * or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -19,6 +19,7 @@ | |||||
| #ifdef JACKBRIDGE_DUMMY | #ifdef JACKBRIDGE_DUMMY | ||||
| # include "CarlaUtils.hpp" | # include "CarlaUtils.hpp" | ||||
| #else | #else | ||||
| # include "CarlaProcessUtils.hpp" | |||||
| # include "CarlaSemUtils.hpp" | # include "CarlaSemUtils.hpp" | ||||
| # include "CarlaShmUtils.hpp" | # include "CarlaShmUtils.hpp" | ||||
| #endif // ! JACKBRIDGE_DUMMY | #endif // ! JACKBRIDGE_DUMMY | ||||
| @@ -135,3 +136,12 @@ void jackbridge_shm_unmap(void* shm, void* ptr) noexcept | |||||
| } | } | ||||
| // ----------------------------------------------------------------------------- | // ----------------------------------------------------------------------------- | ||||
| void jackbridge_parent_deathsig(bool kill) noexcept | |||||
| { | |||||
| #ifndef JACKBRIDGE_DUMMY | |||||
| carla_terminateProcessOnParentExit(kill); | |||||
| #endif | |||||
| } | |||||
| // ----------------------------------------------------------------------------- | |||||
| @@ -137,6 +137,7 @@ const JackBridgeExportedFunctions* JACKBRIDGE_API jackbridge_get_exported_functi | |||||
| funcs.shm_close_ptr = jackbridge_shm_close; | funcs.shm_close_ptr = jackbridge_shm_close; | ||||
| funcs.shm_map_ptr = jackbridge_shm_map; | funcs.shm_map_ptr = jackbridge_shm_map; | ||||
| funcs.shm_unmap_ptr = jackbridge_shm_unmap; | funcs.shm_unmap_ptr = jackbridge_shm_unmap; | ||||
| funcs.parent_deathsig_ptr = jackbridge_parent_deathsig; | |||||
| funcs.unique1 = funcs.unique2 = funcs.unique3 = 0xdeadf00d; | funcs.unique1 = funcs.unique2 = funcs.unique3 = 0xdeadf00d; | ||||
| @@ -588,4 +588,9 @@ void jackbridge_shm_unmap(void* shm, void* ptr) noexcept | |||||
| return getBridgeInstance().shm_unmap_ptr(shm, ptr); | return getBridgeInstance().shm_unmap_ptr(shm, ptr); | ||||
| } | } | ||||
| void jackbridge_parent_deathsig(bool kill) noexcept | |||||
| { | |||||
| return getBridgeInstance().parent_deathsig_ptr(kill); | |||||
| } | |||||
| // ----------------------------------------------------------------------------- | // ----------------------------------------------------------------------------- | ||||
| @@ -120,6 +120,7 @@ typedef void (JACKBRIDGE_API *jackbridgesym_shm_attach)(void*, const char*); | |||||
| typedef void (JACKBRIDGE_API *jackbridgesym_shm_close)(void*); | typedef void (JACKBRIDGE_API *jackbridgesym_shm_close)(void*); | ||||
| typedef void* (JACKBRIDGE_API *jackbridgesym_shm_map)(void*, uint64_t); | typedef void* (JACKBRIDGE_API *jackbridgesym_shm_map)(void*, uint64_t); | ||||
| typedef void (JACKBRIDGE_API *jackbridgesym_shm_unmap)(void*, void*); | typedef void (JACKBRIDGE_API *jackbridgesym_shm_unmap)(void*, void*); | ||||
| typedef void (JACKBRIDGE_API *jackbridgesym_parent_deathsig)(bool); | |||||
| // ----------------------------------------------------------------------------- | // ----------------------------------------------------------------------------- | ||||
| @@ -226,6 +227,7 @@ struct _JackBridgeExportedFunctions { | |||||
| jackbridgesym_shm_close shm_close_ptr; | jackbridgesym_shm_close shm_close_ptr; | ||||
| jackbridgesym_shm_map shm_map_ptr; | jackbridgesym_shm_map shm_map_ptr; | ||||
| jackbridgesym_shm_unmap shm_unmap_ptr; | jackbridgesym_shm_unmap shm_unmap_ptr; | ||||
| jackbridgesym_parent_deathsig parent_deathsig_ptr; | |||||
| ulong unique3; | ulong unique3; | ||||
| }; | }; | ||||
| @@ -146,7 +146,7 @@ public: | |||||
| carla_unsetenv("CARLA_SHM_IDS"); | carla_unsetenv("CARLA_SHM_IDS"); | ||||
| // kill ourselves if main carla dies | // kill ourselves if main carla dies | ||||
| ::prctl(PR_SET_PDEATHSIG, SIGKILL); | |||||
| carla_terminateProcessOnParentExit(true); | |||||
| for (int i=4; --i >= 0;) { | for (int i=4; --i >= 0;) { | ||||
| CARLA_SAFE_ASSERT_RETURN(libjackSetup[i] >= '0' && libjackSetup[i] <= '0'+64,); | CARLA_SAFE_ASSERT_RETURN(libjackSetup[i] >= '0' && libjackSetup[i] <= '0'+64,); | ||||
| @@ -16,6 +16,7 @@ | |||||
| */ | */ | ||||
| #include "CarlaPipeUtils.hpp" | #include "CarlaPipeUtils.hpp" | ||||
| #include "CarlaProcessUtils.hpp" | |||||
| #include "CarlaString.hpp" | #include "CarlaString.hpp" | ||||
| #include "CarlaMIDI.h" | #include "CarlaMIDI.h" | ||||
| @@ -1763,10 +1764,7 @@ bool CarlaPipeClient::initPipeClient(const char* argv[]) noexcept | |||||
| //---------------------------------------------------------------- | //---------------------------------------------------------------- | ||||
| // kill ourselves if parent dies | // kill ourselves if parent dies | ||||
| # ifdef CARLA_OS_LINUX | |||||
| ::prctl(PR_SET_PDEATHSIG, SIGKILL); | |||||
| // TODO, osx version too, see https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits | |||||
| # endif | |||||
| carla_terminateProcessOnParentExit(false); | |||||
| #endif | #endif | ||||
| //---------------------------------------------------------------- | //---------------------------------------------------------------- | ||||
| @@ -0,0 +1,62 @@ | |||||
| /* | |||||
| * Carla process utils | |||||
| * Copyright (C) 2019 Filipe Coelho <falktx@falktx.com> | |||||
| * | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License as | |||||
| * published by the Free Software Foundation; either version 2 of | |||||
| * the License, or any later version. | |||||
| * | |||||
| * This program is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * For a full copy of the GNU General Public License see the doc/GPL.txt file. | |||||
| */ | |||||
| #ifndef CARLA_PROCESS_UTILS_HPP_INCLUDED | |||||
| #define CARLA_PROCESS_UTILS_HPP_INCLUDED | |||||
| #include "CarlaUtils.hpp" | |||||
| #ifdef CARLA_OS_LINUX | |||||
| # include <signal.h> | |||||
| # include <sys/prctl.h> | |||||
| #endif | |||||
| // -------------------------------------------------------------------------------------------------------------------- | |||||
| // process functions | |||||
| /* | |||||
| * Set current process name. | |||||
| */ | |||||
| static inline | |||||
| void carla_setProcessName(const char* const name) noexcept | |||||
| { | |||||
| CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); | |||||
| #ifdef CARLA_OS_LINUX | |||||
| ::prctl(PR_SET_NAME, name, 0, 0, 0); | |||||
| #endif | |||||
| } | |||||
| /* | |||||
| * Set flag to automatically terminate ourselves if parent process dies. | |||||
| */ | |||||
| static inline | |||||
| void carla_terminateProcessOnParentExit(const bool kill) noexcept | |||||
| { | |||||
| #ifdef CARLA_OS_LINUX | |||||
| // | |||||
| ::prctl(PR_SET_PDEATHSIG, kill ? SIGKILL : SIGTERM); | |||||
| // TODO, osx version too, see https://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-parent-exits | |||||
| #endif | |||||
| // maybe unused | |||||
| return; (void)kill; | |||||
| } | |||||
| // -------------------------------------------------------------------------------------------------------------------- | |||||
| #endif // CARLA_PROCESS_UTILS_HPP_INCLUDED | |||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * Carla Thread | * Carla Thread | ||||
| * Copyright (C) 2013-2016 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * This program is free software; you can redistribute it and/or | * This program is free software; you can redistribute it and/or | ||||
| * modify it under the terms of the GNU General Public License as | * modify it under the terms of the GNU General Public License as | ||||
| @@ -20,6 +20,7 @@ | |||||
| #include "CarlaMutex.hpp" | #include "CarlaMutex.hpp" | ||||
| #include "CarlaString.hpp" | #include "CarlaString.hpp" | ||||
| #include "CarlaProcessUtils.hpp" | |||||
| #ifdef CARLA_OS_LINUX | #ifdef CARLA_OS_LINUX | ||||
| # include <sys/prctl.h> | # include <sys/prctl.h> | ||||
| @@ -241,9 +242,7 @@ public: | |||||
| { | { | ||||
| CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); | CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); | ||||
| #ifdef CARLA_OS_LINUX | |||||
| prctl(PR_SET_NAME, name, 0, 0, 0); | |||||
| #endif | |||||
| carla_setProcessName(name); | |||||
| #if defined(__GLIBC__) && (__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2012 && !defined(CARLA_OS_GNU_HURD) | #if defined(__GLIBC__) && (__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2012 && !defined(CARLA_OS_GNU_HURD) | ||||
| pthread_setname_np(pthread_self(), name); | pthread_setname_np(pthread_self(), name); | ||||
| #endif | #endif | ||||