Browse Source

Automatically close bridges if main Carla dies, macOS edition

tags/v2.4.1
falkTX 3 years ago
parent
commit
15e5b9d17a
2 changed files with 32 additions and 5 deletions
  1. +1
    -1
      source/utils/CarlaMacUtils.cpp
  2. +31
    -4
      source/utils/CarlaProcessUtils.hpp

+ 1
- 1
source/utils/CarlaMacUtils.cpp View File

@@ -31,7 +31,7 @@ CARLA_BACKEND_START_NAMESPACE


void initStandaloneApplication() void initStandaloneApplication()
{ {
[NSApplication sharedApplication];
[[NSApplication sharedApplication] retain];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
} }


+ 31
- 4
source/utils/CarlaProcessUtils.hpp View File

@@ -1,6 +1,6 @@
/* /*
* Carla process utils * Carla process utils
* Copyright (C) 2019-2020 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2019-2021 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
@@ -24,6 +24,10 @@
# include <sys/prctl.h> # include <sys/prctl.h>
#endif #endif


#ifdef CARLA_OS_MAC
# include <dispatch/dispatch.h>
#endif

#ifdef CARLA_OS_HAIKU #ifdef CARLA_OS_HAIKU
typedef __sighandler_t sig_t; typedef __sighandler_t sig_t;
#endif #endif
@@ -49,16 +53,39 @@ void carla_setProcessName(const char* const name) noexcept
#endif #endif
} }


#ifdef CARLA_OS_MAC
static inline
void carla_macOS_proc_exit_handler_kill(void*)
{
carla_stdout("Carla bridge parent has died, killing ourselves now");
::kill(::getpid(), SIGKILL);
}
static inline
void carla_macOS_proc_exit_handler_term(void*)
{
carla_stdout("Carla bridge parent has died, terminating ourselves now");
::kill(::getpid(), SIGTERM);
}
#endif

/* /*
* Set flag to automatically terminate ourselves if parent process dies. * Set flag to automatically terminate ourselves if parent process dies.
*/ */
static inline static inline
void carla_terminateProcessOnParentExit(const bool kill) noexcept void carla_terminateProcessOnParentExit(const bool kill) noexcept
{ {
#ifdef CARLA_OS_LINUX
//
#if defined(CARLA_OS_LINUX)
::prctl(PR_SET_PDEATHSIG, kill ? SIGKILL : SIGTERM); ::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
#elif defined(CARLA_OS_MAC)
const dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC,
::getppid(),
DISPATCH_PROC_EXIT,
nullptr);

dispatch_source_set_event_handler_f(source, kill ? carla_macOS_proc_exit_handler_kill
: carla_macOS_proc_exit_handler_term);

dispatch_resume(source);
#endif #endif


// maybe unused // maybe unused


Loading…
Cancel
Save