-int main(int argc, char *argv[])
-{
- struct sigaction sig;
- struct ps_struct *ps;
- char output_file[PATH_MAX];
- char datestr[200];
- time_t t = 0;
- FILE *f;
- int gind;
- int i;
-
- rlim.rlim_cur = 4096;
- rlim.rlim_max = 4096;
- (void) setrlimit(RLIMIT_NOFILE, &rlim);
-
- f = fopen("/etc/systemd/bootchart.conf", "r");
- if (f) {
- char buf[256];
- char *key;
- char *val;
-
- while (fgets(buf, 80, f) != NULL) {
- char *c;
-
- c = strchr(buf, '\n');
- if (c) *c = 0; /* remove trailing \n */
-
- if (buf[0] == '#')
- continue; /* comment line */
-
- key = strtok(buf, "=");
- if (!key)
- continue;
- val = strtok(NULL, "=");
- if (!val)
- continue;
-
- // todo: filter leading/trailing whitespace
-
- if (streq(key, "samples"))
- len = atoi(val);
- if (streq(key, "freq"))
- hz = atof(val);
- if (streq(key, "rel"))
- relative = atoi(val);
- if (streq(key, "filter"))
- filter = atoi(val);
- if (streq(key, "pss"))
- pss = atoi(val);
- if (streq(key, "output"))
- strncpy(output_path, val, PATH_MAX - 1);
- if (streq(key, "init"))
- strncpy(init_path, val, PATH_MAX - 1);
- if (streq(key, "scale_x"))
- scale_x = atof(val);
- if (streq(key, "scale_y"))
- scale_y = atof(val);
- if (streq(key, "entropy"))
- entropy = atoi(val);
- }
- fclose(f);
- }
-
- while (1) {
- static struct option opts[] = {
- {"rel", 0, NULL, 'r'},
- {"freq", 1, NULL, 'f'},
- {"samples", 1, NULL, 'n'},
- {"pss", 0, NULL, 'p'},
- {"output", 1, NULL, 'o'},
- {"init", 1, NULL, 'i'},
- {"filter", 0, NULL, 'F'},
- {"help", 0, NULL, 'h'},
- {"scale-x", 1, NULL, 'x'},
- {"scale-y", 1, NULL, 'y'},
- {"entropy", 0, NULL, 'e'},
- {NULL, 0, NULL, 0}
- };
-
- gind = 0;
-
- i = getopt_long(argc, argv, "erpf:n:o:i:Fhx:y:", opts, &gind);
- if (i == -1)
- break;
- switch (i) {
+static int parse_args(int argc, char *argv[]) {
+ static struct option options[] = {
+ {"rel", no_argument, NULL, 'r'},
+ {"freq", required_argument, NULL, 'f'},
+ {"samples", required_argument, NULL, 'n'},
+ {"pss", no_argument, NULL, 'p'},
+ {"output", required_argument, NULL, 'o'},
+ {"init", required_argument, NULL, 'i'},
+ {"no-filter", no_argument, NULL, 'F'},
+ {"cmdline", no_argument, NULL, 'C'},
+ {"help", no_argument, NULL, 'h'},
+ {"scale-x", required_argument, NULL, 'x'},
+ {"scale-y", required_argument, NULL, 'y'},
+ {"entropy", no_argument, NULL, 'e'},
+ {NULL, 0, NULL, 0}
+ };
+ int c;
+
+ while ((c = getopt_long(argc, argv, "erpf:n:o:i:FChx:y:", options, NULL)) >= 0) {
+ int r;
+
+ switch (c) {