static lvm_t _lvm_init(const char *system_dir) { struct cmd_context *cmd; /* FIXME: logging bound to handle */ if (!udev_init_library_context()) stack; /* * It's not necessary to use name mangling for LVM: * - the character set used for VG-LV names is subset of udev character set * - when we check other devices (e.g. device_is_usable fn), we use major:minor, not dm names */ dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE); /* create context */ /* FIXME: split create_toolcontext */ /* FIXME: make all globals configurable */ cmd = create_toolcontext(0, system_dir, 0, 0, 1, 1); if (!cmd) return NULL; if (stored_errno()) return (lvm_t) cmd; /* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed). */ /* initialization from lvm_run_command */ init_error_message_produced(0); /* FIXME: locking_type config option needed? */ /* initialize locking */ if (!init_locking(-1, cmd, 0)) { /* FIXME: use EAGAIN as error code here */ lvm_quit((lvm_t) cmd); return NULL; } /* * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in * archive() call. Possible example: * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n" */ cmd->cmd_line = "liblvm"; /* * Turn off writing to stdout/stderr. * FIXME Fix lib/ to support a non-interactive mode instead. */ log_suppress(1); return (lvm_t) cmd; }
lvm_t lvm_init(const char *system_dir) { struct cmd_context *cmd; /* FIXME: logging bound to handle */ if (!udev_init_library_context()) stack; /* create context */ /* FIXME: split create_toolcontext */ /* FIXME: make all globals configurable */ cmd = create_toolcontext(0, system_dir, 0, 0); if (!cmd) return NULL; if (stored_errno()) return (lvm_t) cmd; /* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed). */ /* initialization from lvm_run_command */ init_error_message_produced(0); /* FIXME: locking_type config option needed? */ /* initialize locking */ if (!init_locking(-1, cmd, 0)) { /* FIXME: use EAGAIN as error code here */ lvm_quit((lvm_t) cmd); return NULL; } /* * FIXME: Use cmd->cmd_line as audit trail for liblvm calls. Used in * archive() call. Possible example: * cmd_line = "lvm_vg_create: vg1\nlvm_vg_extend vg1 /dev/sda1\n" */ cmd->cmd_line = "liblvm"; /* * Turn off writing to stdout/stderr. * FIXME Fix lib/ to support a non-interactive mode instead. */ log_suppress(1); return (lvm_t) cmd; }
int main(int argc, char *argv[]) { int ret = 0; char *home = getenv("HOME"), *tmp; progname = argv[0]; #ifdef HAVE_SETLOCALE setlocale(LC_ALL, ""); #endif #ifdef ENABLE_NLS bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); #endif /* ENABLE_NLS */ ne_debug_init(stderr, 0); if (!home) { /* Show me the way to go home... */ printf(_("Environment variable $HOME needs to be set!\n")); return -1; } ne_sock_init(); memset(&session, 0, sizeof session); /* Options before rcfile, so rcfile settings can * override defaults */ tmp = ne_concat(home, "/.cadaver-locks", NULL); set_option(opt_lockstore, tmp); init_options(); init_netrc(); init_signals(); init_locking(); parse_args(argc, argv); ret = init_rcfile(); init_readline(); while (ret == 0) { char *cmd; cmd = read_command(); if (cmd == NULL) { /* Is it safe to do this... they just closed stdin, so * is it bad to write to stdout? */ putchar('\n'); ret = 1; } else { #ifdef HAVE_ADD_HISTORY if (strcmp(cmd, "") != 0) add_history(cmd); #endif ret = execute_command(cmd); free(cmd); } } if (session.connected) { close_connection(); } finish_locking(); ne_sock_exit(); return 0; }