Skip to content

runtime: -buildmode=c-shared generated code hijack's signals from main program #11794

@GeertJohan

Description

@GeertJohan

It looks like a shared object created with -buildmode=c-shared "hijack's" signal handling away from the main program.

I'm experimenting with Go shared objects as plugins. The main process has signal handling implemented to do graceful shutdown. However, the main program does not receive signals anymore after a Go shared object was loaded.

I would expect the main program to receive (and handle) the signals. Instead, signals are completely ignored. It requires SIGKILL to kill the process.

Simple code to reproduce:

main.go:

package main

func init() {}

func main() {}

_main.c:

#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

int main() {
    void *plugin;
    plugin = dlopen("./gopkg.so", RTLD_NOW);
    if (!plugin) {
         exit(1);
    }

    while(1) {
        sleep(1);
    }

    return 0;
}

run:

go build -buildmode c-shared -o gopkg.so
gcc -o main _main.c -ldl
./main
ctrl-c

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions