Browse Source

Terminate wine bridges if main carla dies

Expose linux call over bridge, so we can set the flag

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.1-alpha2
falkTX 6 years ago
parent
commit
46dd075303
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
11 changed files with 95 additions and 31 deletions
  1. +1
    -7
      source/bridges-plugin/CarlaBridgePlugin.cpp
  2. +4
    -13
      source/bridges-ui/CarlaBridgeFormat.cpp
  3. +2
    -0
      source/jackbridge/JackBridge.hpp
  4. +12
    -2
      source/jackbridge/JackBridge2.cpp
  5. +1
    -0
      source/jackbridge/JackBridge3.cpp
  6. +5
    -0
      source/jackbridge/JackBridgeExport.cpp
  7. +2
    -0
      source/jackbridge/JackBridgeExport.hpp
  8. +1
    -1
      source/libjack/libjack.cpp
  9. +2
    -4
      source/utils/CarlaPipeUtils.cpp
  10. +62
    -0
      source/utils/CarlaProcessUtils.hpp
  11. +3
    -4
      source/utils/CarlaThread.hpp

+ 1
- 7
source/bridges-plugin/CarlaBridgePlugin.cpp View File

@@ -29,7 +29,6 @@
#ifdef CARLA_OS_LINUX
# include <sched.h>
# include <signal.h>
# include <sys/prctl.h>
# define SCHED_RESET_ON_FORK 0x40000000
#endif

@@ -442,12 +441,7 @@ int main(int argc, char* argv[])
rtClientBaseName[6] = '\0';
nonRtClientBaseName[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
{


+ 4
- 13
source/bridges-ui/CarlaBridgeFormat.cpp View File

@@ -1,6 +1,6 @@
/*
* 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
* modify it under the terms of the GNU General Public License as
@@ -19,13 +19,9 @@
#include "CarlaBridgeToolkit.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
#ifndef nullptr
@@ -336,12 +332,7 @@ void CarlaBridgeFormat::exec(const bool showUI)
{
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);
}



+ 2
- 0
source/jackbridge/JackBridge.hpp View File

@@ -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_unmap(void* shm, void* ptr) noexcept;

JACKBRIDGE_API void jackbridge_parent_deathsig(bool kill) noexcept;

#endif // JACKBRIDGE_HPP_INCLUDED

+ 12
- 2
source/jackbridge/JackBridge2.cpp View File

@@ -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
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -19,6 +19,7 @@
#ifdef JACKBRIDGE_DUMMY
# include "CarlaUtils.hpp"
#else
# include "CarlaProcessUtils.hpp"
# include "CarlaSemUtils.hpp"
# include "CarlaShmUtils.hpp"
#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
}

// -----------------------------------------------------------------------------

+ 1
- 0
source/jackbridge/JackBridge3.cpp View File

@@ -137,6 +137,7 @@ const JackBridgeExportedFunctions* JACKBRIDGE_API jackbridge_get_exported_functi
funcs.shm_close_ptr = jackbridge_shm_close;
funcs.shm_map_ptr = jackbridge_shm_map;
funcs.shm_unmap_ptr = jackbridge_shm_unmap;
funcs.parent_deathsig_ptr = jackbridge_parent_deathsig;

funcs.unique1 = funcs.unique2 = funcs.unique3 = 0xdeadf00d;



+ 5
- 0
source/jackbridge/JackBridgeExport.cpp View File

@@ -588,4 +588,9 @@ void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
return getBridgeInstance().shm_unmap_ptr(shm, ptr);
}

void jackbridge_parent_deathsig(bool kill) noexcept
{
return getBridgeInstance().parent_deathsig_ptr(kill);
}

// -----------------------------------------------------------------------------

+ 2
- 0
source/jackbridge/JackBridgeExport.hpp View File

@@ -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_map)(void*, uint64_t);
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_map shm_map_ptr;
jackbridgesym_shm_unmap shm_unmap_ptr;
jackbridgesym_parent_deathsig parent_deathsig_ptr;
ulong unique3;
};



+ 1
- 1
source/libjack/libjack.cpp View File

@@ -146,7 +146,7 @@ public:
carla_unsetenv("CARLA_SHM_IDS");

// kill ourselves if main carla dies
::prctl(PR_SET_PDEATHSIG, SIGKILL);
carla_terminateProcessOnParentExit(true);

for (int i=4; --i >= 0;) {
CARLA_SAFE_ASSERT_RETURN(libjackSetup[i] >= '0' && libjackSetup[i] <= '0'+64,);


+ 2
- 4
source/utils/CarlaPipeUtils.cpp View File

@@ -16,6 +16,7 @@
*/

#include "CarlaPipeUtils.hpp"
#include "CarlaProcessUtils.hpp"
#include "CarlaString.hpp"
#include "CarlaMIDI.h"

@@ -1763,10 +1764,7 @@ bool CarlaPipeClient::initPipeClient(const char* argv[]) noexcept
//----------------------------------------------------------------
// 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

//----------------------------------------------------------------


+ 62
- 0
source/utils/CarlaProcessUtils.hpp View File

@@ -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

+ 3
- 4
source/utils/CarlaThread.hpp View File

@@ -1,6 +1,6 @@
/*
* 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
* modify it under the terms of the GNU General Public License as
@@ -20,6 +20,7 @@

#include "CarlaMutex.hpp"
#include "CarlaString.hpp"
#include "CarlaProcessUtils.hpp"

#ifdef CARLA_OS_LINUX
# include <sys/prctl.h>
@@ -241,9 +242,7 @@ public:
{
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)
pthread_setname_np(pthread_self(), name);
#endif


Loading…
Cancel
Save