📄 sm.c
字号:
#include<stdio.h>#include<time.h>#include<sys/types.h>#include<dirent.h>#include<../include/shm.h>#define on 1#define off 0#define not -1#define debug notint editcfg(int argc,char *argv[]){ FILE *pfile; char pbuffer[9][256]={0,}; int i=0; int nsize; pfile=fopen("./conf.dvr","r+"); if(pfile) { while(i<8) { fgets(pbuffer[i],256,pfile); printf("%s",pbuffer[i]); i++; } } strcpy(pbuffer[4],argv[1]); strcat(pbuffer[4],"\n"); fclose(pfile); pfile=fopen("./conf.dvr","w"); if(pfile) { for(i=0;i<8;i++) { fputs(pbuffer[i],pfile); } strcpy(pbuffer[8],"\0"); fputs(pbuffer[8],pfile); } fclose(pfile);}int date_func(char * ddate){ time_t dt; struct tm *dtp;// printf("gogogo\n"); time(&dt); dt=(time_t)(dt-60*60*24*7); dtp=localtime(&dt); if(sprintf(ddate,"%04d%02d%02d",1900+dtp->tm_year,1+dtp->tm_mon,dtp->tm_mday)>=0){ printf("date before 7 %s\n",ddate); return 0; } /* if(sprintf(ddate,"%04d%02d%02d",1900+dtp->tm_year,1+dtp->tm_mon,dtp->tm_mday)>=0){ printf("date del %s\n",ddate); return 0; }*/ return 1;}int date_func2(char * ddate){ time_t dt; struct tm *dtp;// printf("gogogo\n"); time(&dt);// dt=(time_t)(dt-60*60*24*7); dtp=localtime(&dt); if(sprintf(ddate,"%04d%02d%02d_%02d%02d",1900+dtp->tm_year,1+dtp->tm_mon,dtp->tm_mday,dtp->tm_hour,dtp->tm_min)>=0){ printf("log date : %s\n",ddate); return 0; } /* if(sprintf(ddate,"%04d%02d%02d",1900+dtp->tm_year,1+dtp->tm_mon,dtp->tm_mday)>=0){ printf("date del %s\n",ddate); return 0; }*/ return 1;} main(){ char deldate[32]; char nowdate[32]; char logdate[32]; char list[64][128]; char cmd[128]; DIR *dp; struct dirent *dirp; int i; int iMax; int status; int no[128]={}; int temp;////share memory define//// int shmid; void *shmaddr; int pidstat; SHMDATA_PTR stCul_cardata; FILE * p_log;#if (debug == on) FILE * ReLog; int r_tm;#endif while(1) { if((shmid = shmget((key_t)1234, sizeof(SHMDATA), IPC_CREAT|0666)) == -1) { perror("shmid failed"); pidstat=0; } if((shmaddr = shmat(shmid, (void *)0, 0)) == (void *)-1) { perror("shmat failed"); pidstat=0; } if(pidstat!=0){ stCul_cardata = (SHMDATA_PTR)shmaddr; stCul_cardata->bProsPids.w7daydelpid= getpid(); }////////del action//// if((dp=opendir("/mnt/ide-hda1/"))==NULL){ perror("opendir failed"); sleep(3600); } i=0; while(dirp=readdir(dp)){ printf("dirp= %d\n",dirp); if(!strncmp(dirp->d_name,".",1)) continue; strcpy(list[i],dirp->d_name); printf("list %d : %s \n",i,dirp->d_name); i++; } iMax=i; printf("iMax = %d\n",iMax); closedir(dp); date_func(deldate);// printf("date?%s\n",deldate); status=0; for(i=0;i<iMax;i++){ if(strncmp(list[i],deldate,8)<=0){ no[status]=i; printf("no i = %d, i = %d \n",no[i],i); status++; printf("status ++ : %d\n",status);// break; } } printf("status = %d , list count %d \n",status,i); if(status>0){ for(i=0;i<status;i++){ strcpy(cmd,"rm"); strcat(cmd," "); strcat(cmd,"-rf"); strcat(cmd," "); strcat(cmd,"/mnt/ide-hda1/"); strcat(cmd,list[no[i]]); printf("cmp %s\n",cmd);// printf("no [%d] = %d \n",i,no[i]); printf("%s\n",list[no[i]]); system(cmd); } } printf("wait!!\n");#if (debug == not) printf("sleep mode and infinite loop\n"); p_log=fopen("/mnt/ide-hda1/debug.log","a"); date_func2(logdate); fprintf(p_log,"start time\t"); fprintf(p_log,logdate); fprintf(p_log,"\n"); fclose(p_log); sleep(600);#endif #if (debug == on) ReLog=fopen("/mnt/ide-hda1/reboot.log","a"); date_func2(logdate); fprintf(ReLog,"start time\t"); fprintf(ReLog,logdate); fprintf(ReLog,"\n"); fclose(ReLog); printf("reboot mode and left log\n"); sleep(3600*4); ReLog=fopen("/mnt/ide-hda1/reboot.log","a"); date_func2(logdate); fprintf(ReLog,"reboot time\t"); fprintf(ReLog,logdate); fprintf(ReLog,"\n"); fclose(ReLog); system("reboot"); #endif #if (debug == off) printf("reboot mode\n"); sleep(3600*2); system("reboot");//reboot!!#endif }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -