Hello everyone,
I am trying to communicate and receive a message from kernel module when a condition occurs.
I am using Ubuntu 8.04
KERNEL MODULE CODE:
Quote:
..
static pid_t id;
int result;
..
int network_response()
{
...
...
if (x = 1)
{
printk("Failure of network.")
result = kill_proc(id, SIGUSR1,1);
printk("\nReporting failure detection %d\n", result);
}
if (x = 2)
{
printk("Failure of Node is detected.")
result = kill_proc(id, SIGUSR1,1);
printk("\nReporting failure detection %d\n", result);
}
}
|
And user APplication code (Sorry pasting full code because i have confusion here):
Quote:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <linux/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "safe_def.h"
#include "pmn.h"
int sig;
void usrSignal(int signo);
int main (void){
welcome_msg();
pid_t id;
int quit =1;
(void)signal(SIGUSR1, usrSignal);
printf ("Caught the user Signal %d\n",sig);
id = getpid();
// gSafeSock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW);
//ioctl (gSafeSock, SIOCGIFFLAGS, &id);
//int result = (void)signal(SIGUSR1, usrSignal);
//ioctl (result, SIOCGIFFLAGS, &id);
ioctl (SIOCGIFFLAGS, &id);
sig = printf("\nMy PID is : %d\n\n", id);
safe_module_connect();
safe_module_get_host_info();
safe_module_get_net_info();
while (quit) {
if (sig < 0){
printf("Exit Program %d", sig);
quit = 0;
}
}
return 0;
}
void usrSignal(int signo) {
sig = signo;
printf("Function usrSignal Called");
if (sig == SIGUSR1)
printf("Received SIGUSR1 successfully\n");
else
printf("Error: In Receieving Signal %d\n", sig);
(void)signal(SIGUSR1, usrSignal);
return ;
}
|
Can you please tell me that What i have to do in order to receive signals from Kernel module, because in that way i am unable to get reply..
or if any thing i am missing in my implementation then please notify it to me..
I am a newbie so sorry if my code or explanation is not so good..
Sindhu