From a05242e166f9d968fdaddcff3009a4ddc351532f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E5=AE=89?= Date: Thu, 3 Dec 2015 09:24:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=AF=B9getpwdnam=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E4=BB=85=E5=9C=A8sys=5Fnicmonitor=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E4=B8=AD=E8=B0=83=E7=94=A8=E4=B8=80=E6=AC=A1=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=B0=86=E5=85=B6=E5=8F=96=E5=BE=97=E7=9A=84=20=E4=B8=BB?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E8=B7=AF=E5=BE=84=E5=90=8D=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=9C=A8=E5=85=B1=E4=BA=AB=E5=86=85=E5=AD=98=E3=80=82=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E6=AF=8F=E6=AC=A1=E8=B0=83=E7=94=A8get=5Fnic=5Finfo?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=86=8D=E8=8E=B7=E5=8F=96=E8=AF=A5=E5=80=BC?= =?UTF-8?q?=20=E6=97=B6=EF=BC=8C=E5=8F=AA=E9=9C=80=E4=BB=8E=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=E5=86=85=E5=AD=98=E4=B8=AD=E8=AF=BB=E5=87=BA=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E5=86=8D=E9=9C=80=E8=A6=81=E8=B0=83=E7=94=A8?= =?UTF-8?q?getpwdnam=E5=87=BD=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sys_nicmonitor/mnic.c | 13 ++++++++++++- src/sys_nicmonitor/nicinfo_shm.c | 20 ++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/sys_nicmonitor/mnic.c b/src/sys_nicmonitor/mnic.c index a4fd8f3..6a59fd6 100644 --- a/src/sys_nicmonitor/mnic.c +++ b/src/sys_nicmonitor/mnic.c @@ -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); diff --git a/src/sys_nicmonitor/nicinfo_shm.c b/src/sys_nicmonitor/nicinfo_shm.c index 3f83988..25b1686 100644 --- a/src/sys_nicmonitor/nicinfo_shm.c +++ b/src/sys_nicmonitor/nicinfo_shm.c @@ -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);