static void print_utline(struct utmp ut, FILE *out) { const char *addr_string, *time_string; char buffer[INET6_ADDRSTRLEN]; if (ut.ut_addr_v6[1] || ut.ut_addr_v6[2] || ut.ut_addr_v6[3]) addr_string = inet_ntop(AF_INET6, &(ut.ut_addr_v6), buffer, sizeof(buffer)); else addr_string = inet_ntop(AF_INET, &(ut.ut_addr_v6), buffer, sizeof(buffer)); #if defined(_HAVE_UT_TV) time_string = timetostr(ut.ut_tv.tv_sec); #else time_string = timetostr((time_t)ut.ut_time); /* ut_time is not always a time_t */ #endif cleanse(ut.ut_id); cleanse(ut.ut_user); cleanse(ut.ut_line); cleanse(ut.ut_host); /* pid id user line host addr time */ fprintf(out, "[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15s] [%-28.28s]\n", ut.ut_type, ut.ut_pid, ut.ut_id, 8, UT_NAMESIZE, ut.ut_user, 12, UT_LINESIZE, ut.ut_line, 20, UT_HOSTSIZE, ut.ut_host, addr_string, time_string); }
static char * ATTRIBUTE_WARN_UNUSED_RESULT human_time (struct timespec t) { /* STR must be at least this big, either because localtime_rz fails, or because the time zone is truly outlandish so that %z expands to a long string. */ enum { intmax_bufsize = INT_BUFSIZE_BOUND (intmax_t) }; static char str[intmax_bufsize + INT_STRLEN_BOUND (int) /* YYYY */ + 1 /* because YYYY might equal INT_MAX + 1900 */ + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +"]; static timezone_t tz; if (!tz) tz = tzalloc (getenv ("TZ")); struct tm tm; int ns = t.tv_nsec; if (localtime_rz (tz, &t.tv_sec, &tm)) nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", &tm, tz, ns); else { char secbuf[INT_BUFSIZE_BOUND (intmax_t)]; sprintf (str, "%s.%09d", timetostr (t.tv_sec, secbuf), ns); } return str; }
void print_utline(struct utmp ut) { char addr_buf[INET6_ADDRSTRLEN+1]; const char *addr_string, *time_string; void *in_addr = &ut.ut_addr_v6; size_t addr_length = INET6_ADDRSTRLEN; int addr_family = AF_INET6; if (!ut.ut_addr_v6[1] && !ut.ut_addr_v6[2] && !ut.ut_addr_v6[3]) { addr_family = AF_INET; addr_length = INET_ADDRSTRLEN; in_addr = &ut.ut_addr; } if ((addr_string = inet_ntop(addr_family, in_addr, addr_buf, addr_length)) == 0) { addr_buf[0] = '\0'; addr_string = &addr_buf[0]; } time_string = timetostr(ut.ut_time); cleanse(ut.ut_id); cleanse(ut.ut_user); cleanse(ut.ut_line); cleanse(ut.ut_host); /* pid id user line host addr time */ printf("[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15.15s] [%-28.28s]\n", ut.ut_type, ut.ut_pid, ut.ut_id, 8, UT_NAMESIZE, ut.ut_user, 12, UT_LINESIZE, ut.ut_line, 20, UT_HOSTSIZE, ut.ut_host, addr_string, time_string); }
static void* mail_job_monitor(time_t job_time,void *arg) { char key[20]; timetostr(&job_time,key); LOGI(key); LOGI("\n"); if(httpGet("172.16.3.14","GET /fastdfs-v2.0/alert/alert.do HTTP/1.1\r\n") < 0) return NULL; get_text(); send_mail(); return NULL; }
static char * ATTRIBUTE_WARN_UNUSED_RESULT human_time (struct timespec t) { static char str[MAX (INT_BUFSIZE_BOUND (intmax_t), (INT_STRLEN_BOUND (int) /* YYYY */ + 1 /* because YYYY might equal INT_MAX + 1900 */ + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +ZZZZ"))]; struct tm const *tm = localtime (&t.tv_sec); if (tm == NULL) return timetostr (t.tv_sec, str); nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t.tv_nsec); return str; }
void osmain( void ) { int i; int j=0; char nb[10]; char tmbuf[30]; /* ini screen first,so that we can output info as early as possible */ init_tty(); /* initialize the screen*/ kprintf( "TTY initialized\n" ); /* init both physical and virtual memory */ init_mm(); kprintf( "Memory manager initialized\n" ); init_irq(); /*initialize irq,with all interrupte disabled.*/ kprintf( "IRQ initialized\n" ); kprintf("\nHello\n"); install_syscall(); init_all_tasks(); init_kb(); /* set keyboard IRQ,and enable it */ kprintf( "\nKeyboard initialized\n" ); init_timer(); /* initialize time, enable timer irq */ /* init_system_clock(&real_tm); */ kprintf( "\nTimer initialized\n"); init_system_clock(&start_tm); kprintf("\nSystem start time is \n"); kprintf(timetostr(&start_tm, tmbuf)); kprintf("\nStarting first process....\n"); start_first_process(); kprintf( "\nNow I am doing a loop ,waiting for interrupt :)\n" ); while(1); halt(); }
void print_utline(struct utmp ut) { char *addr_string, *time_string; struct in_addr in; in.s_addr = ut.ut_addr; addr_string = inet_ntoa(in); time_string = timetostr(ut.ut_time); cleanse(ut.ut_id); cleanse(ut.ut_user); cleanse(ut.ut_line); cleanse(ut.ut_host); /* pid id user line host addr time */ printf("[%d] [%05d] [%-4.4s] [%-*.*s] [%-*.*s] [%-*.*s] [%-15.15s] [%-28.28s]\n", ut.ut_type, ut.ut_pid, ut.ut_id, 8, UT_NAMESIZE, ut.ut_user, 12, UT_LINESIZE, ut.ut_line, 20, UT_HOSTSIZE, ut.ut_host, addr_string, time_string); }
/* *route of the timer irq. *scheduler will goes from here. */ void timer_irq() { timefly++; if(timefly%2==0) { char buf[25]; int oldx,oldy; getxy(&oldx,&oldy); gotoxy(60,23); //kprint(itoa(timefly,buf,10)); kprintf("%d\n", timefly); //kprint("ok\n"); gotoxy(50,21); kprintf("%s\n", timetostr(update_sys_time(timefly), buf)); //kprint( timetostr(update_sys_time(timefly),buf) ); gotoxy(oldx,oldy); } schedule(); outportb(0x20,0x20); }
/************************************************* Function: shortmsg_trans_send Description: 报警短信事件 Input: 防区号码 Output: 无 Return: 上报成功与否 Others: *************************************************/ static int32 shortmsg_trans_send(int8 area_num) { uint32 code; uint32 Center_Ip; char stime[20]; char transbuf[255]; uint8 i; uint8 area_type[AREA_AMOUNT]; char alarm_type[12]; char area_des[10]; char type_des[12]; SEND_SHORT_MSG short_msg; uint8 tel_num1[TELNUM_LEN+1]; uint8 tel_num2[TELNUM_LEN+1]; uint8 *tel_num = NULL; memset(tel_num1, 0, TELNUM_LEN+1); memset(tel_num2, 0, TELNUM_LEN+1); storage_get_gsm_num(tel_num1, tel_num2); code = storage_get_validate_code(); Center_Ip = storage_get_center_ip(); if (0 == code || 0 == Center_Ip || 0 == area_num) { return FALSE; } storage_get_area_type(area_type); //发送短信 short_msg.level = 2; timetostr(stime); for (i = 0; i < 2; i++) { if (0 == i) { tel_num = tel_num1; } else { tel_num = tel_num2; } memset(&short_msg, 0, sizeof(SEND_SHORT_MSG)); memset(alarm_type, 0, sizeof(alarm_type)); memset(area_des, 0, sizeof(area_des)); memset(type_des, 0, sizeof(type_des)); if(strcmp(tel_num, "") != 0) { memset(transbuf, 0, sizeof(transbuf)); memcpy(&short_msg.ReceiveNo,tel_num,sizeof(short_msg.ReceiveNo)); memcpy(transbuf,(char*)(&code),sizeof(uint32)); strcpy(alarm_type,get_str(SID_Bj_Report_Type_Chufa)); strcpy(area_des,get_str(SID_Bj_Fangqu)); strcpy(type_des,get_str(SID_Bj_SOS+area_type[area_num-1])); sprintf(short_msg.Content,"%s %s %s:%d %s", alarm_type,stime,\ area_des,area_num, type_des); memcpy(transbuf+4,&short_msg,sizeof(short_msg)); set_nethead(G_CENTER_DEVNO, PRIRY_HIGHEST); net_direct_send(CMD_SHORT_MSG_TRANSMIT, transbuf, sizeof(int) + sizeof(short_msg), Center_Ip, NETCMD_UDP_PORT); } } return TRUE; }
main(int argc, char *argv[]) { FILE *fp; FILE *op; char buf[256], *p,bname[20]; char date[80]; int mode; int c[3]; int max[3]; unsigned int ave[3]; int now,sec; int i, j,k; char *blk[10] = { "£ß", "£ß", "¨x", "¨y", "¨z", "¨{", "¨|", "¨}", "¨~", "¨€", }; mode=atoi(argv[1]); sprintf(buf,"%s/use_board", BBSHOME); if ((fp = fopen(buf, "r")) == NULL) { printf("cann't open use_board\n"); return 1; } sprintf(buf,"%s/0Announce/bbslist/todayboard%d", BBSHOME, ( mode == 1 ) ? 2 : 1); if ((op = fopen(buf, "w")) == NULL) { printf("Can't Write file\n"); return 1; } fillboard(); now=time(0); getdatestring(now); sprintf(date,"%14.14s",datestring); while (fgets(buf, 256, fp)) { if(strlen(buf)<57) continue; if(strstr(buf,date)!=buf) continue; if ( !strncmp(buf+23, "USE", 3)) { p=strstr(buf,"USE"); p+=4; p=strtok(p," "); strcpy(bname,p); if ( p = (char *)strstr(buf+48, "Stay: ")) { sec=atoi( p + 6); } else sec=0; record_data(bname,sec); } } fclose(fp); qsort(st, numboards, sizeof( st[0] ), brd_cmp); ave[0]=0; ave[1]=0; ave[2]=0; max[1]=0; max[0]=0; max[2]=0; for(i=0;i<numboards;i++) { ave[0]+=st[i].times; ave[1]+=st[i].sum; ave[2]+=st[i].times==0?0:st[i].sum/st[i].times; if(max[0]<st[i].times) { max[0]=st[i].times; } if(max[1]<st[i].sum) { max[1]=st[i].sum; } if(max[2]<(st[i].times==0?0:st[i].sum/st[i].times)) { max[2]=(st[i].times==0?0:st[i].sum/st[i].times); } } c[0]=max[0]/30+1; c[1]=max[1]/30+1; c[2]=max[2]/30+1; numboards++; st[numboards-1].times=ave[0]/numboards; st[numboards-1].sum=ave[1]/numboards; strcpy(st[numboards-1].boardname,"Average"); strcpy(st[numboards-1].expname,"×Üƽ¾ù"); if(mode==1) { fprintf(op,"[1;37mÃû´Î %-21.21s%-24.24s %5s %8s %10s[m\n","ÌÖÂÛÇøÃû³Æ","ÖÐÎÄÐðÊö","ÈË´Î","ÀÛ»ýʱ¼ä","ƽ¾ùʱ¼ä"); }else { fprintf(op," [1;37m1 [m[34m%2s[1;37m= %d (×ÜÈË´Î) [1;37m1 [m[32m%2s[1;37m= %s (ÀÛ»ý×ÜʱÊý) [1;37m1 [m[31m%2s[1;37m= %d Ãë(ƽ¾ùʱÊý)\n\n", blk[9],c[0],blk[9],timetostr(c[1]),blk[9],c[2]); } for(i=0;i<numboards;i++) { if(!strcmp(st[i].boardname,"Others")) printf("ok"); if(mode==1) fprintf(op,"[1m%4d[m %-21.21s%-24.24s %5d %-.8s %10d\n",i+1,st[i].boardname,st[i].expname,st[i].times,timetostr(st[i].sum),st[i].times==0?0:st[i].sum/st[i].times); else { fprintf(op," [1;37mµÚ[31m%3d [37mÃû ÌÖÂÛÇøÃû³Æ£º[31m%s [35m%s[m\n",i+1,st[i].boardname,st[i].expname); fprintf(op,"[1;37m ©°¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª\n"); fprintf(op,"[1;37mÈ˴Ω¦[m[34m"); for(j=0;j<st[i].times/c[0];j++) { fprintf(op,"%2s",blk[9]); } fprintf(op,"%2s [1;37m%d[m\n",blk[(st[i].times%c[0])*10/c[0]],st[i].times); fprintf(op,"[1;37mʱ¼ä©¦[m[32m"); for(j=0;j<st[i].sum/c[1];j++) { fprintf(op,"%2s",blk[9]); } fprintf(op,"%2s [1;37m%s[m\n",blk[(st[i].sum%c[1])*10/c[1]],timetostr(st[i].sum)); j=st[i].times==0?0:st[i].sum/st[i].times; fprintf(op,"[1;37mƽ¾ù©¦[m[31m"); for(k=0;k<j/c[2];k++) { fprintf(op,"%2s",blk[9]); } fprintf(op,"%2s [1;37m%s[m\n",blk[(j%c[2])*10/c[2]],timetostr(j)); fprintf(op,"[1;37m ©¸¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª[m\n\n"); } if(!strcmp(st[i].boardname,"Others")) printf("ok"); } fclose(op); }
void wtmpxrawdump (const char *wtmpfile, const char *user) { STRUCT_UTMP *utp; struct in_addr addr; char *addr_string, *time_string; if (access (wtmpfile, R_OK)) die (errno, "cannot access the file"); /* Ignore the return value for now. Solaris' utmpname returns 1 upon success -- which is contrary to what the GNU libc version does. In addition, older GNU libc versions are actually void. */ UTMP_NAME_FUNCTION (wtmpfile); SET_UTMP_ENT (); while ((utp = GET_UTMP_ENT ()) != NULL) { if (user && strncmp (UT_USER (utp), user, sizeof (UT_USER (utp)))) continue; /* FIXME: missing support for IPv6 */ #ifdef HAVE_UTP_UT_ADDR_V6 addr.s_addr = utp->ut_addr_v6[0]; #endif addr_string = inet_ntoa (addr); time_string = timetostr (UT_TIME_MEMBER (utp)); switch (utp->ut_type) { default: /* Note: also catch EMPTY/UT_UNKNOWN values */ printf ("%-9s", "NONE"); break; #ifdef RUN_LVL /* Undefined on AIX if _ALL_SOURCE is false */ case RUN_LVL: printf ("%-9s", "RUNLEVEL"); break; #endif case BOOT_TIME: printf ("%-9s", "REBOOT"); break; case OLD_TIME: case NEW_TIME: /* FIXME */ break; case INIT_PROCESS: printf ("%-9s", "INIT"); break; case LOGIN_PROCESS: printf ("%-9s", "LOGIN"); break; case USER_PROCESS: printf ("%-9.*s", sizeof (UT_USER (utp)), UT_USER (utp)); break; case DEAD_PROCESS: printf ("%-9s", "DEAD"); break; #ifdef ACCOUNTING /* Undefined on AIX if _ALL_SOURCE is false */ case ACCOUNTING: printf ("%-9s", "ACCOUNT"); break; #endif } /* pid */ UT_PID (utp) ? printf ("[%05d]", UT_PID (utp)) : printf ("[%5s]", "-"); /* line id host addr date&time */ printf (" [%-12.*s] [%-4.*s] [%-19.*s] [%-15.15s] [%-19.19s]\n", sizeof (utp->ut_line), utp->ut_line, sizeof (utp->ut_id), utp->ut_id, sizeof (utp->ut_host), utp->ut_host, addr_string, time_string); } END_UTMP_ENT (); }
/* *********************************************************************** */ edit_out() { int i,j; int rdl; int totins; /* get total inserts */ int totdel; /* get total deletes */ unsigned char fmtwk[9]; unsigned char timebuf[9]; unsigned char *pnmwk; /* make sure we read the beginning */ fileseek( Infile, (long)0 ) ; /* read into fci struct */ if ( (rdl = fileread(Infile,&Fm,FCINSIZE) ) <=0) { disperr("COULD NOT READ %s",Pathbuf); return(-1); } charfill(&Bi,sizeof (Bi),' '); strncpy_s(Bi.drtdir, sizeof(Bi.drtdir), Fm.fc_drtdir, FILENMSZ); strncpy_s(Bi.dname, sizeof(Bi.dname), Fm.fc_dname, FILENMSZ); strncpy_s(Bi.dbtch, sizeof(Bi.dbtch), Fm.fc_dbtch, FILENMSZ); strncpy_s(Bi.frtdir, sizeof(Bi.frtdir), Fm.fc_frtdir, FILENMSZ); strncpy_s(Bi.fname, sizeof(Bi.fname), Fm.fc_fname, FILENMSZ); for( i=0 ; i < MAXMODES ; i++ ) { Bi.stat[i] = Status[Fm.fc_stat[i]] ; Bi.dopen[i] = Fm.fc_dopen[i] ; } for( i=0 ; i < MAXIO ; i++ ) { fmtstr(fmtwk,"%02d",Fm.fc_ioiter[i]); strncpy_s(Bi.ioiter[i], sizeof(Bi.ioiter[i]), fmtwk, 2); if( Fm.fc_iouid[i] > 0 ) { fmtstr( fmtwk, "%03d", Fm.fc_iouid[i] ) ; strncpy_s(Bi.iouid[i], sizeof(Bi.iouid[i]), fmtwk, 3); if( ( pnmwk = getusrnam( Fm.fc_iouid[i] ) ) != (char *)ERRCODE ) { strncpy_s(Bi.iouname[i], sizeof(Bi.iouname[i]), pnmwk, NMSZ); } else { charfill(Bi.iouname[i],NMSZ,'*'); } } else { charfill(Bi.iouid[i],3,'*'); charfill(Bi.iouname[i],NMSZ,'*'); } Bi.iostatus[i] = Fm.fc_iostatus[i]; } for (i=0; i< MAXMODES;i++) { fmtstr(fmtwk,"%05d",Fm.fc_rcntt[i]); strncpy_s(Bi.rcntt[i], sizeof(Bi.rcntt[i]), fmtwk, 5); fmtstr(fmtwk,"%05d",Fm.fc_dcntt[i]); strncpy_s(Bi.dcntt[i], sizeof(Bi.dcntt[i]), fmtwk, 5); fmtstr(fmtwk,"%08d",Fm.fc_kscntt[i]); strncpy_s(Bi.kscntt[i], sizeof(Bi.kscntt[i]), fmtwk, 8); fmtstr(fmtwk,"%08d",Fm.fc_kscnttf[i]); strncpy_s(Bi.kscnttf[i], sizeof(Bi.kscnttf[i]), fmtwk, 8); fmtstr(fmtwk,"%05d",Fm.fc_ercntt[i]); strncpy_s(Bi.ercntt[i], sizeof(Bi.ercntt[i]), fmtwk, 5); fmtstr(fmtwk,"%08d",Fm.fc_ekscntt[i]); strncpy_s(Bi.ekscntt[i],sizeof(Bi.ekscntt[i]) , fmtwk, 8); /* error k.s.count of function key */ fmtstr(fmtwk,"%08d",Fm.fc_ekscnttf[i]); strncpy_s(Bi.ekscnttf[i], sizeof(Bi.ekscnttf[i]), fmtwk, 8); /* total flag count */ fmtstr(fmtwk,"%05d",Fm.fc_flgcntt[i]); strncpy_s(Bi.flgcntt[i], sizeof(Bi.flgcntt[i]), fmtwk, 5); if (Fm.fc_fstime[i] == 0) charfill(Bi.fstime[i],24,'*'); else timetostr(Fm.fc_fstime[i],Bi.fstime[i]); if (Fm.fc_strtime[i] == 0) charfill(Bi.strtime[i],24,'*'); else timetostr(Fm.fc_strtime[i],Bi.strtime[i]); if (Fm.fc_lstime[i] == 0) charfill(Bi.lstime[i],24,'*'); else timetostr(Fm.fc_lstime[i],Bi.lstime[i]); if (elapsed_time(i,timebuf) ) /* calculate total elapsed time */ strncpy_s(Bi.eltimet[i], sizeof(Bi.eltimet[i]), timebuf, 8); else charfill(Bi.eltimet[i],8,'*'); } /* # inserts, # deletes */ totins = Fm.fc_mins[0] + Fm.fc_mins[1]; /* total inserts */ totdel = Fm.fc_mdel[0] + Fm.fc_mdel[1]; /* total deletes */ fmtstr(Bi.mins,"%05d",totins); fmtstr(Bi.mdel,"%05d",totdel); totins = Fm.fc_mdins[0] + Fm.fc_mdins[1]; /* total doc inserts */ totdel = Fm.fc_mddel[0] + Fm.fc_mddel[1]; /* total doc deletes */ fmtstr(Bi.mdins,"%05d",totins); fmtstr(Bi.mddel,"%05d",totdel); for (i=0; i< MAXMODES;i++) { for (j=0 ;j < MAXUSER;j++) { if (Fm.fc_muid[j][i] > 0) { fmtstr(fmtwk,"%03d",Fm.fc_muid[j][i]); strncpy_s(Bi.muid[j][i], sizeof(Bi.muid[j][i]), fmtwk, 3); if ( (pnmwk=getusrnam(Fm.fc_muid[j][i]) ) != (char *)ERRCODE) { strncpy_s(Bi.muidname[j][i], sizeof(Bi.muidname[j][i]), pnmwk, NMSZ); } else { charfill(Bi.muidname[j][i],NMSZ,'*'); } } else { charfill(Bi.muid[j][i],3,'*'); charfill(Bi.muidname[j][i],NMSZ,'*'); } } } Bi.sysfile = Fm.fc_sysfile; for (i=0; i< MAXMODES;i++) { fmtstr(fmtwk,"%05d",Fm.fc_iter[i]); strncpy_s(Bi.iter[i], sizeof(Bi.iter[i]), fmtwk, 5); } for (i=0; i< MAXIO;i++) { fmtstr(fmtwk,"%05d",Fm.fc_iositer[i]); strncpy_s(Bi.iositer[i], sizeof(Bi.iositer[i]), fmtwk, 5); fmtstr(fmtwk,"%05d",Fm.fc_iorcnt[i]); strncpy_s(Bi.iorcnt[i], sizeof(Bi.iorcnt[i]), fmtwk, 5); fmtstr(fmtwk,"%05d",Fm.fc_iodcnt[i]); strncpy_s(Bi.iodcnt[i], sizeof(Bi.iodcnt[i]), fmtwk, 5); if ( Fm.fc_iostime[i] == 0) charfill(Bi.iostime[i],24,'*'); else timetostr(Fm.fc_iostime[i],Bi.iostime[i]); if (Fm.fc_ioetime[i] == 0) charfill(Bi.ioetime[i],24,'*'); else timetostr(Fm.fc_ioetime[i],Bi.ioetime[i]); fmtstr(fmtwk,"%05d",Fm.fc_iopen[i]); strncpy_s(Bi.iopen[i], sizeof(Bi.iopen[i]), fmtwk, 5); } Bi.endmark= ' '; filewrite(BATCH_infof,&Bi,sizeof (Bi)); filewrite(BATCH_infof,"\n",1); return( 0 ) ; }