#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#define MIN_SLEEP_TIME 10
#define MAX_SLEEP_TIME 100
void random_sleep()
{
int sleep_time = (rand() % (MAX_SLEEP_TIME - MIN_SLEEP_TIME + 1)) + MIN_SLEEP_TIME;
usleep(sleep_time * 1000);
}
pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t rtnl_mutex = PTHREAD_MUTEX_INITIALIZER;
int is_rtnl_locked = 0;
int mylock_locked = 0;
void rtnl_lock()
{
pthread_mutex_lock(&rtnl_mutex);
is_rtnl_locked = 1;
}
void rtnl_unlock()
{
is_rtnl_locked = 0;
pthread_mutex_unlock(&rtnl_mutex);
}
void mylock_lock()
{
pthread_mutex_lock(&mylock);
mylock_locked = 1;
}
void mylock_unlock()
{
mylock_locked = 0;
pthread_mutex_unlock(&mylock);
}
int is_mylock_locked()
{
return mylock_locked;
}
void wifi_open()
{
if (is_mylock_locked() && is_rtnl_locked)
{
rtnl_unlock();
printf("main wireless device up\n");
sleep(1);
rtnl_lock();
}
}
void devinet_ioctl(int iswireless)
{
if (iswireless)
{
mylock_lock();
}
rtnl_lock();
if (iswireless)
{
wifi_open();
}
rtnl_unlock();
if (iswireless)
{
mylock_unlock();
}
}
void wireless_process_ioctl()
{
mylock_lock();
rtnl_lock();
wifi_open();
rtnl_unlock();
mylock_unlock();
}
void *wireless_ioctl(void *arg)
{
int count = 0;
while (1)
{
wireless_process_ioctl();
printf("[1] wireless_ioctl, %d\n", count++);
random_sleep();
}
return NULL;
}
void *wireless_ifconfig_up(void *arg)
{
int count = 0;
while (1)
{
devinet_ioctl(1);
printf("[2] wireless_ifconfig_up, %d\n", count++);
random_sleep();
}
return NULL;
}
void *other_ifconfig_up(void *arg)
{
int count = 0;
while (1)
{
devinet_ioctl(0);
printf("[3] other_ifconfig_up, %d\n", count++);
random_sleep();
}
return NULL;
}
int main(int argc, char *argv[])
{
srand(time(0)); // 初始化隨機種子
pthread_t th;
pthread_create(&th, NULL, wireless_ifconfig_up, NULL);
pthread_create(&th, NULL, other_ifconfig_up, NULL);
wireless_ioctl(NULL);
return 0;
}
ifconfig Call Trace:
[<80016034>] show_stack+0x88/0xa4
[<808795a8>] dump_stack+0x6c/0x8c
[<80538218>] MtCmdEfusBufferModeSet+0x70/0x2a4
[<80490db0>] NICReadEEPROMParameters+0x1a8/0xa74
[<804a889c>] WfEPROMSysInit+0x3c/0xe0
[<803f9f1c>] WfEPROMInit+0x18/0x64
[<803fa030>] WfInit+0xa8/0x20c
[<804ac01c>] mt_wifi_init+0x324/0x600
[<805fa358>] mt_wifi_open+0x110/0x2ac
[<805fa54c>] virtual_if_init_handler+0x58/0xdc
[<80401b74>] RTMP_COM_IoctlHandle+0x604/0x1684
[<805f9e78>] main_virtual_if_open+0xb8/0x1ec
[<806f7d2c>] __dev_open+0xec/0x15c
[<806f804c>] __dev_change_flags+0xa0/0x184
[<806f815c>] dev_change_flags+0x24/0x68
[<807aa6e8>] devinet_ioctl+0x808/0x8a0
[<806d75b4>] sock_ioctl+0xa4/0x374
[<801144f4>] do_vfs_ioctl+0xa0/0x6d4
[<80114bcc>] SyS_ioctl+0xa4/0xb8
[<8001c464>] handle_sys+0x124/0x144
iwpriv Call Trace:
[<80016034>] show_stack+0x88/0xa4
[<808795a8>] dump_stack+0x6c/0x8c
[<80374598>] rt28xx_ap_ioctl+0x538/0xa10
[<805f9a30>] rt28xx_ioctl+0x60/0xb0
[<80871e14>] wext_handle_ioctl+0x200/0x28c
[<8070d61c>] dev_ioctl+0x104/0x698
[<801144f4>] do_vfs_ioctl+0xa0/0x6d4
[<80114bcc>] SyS_ioctl+0xa4/0xb8
[<8001c464>] handle_sys+0x124/0x144
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者