Kernel: using sigqueue-functions
<p>I try to implement a signal call from a loadable kernel module to a user application. The application uses <code>sigaction</code> to handle the signal call and later it shall use <code>sival_int</code> to handle different actions by <code>switch</code>and <code>case</code>.</p>

<pre><code>void signalHandler_function (int signum,
                             siginfo_t *siginfo,
                             void *ucontext)
{
   printf("signum: %i\n", signum);
   printf("sigval: %d\n", siginfo-&gt;si_value.sival_int);
}

int main(){
   int ret;
   int pid = getpid();
   char pidc[4];
   struct sigaction sig;

   memcpy(pidc,&amp;pid,4);

   // configure signal handler
   sig.sa_flags = SA_SIGINFO;
   sig.sa_sigaction = signalHandler_function;
   sigaction(SIGIO, &amp;sig, NULL);

   g_fdCharDev = open(EXPDEV_DEVPATHNAME, O_RDWR);

   printf("My process ID : %d\n", pid);
   ret = write(g_fdCharDev, &amp;pid, 1);
   ...
}
</code></pre>

<p>On kernel side I try to use <code>send_sigqueue()</code> (together with <code>sigqueue_alloc()</code>and <code>sigqueue_free()</code>). This is declared in <a href="http://lxr.free-electrons.com/source/include/linux/sched.h?v=3.16#L2320" rel="nofollow">include/linux/sched.h, line 2320</a> as <code>extern</code> and defined in <a href="http://lxr.free-electrons.com/source/kernel/signal.c?v=3.16#L1560" rel="nofollow">kernel/signal.c, line 1560</a>. But the linker says this functions are undefined:</p>

<pre><code>make -C /lib/modules/3.19.0-58-generic/build/ M=/home/alex/git/Kernel3/SignalHandling modules
make[1]: Verzeichnis »/usr/src/linux-headers-3.19.0-58-generic« wird betreten
  CC [M]  /home/alex/git/Kernel3/SignalHandling/ExpDev.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "sigqueue_free" [/home/alex/git/Kernel3/SignalHandling/ExpDev.ko] undefined!
WARNING: "sigqueue_alloc" [/home/alex/git/Kernel3/SignalHandling/ExpDev.ko] undefined!
WARNING: "send_sigqueue" [/home/alex/git/Kernel3/SignalHandling/ExpDev.ko] undefined!
  CC      /home/alex/git/Kernel3/SignalHandling/ExpDev.mod.o
  LD [M]  /home/alex/git/Kernel3/SignalHandling/ExpDev.ko
make[1]: Verzeichnis »/usr/src/linux-headers-3.19.0-58-generic« wird verlassen
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
</code></pre>

<p>Here comes the shortened source of the LKM:</p>

<pre><code>#include &lt;linux/init.h&gt;   /// Macros used to mark up functions e.g. __init __exit
#include &lt;linux/module.h&gt; /// Core header for loading LKMs into the kernel
#include &lt;linux/device.h&gt; /// Header to support the kernel Driver Model
#include &lt;linux/kernel.h&gt; /// Contains types, macros, functions for the kernel
#include &lt;linux/fs.h&gt;     /// Header for the Linux file system support
#include &lt;asm/uaccess.h&gt;  /// Required for the copy to user function
#include &lt;linux/signal.h&gt;
#include &lt;linux/sched.h&gt;
#include &lt;linux/rcupdate.h&gt;
#include &lt;linux/slab.h&gt;

struct siginfo *g_sig_info;
static struct sigqueue *g_sigqueue;
int g_usp_pid;
struct task_struct *g_sig_task;

static int __init expdev_init(void)
{
  ...
  // setup signal
  g_sigqueue = sigqueue_alloc();
  g_sigqueue-&gt;info.si_signo = SIGIO;
  g_sigqueue-&gt;info.si_signo = SI_QUEUE;
  g_sigqueue-&gt;info.si_errno = 0;
  ...
}

static void __exit expdev_exit(void)
{
  sigqueue_free(g_sigqueue);
  ...
}

static ssize_t dev_write(struct file *filep,
                         const char *buffer,
                         size_t len,
                         loff_t *offset)
{
  ...
  memcpy(&amp;g_usp_pid,buffer,4); // we know the PID comes with the buffer

  // find task to the given PID
  rcu_read_lock();
  g_sig_task = pid_task(find_pid_ns(g_usp_pid, &amp;init_pid_ns),
                        PIDTYPE_PID);

  //send signal to user land
  g_sigqueue-&gt;info.si_value.sival_int = 33;
  ret = send_sigqueue(g_sigqueue, g_sig_task, 0);
  ...
}
</code></pre>

<p>Why it isn't linkable? Is my approach wrong?</p>