将对getpwdnam的调用仅在sys_nicmonitor程序中调用一次,并将其取得的
主目录路径名存储在共享内存。之后每次调用get_nic_info时,再获取该值 时,只需从共享内存中读出,而不再需要调用getpwdnam函数。
This commit is contained in:
@@ -344,6 +344,7 @@ static void init_sem(int *semid, CONFIG_FILE_ST *ptr)
|
||||
}
|
||||
|
||||
static int global_share_id = -1;
|
||||
static int dir_share_id -1;
|
||||
static void *global_shmptr = NULL;
|
||||
|
||||
static void init_shm(SHM **ptr, CONFIG_FILE_ST *p)
|
||||
@@ -1076,6 +1077,7 @@ void sig_handler(int sig)
|
||||
// record_log(err_str);
|
||||
semctl(semid,0,IPC_RMID,0);
|
||||
shmctl(global_share_id,IPC_RMID,NULL);
|
||||
shmctl(dir_share_id,IPC_RMID,NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -1500,7 +1502,9 @@ int main(int argc, char ** argv)
|
||||
proc_invocation prcm;
|
||||
#endif
|
||||
char log_record[125]={0};
|
||||
|
||||
char *dir_memory;
|
||||
int shm_key =0x1d6010;
|
||||
|
||||
if( getenv("SYS_NIC_DEBUG") ) {
|
||||
sys_nic_debug = 1;
|
||||
}
|
||||
@@ -1535,6 +1539,13 @@ int main(int argc, char ** argv)
|
||||
sprintf(conf_path,"%s",user->pw_dir);
|
||||
}
|
||||
|
||||
dir_share_id = shmget(shm_key,128,IPC_CREAT|IPC_EXCL|0666);
|
||||
if(dir_share_id == -1)
|
||||
return -1;
|
||||
dir_memory = (char *) shmat(dir_share_id,NULL,0);
|
||||
if(dir_memory == (void *) -1)
|
||||
return -1;
|
||||
strcpy(dir_memory,user->pw_dir);
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
|
||||
@@ -291,11 +291,13 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
int i,ret;
|
||||
time_t tamp;
|
||||
struct tm tmptr;
|
||||
DIR *dir;
|
||||
char *s;
|
||||
char buf[128];
|
||||
char err_str[200];
|
||||
struct passwd *user;
|
||||
int shm_id;
|
||||
int shm_key = 0x1d6010;
|
||||
char *shm_buff;
|
||||
#if 0
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: get nicinfo:%s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
@@ -303,11 +305,17 @@ int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
tamp = time(NULL);
|
||||
localtime_r(&tamp, &tmptr);
|
||||
|
||||
if((user = getpwnam("d5000"))!= NULL){
|
||||
sprintf(log_path,"%s",user->pw_dir);
|
||||
sprintf(shm_path,"%s",user->pw_dir);
|
||||
sprintf(sem_path,"%s",user->pw_dir);
|
||||
}
|
||||
shm_id = shmget(shm_key,128,0666);
|
||||
if(shm_id < 0) return -1;
|
||||
shm_buf = (char *)shmat(shm_id,NULL,0);
|
||||
if(shm_buf == (void *) -1) return -1;
|
||||
|
||||
sprintf(log_path,"%s",shm_buf);
|
||||
sprintf(shm_path,"%s",shm_buf);
|
||||
sprintf(sem_path,"%s",shm_buf);
|
||||
|
||||
shmdt(shm_buf);
|
||||
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
|
||||
Reference in New Issue
Block a user