2007年6月12日 星期二

DM自動重新開程序原始碼

#define MAXLINE 128

int main(int argc, char **argv)
{
int iHour,iMin,iSec;
FILE *fp;
char myHour[5];
char myMin[5];
char mySec[5];
memset(myHour,0,5);
memset(myMin,0,5);
memset(mySec,0,5);

if((fp=fopen("/var/etc/autoreboot.txt","r"))==NULL)
{
perror("No reboot setting time...\n");
exit(0);
}
fgets(myHour,MAXLINE,fp);
fgets(myMin ,MAXLINE,fp);
fgets(mySec ,MAXLINE,fp);
iHour = atoi(myHour);
iMin = atoi(myMin);
iSec = atoi(mySec);
printf("Set reboot time to %02d:%02d:%02d\n",iHour,iMin,iSec);

while(1)
{
sleep(1);
time_t t = time(0);
struct tm* lt = localtime(&t);
//printf("now is %02d:%02d:%02d\n",lt->tm_hour,lt->tm_min,lt->tm_sec);
if( (lt->tm_hour)==iHour)
{
if( (lt->tm_min)==iMin)
{
if( (lt->tm_sec)==iSec (lt->tm_sec)==(iSec+1))
{
//printf("Reboot now...\n");
system("/sbin/reboot");
sleep(10);
}
}
}
}

return 0;
}

2 則留言:

Unknown 提到...

請問大哥, compile 環境為何?

Dreambox World 提到...

您必需要下載tuxbox cvs的source code才可以Cross Compiler :)
之前在http://www.dreambox.tw裡PO過,會找時間移過來到此佈落格!