FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/fsnew.c @ 321:0cb766828d7a
fc-fsio: implemented write-battery-table and write-charging-config commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 17 Dec 2017 03:31:54 +0000 |
parents | |
children | 003e48f8ebe1 |
comparison
equal
deleted
inserted
replaced
320:7572c35a768a | 321:0cb766828d7a |
---|---|
1 /* | |
2 * In this module we are going to implement the commands that upload | |
3 * new FreeCalypso-invented stuff into the FFS of our FC devices. | |
4 */ | |
5 | |
6 #include <sys/wait.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
10 #include "exitcodes.h" | |
11 | |
12 char batterytab_compile_tool[] = "/opt/freecalypso/bin/compile-fc-batt"; | |
13 char charging_compile_tool[] = "/opt/freecalypso/bin/compile-fc-chg"; | |
14 | |
15 upload_fc_table_from_ascii(asciisrc, compiletool, ffs_pathname) | |
16 char *asciisrc, *compiletool, *ffs_pathname; | |
17 { | |
18 char tmpfile[] = "/tmp/fc-fsioXXXXXX"; | |
19 int tmpfd; | |
20 pid_t child, waitres; | |
21 int status, rc; | |
22 | |
23 tmpfd = mkstemp(tmpfile); | |
24 if (tmpfd < 0) { | |
25 fprintf(stderr, "unable to get temp file via mkstemp()\n"); | |
26 return(ERROR_UNIX); | |
27 } | |
28 close(tmpfd); | |
29 child = vfork(); | |
30 if (child < 0) { | |
31 fprintf(stderr, "unable to vfork to run compiler tool\n"); | |
32 unlink(tmpfile); | |
33 return(ERROR_UNIX); | |
34 } | |
35 if (!child) { | |
36 execl(compiletool, compiletool, asciisrc, tmpfile, 0); | |
37 perror(compiletool); | |
38 _exit(ERROR_UNIX); | |
39 } | |
40 waitres = waitpid(child, &status, 0); | |
41 if (waitres != child || !WIFEXITED(status)) { | |
42 fprintf(stderr, "unexpected wait result after compiler run\n"); | |
43 unlink(tmpfile); | |
44 return(ERROR_UNIX); | |
45 } | |
46 rc = WEXITSTATUS(status); | |
47 if (rc) { | |
48 unlink(tmpfile); | |
49 return rc; | |
50 } | |
51 rc = fwrite_from_file(ffs_pathname, tmpfile); | |
52 unlink(tmpfile); | |
53 return rc; | |
54 } | |
55 | |
56 cmd_write_battery_table(argc, argv) | |
57 char **argv; | |
58 { | |
59 return upload_fc_table_from_ascii(argv[1], batterytab_compile_tool, | |
60 "/etc/batterytab"); | |
61 } | |
62 | |
63 cmd_write_charging_config(argc, argv) | |
64 char **argv; | |
65 { | |
66 return upload_fc_table_from_ascii(argv[1], charging_compile_tool, | |
67 "/etc/charging"); | |
68 } |