bool cfg_fromfile_direct(char *file) { struct cfg_state cmd; memset(&cmd, 0, sizeof(cmd)); /* Use dolog() as the output channel */ cmd.sock = -1; /* * This is a console command thus * execute with full priveleges */ cmd.level = LEVEL_MAXIMUM; cmd.quit = false; /* Run it */ return (cfg_fromfile(&cmd, file) && !cmd.quit); }
int readcfg(void) { char ports[BUFSIZ], *p; int port; pipe_s *pipe; cfg_s local; serialinfo_s sinfo; char *parity; /* Read the global config settings */ cfg_fromfile(&cfg, cfgfile); /* Read the comm port list */ if (cfg_readbuf(cfgfile, "comm_ports", ports, sizeof(ports)) == NULL) errend("Couldn't find 'comm_ports' entry in config file '%s'", cfgfile); vlist_clear(&pipes); /* Parse the comm ports list */ p = strtok(ports, ","); while (p) { if (sscanf(p, "%d", &port) > 0) { pipe = malloc(sizeof(pipe_s)); //pipe_init(pipe); if (pipe == NULL) perrend("malloc(pipe_s)"); cfg_init(&local, port); /* Copy global settings to those for current pipe */ cfg_assign(&local, &cfg); /* Set the comm port */ local.ints[CFG_IPORT].val = port; /* Load this pipe's config */ cfg_fromfile(&local, cfgfile); /* Try initializing the pipe */ if (pipe_init(pipe, local.ints[CFG_INETPORT].val)) perrend("pipe_init"); /* Copy over the rest of the pipe's config */ pipe->timeout = local.ints[CFG_ITIMEOUT].val; sinfo.port = port; sinfo.baud = local.ints[CFG_IBAUD].val; sinfo.stopbits = local.ints[CFG_ISTOP].val; sinfo.databits = local.ints[CFG_IDATA].val; parity = local.strs[CFG_SPARITY].val; if (strcmp(parity, "none") == 0) { sinfo.parity = SIO_PARITY_NONE; } else if (strcmp(parity, "even") == 0) { sinfo.parity = SIO_PARITY_EVEN; } else if (strcmp(parity, "odd") == 0) { sinfo.parity = SIO_PARITY_ODD; } else { errend("Unknown parity string '%s'", parity); } if (sio_setinfo(&pipe->sio, &sinfo)) errend("Unable to configure comm port %d", port); /* Finally add the pipe to the pipes list */ vlist_add(&pipes, pipes.tail, pipe); cfg_cleanup(&local); } p = strtok(NULL, ","); } /* Clean up local cfg struct */ cfg_cleanup(&local); return 0; }