int main() { int i, k, cnt; if (!geteuid()) { fprintf(stderr, "Don't run as root!\n"); exit(-2); } if (pilock()) exit(-1); mfd = open("/tmp/sdofstate", O_RDWR | O_CREAT, 0666); if (mfd < 0) return -1; memset(buf, 0xa5, 52); write(mfd, buf, 52); memimg = mmap(0, 52, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); signal(SIGTERM, teardown); signal(SIGINT, teardown); signal(SIGQUIT, teardown); startup(); startsock(); cnt = 0; for (;;) { char outstr[256]; for (i = 0; i < 13; i++) memimg[i] = (buf[i * 2 + 1] << 8) | buf[i * 2 + 2]; sprintf(outstr, "$PD6DF,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", memimg[0], memimg[1], memimg[2], memimg[3], memimg[4], memimg[5], memimg[6], memimg[7], memimg[8], memimg[9], memimg[10], memimg[11], memimg[12]); addnmeacksum(outstr); // printf( "%s\n", outstr ); fflush(stdout); i = readstr(); if (i != 0) startup(); if (mgdfd >= 0) { k = write(mgdfd, outstr, strlen(outstr)); if (k != strlen(outstr)) { printf("LOG DISCONNECT\n"); close(mgdfd); mgdfd = -1; } } else; //startsock(); } }
void* mutexFunc2() { int tid = picreate(30, &calcFunc, NULL); printf("\t\tentrando em mutexFunc2!\n"); pilock(&mutex); printf("\t\tchamando piwait em mutexFunc2!\n"); piwait(tid); printf("\t\ti = %d\n", *i); piunlock(&mutex); printf("\t\t * terminando mutexFunc2!\n"); return NULL; }