Cocoa App Plug

My problem is not the best fork () script. However, this is the best feature I can get.

I am working on a Firefox plugin on Mac OSX. To make it reliable, I need to create a new process to run my plugin. The problem is that when I forked a new process, like this:

if (fork() == 0) exit(other_main());

However, since the state is not cleared, I cannot correctly initialize my new process (call NSApplicationLoad, etc.). Any ideas? BTW, of course, I do not want to create a new binary file and execute it.

+5
source share
3 answers

In general, you need exec() after fork() on Mac OS X.

On the fork(2) page:

There are restrictions on what you can do in the child process. To be completely safe, you must limit yourself to only performing safe operations on the asynchronous signal until one of the exec functions is called. All APIs, including global data characters, in any structure or library should be considered unsafe after fork (), unless explicitly documented, to be safe or safe for an asynchronous signal. If you need to use these frameworks in a child process, you must run the command. In this situation, it is wise to fulfill oneself.

TN2083 also comments on this subject:

Many Mac OS X frameworks do not work reliably if you call fork , but you don't call exec . The only exception is the system environment, and even there the POSIX standard creates severe restrictions on what you can do between fork and exec.

IMPORTANT: In fact, on Mac OS X 10.5 and later, the Core Foundation will detect this situation and print the warning message shown in Listing 13.

Code Listing 13: Core Foundation complains about fork-without-exec

The process is forked and you cannot safely use this CoreFoundation functionality. You MUST execute exec (). Break __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() for debugging.

+3
source

fork without exec is basically unsafe on OSX. For example, you end up with legacy mach ports.

+2
source

I am writing a FreeWRL plugin for Firefox (currently Linux, Mac and Windows).

http://freewrl.sourceforge.net/

It is based on fork + exec to run FreeWRL and learn its window in Firefox.

You will need to use the channel to properly handle a possible fork + exec failure or your child process to crash:

How to handle execvp (...) errors after fork ()?

Cheers, C

0
source

Source: https://habr.com/ru/post/948601/


All Articles