SIGTERM again
[handlervirt.git] / experiment2.c
blob1df8c7ccc58f76d35de961af2b28cc4e479a5e2b
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <sys/file.h>
5 #include <stdio.h>
6 #include <stdlib.h>
8 int main() {
9 char filemac[13];
10 unsigned long int mac;
11 int fd = open("/mnt/netapp/maccounter", O_RDWR|O_CREAT|O_TRUNC);
12 flock(fd, LOCK_EX);
13 FILE * fd2 = fdopen(fd, "r");
15 if (fd2 == NULL) printf("ga dood\n");
16 if (fread(filemac, sizeof(char), 13, fd2) == 0) {
17 printf("read = 0\n");
18 mac = 0x0;
19 } else {
20 mac++;
23 mac = strtoul(filemac, NULL, 16);
24 printf("cur: %06X\n", mac);
25 mac++;
26 snprintf(filemac, 13, "%06X", mac);
27 printf("next: %s\n", filemac);
29 lseek(fd, 0, SEEK_SET);
30 write(fd, &filemac, 13);
31 close(fd);
32 flock(fd, LOCK_UN);