105 lines
2.2 KiB
C
105 lines
2.2 KiB
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
void func1()
|
||
|
{
|
||
|
FILE *fp;
|
||
|
char string[255];
|
||
|
fp = fopen("/media/usb/lbu.last","r");
|
||
|
if(fp == NULL){
|
||
|
printf("lbu down");
|
||
|
}
|
||
|
char string2[255];
|
||
|
fscanf(fp,"%*s %*s %*s %s %*s %*s %s", string, string2);
|
||
|
fclose(fp);
|
||
|
printf(" LBU commit %s %-10s \n",string,string2);
|
||
|
}
|
||
|
|
||
|
void func2()
|
||
|
{
|
||
|
char string[3][5];
|
||
|
FILE *fp;
|
||
|
fp = fopen("/proc/loadavg","r");
|
||
|
fscanf(fp,"%s %s %s", string[1],string[2],string[3]);
|
||
|
fclose(fp);
|
||
|
printf(" Load averages %s %s %s \n",string[1],string[2],string[3]);
|
||
|
}
|
||
|
|
||
|
void func3()
|
||
|
{
|
||
|
char string[3][5];
|
||
|
FILE *fp;
|
||
|
fp = fopen("/proc/loadavg","r");
|
||
|
fscanf(fp,"%s %s %s", string[1],string[2],string[3]);
|
||
|
fclose(fp);
|
||
|
printf(" Load averages %s %s %s \n",string[1],string[2],string[3]);
|
||
|
}
|
||
|
|
||
|
// main is a control loop
|
||
|
int main(void)
|
||
|
{
|
||
|
FILE *fp = fopen("/tmp/hoststat.sock","r+");
|
||
|
if(fp == NULL){
|
||
|
printf("socket lost");
|
||
|
fp = fopen("/tmp/hoststat.sock","w+");
|
||
|
fclose(fp);
|
||
|
return 1;
|
||
|
}
|
||
|
char tmpsock[50];
|
||
|
fgets(tmpsock,50,fp);
|
||
|
fclose(fp);
|
||
|
fp = fopen("/tmp/hoststat.sock","w");
|
||
|
if (strcmp(tmpsock,"step0\n")==0)
|
||
|
{
|
||
|
func1();
|
||
|
fprintf(fp,"step1\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step1\n")==0){
|
||
|
func1();
|
||
|
fprintf(fp,"step2\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step2\n")==0){
|
||
|
func2();
|
||
|
fprintf(fp,"step3\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step3\n")==0){
|
||
|
func2();
|
||
|
fprintf(fp,"step4\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step4\n")==0){
|
||
|
func2();
|
||
|
fprintf(fp,"step5\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step5\n")==0){
|
||
|
func3();
|
||
|
fprintf(fp,"step6\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step6\n")==0){
|
||
|
func3();
|
||
|
fprintf(fp,"step7\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step7\n")==0){
|
||
|
func3();
|
||
|
fprintf(fp,"step8\n");
|
||
|
return 0;
|
||
|
}
|
||
|
if (strcmp(tmpsock,"step8\n")==0){
|
||
|
func1();
|
||
|
fprintf(fp,"step0\n");
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printf("Starting up");
|
||
|
fprintf(fp,"step0\n");
|
||
|
return 0;
|
||
|
}
|
||
|
}
|