Handling signals in D
    Basile B 
    b2.temp at gmx.com
       
    Wed Dec 26 09:35:30 UTC 2018
    
    
  
On Wednesday, 26 December 2018 at 03:19:45 UTC, Norbert Preining 
wrote:
> Hello everyone,
> we are writing a program that synchronizes the OneDrive cloud 
> service with the local computer, and run it as daemon in the 
> background. To ensure proper database shutdown on exit, we need 
> to install signal handlers that react to SIGINT etc.
>
> [...]
> 
> Now, unfortunately the call to the shutdown procedure is not 
> possible in `@nogc`, so I am a bit at loss how to deal with all 
> this.
>
> The code I am using is:
> ```
> extern(C) @nogc @system void exitHandler(int value) {
>        printf("Ooohhhh got %d\n", value);
>        // workaround for segfault in 
> std.net.curl.Curl.shutdown() on exit
>        oneDrive.http.shutdown();
>        exit(0);
> }
> ```
> and in `main` before entering the loop:
> ```
> signal(SIGINT, &exitHandler);
> ```
>
> Any suggestion would be very much appreciated.
>
> Norbert
The technique to use here is to wrap the non-gc code in a 
delegate, cast it as a @nogc delegate and call it, see [1] for 
more details.
[1] https://p0nce.github.io/d-idioms/#Bypassing-@nogc
    
    
More information about the Digitalmars-d-learn
mailing list