summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2009-11-16 19:00:52 -1000
committerDavid Cantrell <dcantrell@redhat.com>2009-11-18 14:42:13 -1000
commit3520edec88cd52222b02aea1a7e3a91863e06a85 (patch)
tree05b9627f1e582a3928146e086a621232296a5227
parent5a29882c8c85d94d7cc4705f719512f59e48bb24 (diff)
downloadanaconda-3520edec88cd52222b02aea1a7e3a91863e06a85.tar.gz
anaconda-3520edec88cd52222b02aea1a7e3a91863e06a85.tar.xz
anaconda-3520edec88cd52222b02aea1a7e3a91863e06a85.zip
Replace all popt use with glib's option parsing code.
We have glib for other things, so we can use it for option parsing and dump another library dependency.
-rw-r--r--anaconda.spec.in1
-rw-r--r--configure.ac5
-rw-r--r--isys/Makefile.am2
-rw-r--r--isys/isys.c1
-rw-r--r--loader/Makefile.am4
-rw-r--r--loader/driverdisk.c53
-rw-r--r--loader/hardware.c17
-rw-r--r--loader/hdinstall.c36
-rw-r--r--loader/kickstart.c53
-rw-r--r--loader/loader.c59
-rw-r--r--loader/modules.c33
-rw-r--r--loader/net.c96
-rw-r--r--loader/nfsinstall.c32
-rw-r--r--loader/urlinstall.c36
-rw-r--r--utils/Makefile.am4
-rw-r--r--utils/modlist.c62
16 files changed, 268 insertions, 226 deletions
diff --git a/anaconda.spec.in b/anaconda.spec.in
index 4f7952082..862e3061e 100644
--- a/anaconda.spec.in
+++ b/anaconda.spec.in
@@ -66,7 +66,6 @@ BuildRequires: libxml2-python
BuildRequires: mkinitrd-devel >= %{mkinitrdver}
BuildRequires: newt-devel
BuildRequires: pango-devel
-BuildRequires: popt-devel
BuildRequires: pykickstart >= %{pykickstartver}
BuildRequires: python-devel
BuildRequires: python-urlgrabber
diff --git a/configure.ac b/configure.ac
index 25af0c24e..8162b86ee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,10 +70,6 @@ AC_CHECK_LIB([newt], [newtInit],
[AC_SUBST(NEWT_LIBS, [-lnewt])],
[AC_MSG_FAILURE([*** libnewt not usable.])])
-AC_CHECK_LIB([popt], [poptGetContext],
- [AC_SUBST(POPT_LIBS, [-lpopt])],
- [AC_MSG_FAILURE([*** libpopt not usable.])])
-
AC_CHECK_LIB([slang], [SLang_get_int_size],
[AC_SUBST(SLANG_LIBS, [-lslang])],
[AC_MSG_FAILURE([*** libslang not usable.])])
@@ -132,6 +128,7 @@ AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers or library)
# Check for libraries we need that provide pkg-config scripts
PKG_PROG_PKG_CONFIG([0.23])
+PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16.1])
PKG_CHECK_MODULES([GTK_X11], [gtk+-x11-2.0 >= 2.16.1])
PKG_CHECK_MODULES([GDK], [gdk-2.0 >= 2.16.1])
PKG_CHECK_MODULES([NETWORKMANAGER], [NetworkManager >= 0.7.1])
diff --git a/isys/Makefile.am b/isys/Makefile.am
index e591b4020..420e78d21 100644
--- a/isys/Makefile.am
+++ b/isys/Makefile.am
@@ -30,7 +30,7 @@ dist_noinst_HEADERS = *.h
ISYS_CFLAGS = -DVERSION='"$(PACKAGE_VERSION)"' $(NFS_CFLAGS) \
$(NETWORKMANAGER_CFLAGS) $(LIBNL_CFLAGS) $(LIBNM_GLIB_CFLAGS) \
$(SELINUX_CFLAGS)
-ISYS_LIBS = $(RESOLV_LIBS) $(POPT_LIBS) $(EXT2FS_LIBS) $(ZLIB_LIBS) \
+ISYS_LIBS = $(RESOLV_LIBS) $(EXT2FS_LIBS) $(ZLIB_LIBS) \
$(DEVMAPPER_LIBS) $(BLKID_LIBS) $(X11_LIBS) $(SELINUX_LIBS) \
$(LIBNL_LIBS) $(LIBNM_GLIB_LIBS)
diff --git a/isys/isys.c b/isys/isys.c
index 3c0c573ad..4c315126c 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -25,7 +25,6 @@
#define u32 __u32
#include <ext2fs/ext2fs.h>
#include <fcntl.h>
-#include <popt.h>
/* Need to tell loop.h what the actual dev_t type is. */
#undef dev_t
#if defined(__alpha) || (defined(__sparc__) && defined(__arch64__))
diff --git a/loader/Makefile.am b/loader/Makefile.am
index 8d0fdced1..e5d1b7faf 100644
--- a/loader/Makefile.am
+++ b/loader/Makefile.am
@@ -39,10 +39,10 @@ endif
COMMON_CFLAGS = -DUSE_LOGDEV -DVERSION='"$(PACKAGE_VERSION)"'
-loader_CFLAGS = $(COMMON_CFLAGS) $(LIBNM_GLIB_CFLAGS) \
+loader_CFLAGS = $(COMMON_CFLAGS) $(GLIB_CFLAGS) $(LIBNM_GLIB_CFLAGS) \
$(LIBCURL_CFLAGS) \
-DINCLUDE_LOCAL -DINCLUDE_NETWORK
-loader_LDADD = $(NEWT_LIBS) $(POPT_LIBS) $(LIBNL_LIBS) \
+loader_LDADD = $(NEWT_LIBS) $(GLIB_LIBS) $(LIBNL_LIBS) \
$(LIBNM_GLIB_LIBS) $(CHECKISOMD5_LIBS) \
$(LIBCURL_LIBS) \
$(ISCSI_LIBS) $(top_srcdir)/isys/libisys.la
diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index e5d8f9022..8c8cc93dc 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -23,12 +23,12 @@
#include <errno.h>
#include <fcntl.h>
#include <newt.h>
-#include <popt.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <glib.h>
#include "copy.h"
#include "loader.h"
@@ -554,34 +554,42 @@ static void getDDFromDev(struct loaderData_s * loaderData, char * dev);
void useKickstartDD(struct loaderData_s * loaderData,
int argc, char ** argv) {
- char * fstype = NULL;
char * dev = NULL;
- char * src = NULL;
-
char * biospart = NULL, * p = NULL;
- int usebiosdev = 0;
-
- poptContext optCon;
- int rc;
- struct poptOption ksDDOptions[] = {
+ gchar *fstype = NULL, *src = NULL;
+ gint usebiosdev = 0;
+ gchar **remaining = NULL;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksDDOptions[] = {
/* The --type option is deprecated and now has no effect. */
- { "type", '\0', POPT_ARG_STRING, &fstype, 0, NULL, NULL },
- { "source", '\0', POPT_ARG_STRING, &src, 0, NULL, NULL },
- { "biospart", '\0', POPT_ARG_NONE, &usebiosdev, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+ { "type", 0, 0, G_OPTION_ARG_STRING, &fstype, NULL, NULL },
+ { "source", 0, 0, G_OPTION_ARG_STRING, &src, NULL, NULL },
+ { "biospart", 0, 0, G_OPTION_ARG_INT, &usebiosdev, NULL, NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
+ NULL, NULL },
+ { NULL },
};
- optCon = poptGetContext(NULL, argc, (const char **) argv, ksDDOptions, 0);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksDDOptions, NULL);
+
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
newtWinMessage(_("Kickstart Error"), _("OK"),
_("The following invalid argument was specified for "
- "the kickstart driver disk command: %s:%s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ "the kickstart driver disk command: %s"),
+ optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
+ g_strfreev(remaining);
return;
}
- dev = (char *) poptGetArg(optCon);
+ g_option_context_free(optCon);
+
+ if ((remaining != NULL) && (g_strv_length(remaining) == 1)) {
+ dev = remaining[0];
+ }
if (!dev && !src) {
logMessage(ERROR, "bad arguments to kickstart driver disk command");
@@ -606,10 +614,13 @@ void useKickstartDD(struct loaderData_s * loaderData,
}
if (dev) {
- return getDDFromDev(loaderData, dev);
+ getDDFromDev(loaderData, dev);
} else {
- return getDDFromSource(loaderData, src);
+ getDDFromSource(loaderData, src);
}
+
+ g_strfreev(remaining);
+ return;
}
static void getDDFromDev(struct loaderData_s * loaderData, char * dev) {
diff --git a/loader/hardware.c b/loader/hardware.c
index e9be27933..1f329055d 100644
--- a/loader/hardware.c
+++ b/loader/hardware.c
@@ -25,13 +25,13 @@
#include <errno.h>
#include <fcntl.h>
-#include <popt.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/wait.h>
+#include <glib.h>
#include "loader.h"
#include "hardware.h"
@@ -115,8 +115,9 @@ static int detectHardware() {
int earlyModuleLoad(int justProbe) {
int fd, len, i;
char buf[1024], *cmdLine;
- int argc;
- char ** argv;
+ gint argc = 0;
+ gchar **argv = NULL;
+ GError *optErr = NULL;
/* FIXME: reparsing /proc/cmdline to avoid major loader changes.
* should probably be done in loader.c:parseCmdline() like everything
@@ -126,13 +127,15 @@ int earlyModuleLoad(int justProbe) {
len = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (len <= 0) return 1;
-
+
buf[len] = '\0';
cmdLine = buf;
-
- if (poptParseArgvString(cmdLine, &argc, (const char ***) &argv))
+
+ if (!g_shell_parse_argv(cmdLine, &argc, &argv, &optErr)) {
+ g_error_free(optErr);
return 1;
-
+ }
+
for (i=0; i < argc; i++) {
if (!strncasecmp(argv[i], "driverload=", 11)) {
logMessage(INFO, "loading %s early", argv[i] + 11);
diff --git a/loader/hdinstall.c b/loader/hdinstall.c
index a4396df9f..c523f1c5c 100644
--- a/loader/hdinstall.c
+++ b/loader/hdinstall.c
@@ -27,11 +27,11 @@
#include <errno.h>
#include <fcntl.h>
#include <newt.h>
-#include <popt.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <unistd.h>
+#include <glib.h>
#include "driverdisk.h"
#include "hdinstall.h"
@@ -353,30 +353,34 @@ char * mountHardDrive(struct installMethod * method,
void setKickstartHD(struct loaderData_s * loaderData, int argc,
char ** argv) {
- char *biospart = NULL, *partition = NULL, *dir = NULL, *p;
- poptContext optCon;
- int rc;
-
- struct poptOption ksHDOptions[] = {
- { "biospart", '\0', POPT_ARG_STRING, &biospart, 0, NULL, NULL },
- { "partition", '\0', POPT_ARG_STRING, &partition, 0, NULL, NULL },
- { "dir", '\0', POPT_ARG_STRING, &dir, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+ char *p;
+ gchar *biospart = NULL, *partition = NULL, *dir = NULL;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksHDOptions[] = {
+ { "biospart", 0, 0, G_OPTION_ARG_STRING, &biospart, NULL, NULL },
+ { "partition", 0, 0, G_OPTION_ARG_STRING, &partition, NULL, NULL },
+ { "dir", 0, 0, G_OPTION_ARG_STRING, &dir, NULL, NULL },
+ { NULL },
};
-
logMessage(INFO, "kickstartFromHD");
- optCon = poptGetContext(NULL, argc, (const char **) argv, ksHDOptions, 0);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
+
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksHDOptions, NULL);
+
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
startNewt();
newtWinMessage(_("Kickstart Error"), _("OK"),
_("Bad argument to HD kickstart method "
- "command %s: %s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ "command: %s"), optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
return;
}
+ g_option_context_free(optCon);
+
if (biospart) {
char * dev;
diff --git a/loader/kickstart.c b/loader/kickstart.c
index 764df5d69..494045dd4 100644
--- a/loader/kickstart.c
+++ b/loader/kickstart.c
@@ -28,11 +28,11 @@
#include <errno.h>
#include <fcntl.h>
#include <newt.h>
-#include <popt.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <glib.h>
#include "loader.h"
#include "loadermisc.h"
@@ -120,8 +120,9 @@ int ksReadCommands(char * cmdFile) {
char * start, * end, * chptr;
char oldch;
int line = 0;
- char ** argv;
- int argc;
+ gint argc = 0;
+ gchar **argv = NULL;
+ GError *optErr = NULL;
int inSection = 0; /* in a section such as %post, %pre or %packages */
struct ksCommandNames * cmd;
int commandsAlloced = 5;
@@ -179,11 +180,15 @@ int ksReadCommands(char * cmdFile) {
/* JKFIXME: this should be handled better, but at least we
* won't segfault now */
} else {
- if (poptParseArgvString(start, &argc,
- (const char ***) &argv) || !argc) {
- newtWinMessage(_("Kickstart Error"), _("OK"),
- _("Error in %s on line %d of kickstart file %s."),
- argv[0], line, cmdFile);
+ if (!g_shell_parse_argv(start, &argc, &argv, &optErr) && argc) {
+ newtWinMessage(_("Kickstart Error"), _("OK"),
+ _("Error in %s on line %d of kickstart "
+ "file %s."), argv[0], line, cmdFile);
+ g_error_free(optErr);
+ } else if (!argc) {
+ newtWinMessage(_("Kickstart Error"), _("OK"),
+ _("Missing options on line %d of kickstart "
+ "file %s."), line, cmdFile);
} else {
for (cmd = ksTable; cmd->name; cmd++)
if (!strcmp(cmd->name, argv[0])) break;
@@ -478,29 +483,31 @@ static void setHalt(struct loaderData_s * loaderData, int argc,
static void setShutdown(struct loaderData_s * loaderData, int argc,
char ** argv) {
- poptContext optCon;
- int reboot = 0, halt = 0, poweroff = 0;
- int rc;
-
- struct poptOption ksOptions[] = {
- { "eject", 'e', POPT_ARG_NONE, NULL, 0, NULL, NULL },
- { "reboot", 'r', POPT_ARG_NONE, &reboot, 0, NULL, NULL },
- { "halt", 'h', POPT_ARG_NONE, &halt, 0, NULL, NULL },
- { "poweroff", 'p', POPT_ARG_NONE, &poweroff, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+ gint eject = 0, reboot = 0, halt = 0, poweroff = 0;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksOptions[] = {
+ { "eject", 'e', 0, G_OPTION_ARG_INT, &eject, NULL, NULL },
+ { "reboot", 'r', 0, G_OPTION_ARG_INT, &reboot, NULL, NULL },
+ { "halt", 'h', 0, G_OPTION_ARG_INT, &halt, NULL, NULL },
+ { "poweroff", 'p', 0, G_OPTION_ARG_INT, &poweroff, NULL, NULL },
+ { NULL },
};
- optCon = poptGetContext(NULL, argc, (const char **) argv, ksOptions, 0);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksOptions, NULL);
+
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
startNewt();
newtWinMessage(_("Kickstart Error"), _("OK"),
_("Bad argument to shutdown kickstart method "
- "command %s: %s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ "command: %s"), optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
return;
}
+ g_option_context_free(optCon);
if (FL_NOKILL(flags)) {
flags |= LOADER_FLAGS_HALT;
diff --git a/loader/loader.c b/loader/loader.c
index 89edee257..12e46c514 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -33,7 +33,6 @@
#include <execinfo.h>
#include <fcntl.h>
#include <newt.h>
-#include <popt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -56,6 +55,7 @@
#include <linux/vt.h>
#include <curl/curl.h>
+#include <glib.h>
#ifdef USE_MTRACE
#include <mcheck.h>
@@ -902,8 +902,9 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData,
int fd;
char buf[1024];
int len;
- char ** argv;
- int argc;
+ gint argc = 0;
+ gchar **argv = NULL;
+ GError *optErr = NULL;
int numExtraArgs = 0;
int i;
char *front, *stage2param = NULL;
@@ -928,8 +929,10 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData,
logMessage(INFO, "kernel command line: %s", cmdLine);
- if (poptParseArgvString(cmdLine, &argc, (const char ***) &argv))
+ if (!g_shell_parse_argv(cmdLine, &argc, &argv, &optErr)) {
+ g_error_free(optErr);
return;
+ }
for (i=0; i < argc; i++) {
if (!strcasecmp(argv[i], "askmethod"))
@@ -1823,19 +1826,21 @@ int main(int argc, char ** argv) {
struct loaderData_s loaderData;
char *path;
- char * cmdLine = NULL;
- char * ksFile = NULL;
- int testing = 0;
- int mediacheck = 0;
- char * virtpcon = NULL;
- poptContext optCon;
- struct poptOption optionTable[] = {
- { "cmdline", '\0', POPT_ARG_STRING, &cmdLine, 0, NULL, NULL },
- { "ksfile", '\0', POPT_ARG_STRING, &ksFile, 0, NULL, NULL },
- { "test", '\0', POPT_ARG_NONE, &testing, 0, NULL, NULL },
- { "mediacheck", '\0', POPT_ARG_NONE, &mediacheck, 0, NULL, NULL},
- { "virtpconsole", '\0', POPT_ARG_STRING, &virtpcon, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+
+ gchar *cmdLine = NULL, *ksFile = NULL, *virtpcon = NULL;
+ gboolean testing = FALSE, mediacheck = FALSE;
+ gchar **remaining = NULL;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry optionTable[] = {
+ { "cmdline", 0, 0, G_OPTION_ARG_STRING, &cmdLine, NULL, NULL },
+ { "ksfile", 0, 0, G_OPTION_ARG_STRING, &ksFile, NULL, NULL },
+ { "test", 0, 0, G_OPTION_ARG_NONE, &testing, NULL, NULL },
+ { "mediacheck", 0, 0, G_OPTION_ARG_NONE, &mediacheck, NULL, NULL },
+ { "virtpconsole", 0, 0, G_OPTION_ARG_STRING, &virtpcon, NULL, NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
+ NULL, NULL },
+ { NULL },
};
/* get init PID if we have it */
@@ -1865,20 +1870,26 @@ int main(int argc, char ** argv) {
rc = anaconda_trace_init();
/* now we parse command line options */
- optCon = poptGetContext(NULL, argc, (const char **) argv, optionTable, 0);
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, optionTable, NULL);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
- fprintf(stderr, "bad option %s: %s\n",
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
+ fprintf(stderr, "bad option: %s\n", optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
doExit(1);
}
- if ((arg = (char *) poptGetArg(optCon))) {
- fprintf(stderr, "unexpected argument: %s\n", arg);
+ g_option_context_free(optCon);
+
+ if (remaining) {
+ fprintf(stderr, "unexpected argument: %s\n", remaining[0]);
+ g_strfreev(remaining);
doExit(1);
}
+ g_strfreev(remaining);
+
if (!testing && !access("/var/run/loader.run", R_OK)) {
printf(_("loader has already been run. Starting shell.\n"));
execl("/bin/sh", "-/bin/sh", NULL);
diff --git a/loader/modules.c b/loader/modules.c
index a174dc11b..07f781a24 100644
--- a/loader/modules.c
+++ b/loader/modules.c
@@ -29,7 +29,6 @@
#include <errno.h>
#include <fcntl.h>
#include <newt.h>
-#include <popt.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -363,27 +362,35 @@ void loadKickstartModule(struct loaderData_s * loaderData,
int argc, char **argv) {
gchar *opts = NULL;
gchar *module = NULL;
- gchar **args = NULL;
- poptContext optCon;
+ gchar **args = NULL, **remaining = NULL;
gboolean rc;
- struct poptOption ksDeviceOptions[] = {
- { "opts", '\0', POPT_ARG_STRING, &opts, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksDeviceOptions[] = {
+ { "opts", 0, 0, G_OPTION_ARG_STRING, &opts, NULL, NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
+ NULL, NULL },
+ { NULL },
};
- optCon = poptGetContext(NULL, argc, (const char **) argv,
- ksDeviceOptions, 0);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksDeviceOptions, NULL);
+
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
startNewt();
newtWinMessage(_("Kickstart Error"), _("OK"),
_("Bad argument to device kickstart method "
- "command %s: %s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ "command: %s"), optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
return;
}
- module = (gchar *) poptGetArg(optCon);
+ g_option_context_free(optCon);
+
+ if ((remaining != NULL) && (g_strv_length(remaining) == 1)) {
+ module = remaining[0];
+ }
if (!module) {
startNewt();
diff --git a/loader/net.c b/loader/net.c
index 9280dc73a..4f49d8f44 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -28,7 +28,6 @@
#include <sys/utsname.h>
#include <arpa/inet.h>
#include <errno.h>
-#include <popt.h>
#include <resolv.h>
#include <net/if.h>
#include <newt.h>
@@ -1526,72 +1525,53 @@ int writeEnabledNetInfo(iface_t *iface) {
void setKickstartNetwork(struct loaderData_s * loaderData, int argc,
char ** argv) {
- char * arg, * bootProto = NULL, * device = NULL, *ethtool = NULL, * class = NULL;
- char * essid = NULL, * wepkey = NULL, * onboot = NULL;
- int mtu = 1500, noipv4 = 0, noipv6 = 0, dhcpTimeout = -1, noDns = 0, noksdev = 0;
- int rc;
- poptContext optCon;
iface_t iface;
-
- struct poptOption ksOptions[] = {
- { "bootproto", '\0', POPT_ARG_STRING, &bootProto, 0, NULL, NULL },
- { "device", '\0', POPT_ARG_STRING, &device, 0, NULL, NULL },
- { "dhcpclass", '\0', POPT_ARG_STRING, &class, 0, NULL, NULL },
- { "gateway", '\0', POPT_ARG_STRING, NULL, 'g', NULL, NULL },
- { "ip", '\0', POPT_ARG_STRING, NULL, 'i', NULL, NULL },
- { "mtu", '\0', POPT_ARG_INT, &mtu, 0, NULL, NULL },
- { "nameserver", '\0', POPT_ARG_STRING, NULL, 'n', NULL, NULL },
- { "netmask", '\0', POPT_ARG_STRING, NULL, 'm', NULL, NULL },
- { "noipv4", '\0', POPT_ARG_NONE, &noipv4, 0, NULL, NULL },
- { "noipv6", '\0', POPT_ARG_NONE, &noipv6, 0, NULL, NULL },
- { "nodns", '\0', POPT_ARG_NONE, &noDns, 0, NULL, NULL },
- { "hostname", '\0', POPT_ARG_STRING, NULL, 'h', NULL, NULL},
- { "ethtool", '\0', POPT_ARG_STRING, &ethtool, 0, NULL, NULL },
- { "essid", '\0', POPT_ARG_STRING, &essid, 0, NULL, NULL },
- { "wepkey", '\0', POPT_ARG_STRING, &wepkey, 0, NULL, NULL },
- { "onboot", '\0', POPT_ARG_STRING, &onboot, 0, NULL, NULL },
- { "notksdevice", '\0', POPT_ARG_NONE, &noksdev, 0, NULL, NULL },
- { "dhcptimeout", '\0', POPT_ARG_INT, &dhcpTimeout, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+ gchar *bootProto = NULL, *device = NULL, *class = NULL, *ethtool = NULL;
+ gchar *essid = NULL, *wepkey = NULL, *onboot = NULL;
+ gint mtu = 1500, dhcpTimeout = -1;
+ gboolean noipv4 = FALSE, noipv6 = FALSE, noDns = FALSE, noksdev = FALSE;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksOptions[] = {
+ { "bootproto", 0, 0, G_OPTION_ARG_STRING, &bootProto, NULL, NULL },
+ { "device", 0, 0, G_OPTION_ARG_STRING, &device, NULL, NULL },
+ { "dhcpclass", 0, 0, G_OPTION_ARG_STRING, &class, NULL, NULL },
+ { "gateway", 'g', 0, G_OPTION_ARG_STRING, &loaderData->gateway,
+ NULL, NULL },
+ { "ip", 'i', 0, G_OPTION_ARG_STRING, &loaderData->ipv4, NULL, NULL },
+ { "mtu", 0, 0, G_OPTION_ARG_INT, &mtu, NULL, NULL },
+ { "nameserver", 'n', 0, G_OPTION_ARG_STRING, &loaderData->dns,
+ NULL, NULL },
+ { "netmask", 'm', 0, G_OPTION_ARG_STRING, &loaderData->netmask,
+ NULL, NULL },
+ { "noipv4", 0, 0, G_OPTION_ARG_NONE, &noipv4, NULL, NULL },
+ { "noipv6", 0, 0, G_OPTION_ARG_NONE, &noipv6, NULL, NULL },
+ { "nodns", 0, 0, G_OPTION_ARG_NONE, &noDns, NULL, NULL },
+ { "hostname", 'h', 0, G_OPTION_ARG_STRING, &loaderData->hostname,
+ NULL, NULL },
+ { "ethtool", 0, 0, G_OPTION_ARG_STRING, &ethtool, NULL, NULL },
+ { "essid", 0, 0, G_OPTION_ARG_STRING, &essid, NULL, NULL },
+ { "wepkey", 0, 0, G_OPTION_ARG_STRING, &wepkey, NULL, NULL },
+ { "onboot", 0, 0, G_OPTION_ARG_STRING, &onboot, NULL, NULL },
+ { "notksdevice", 0, 0, G_OPTION_ARG_NONE, &noksdev, NULL, NULL },
+ { "dhcptimeout", 0, 0, G_OPTION_ARG_INT, &dhcpTimeout, NULL, NULL },
+ { NULL },
};
iface_init_iface_t(&iface);
- optCon = poptGetContext(NULL, argc, (const char **) argv,
- ksOptions, 0);
- while ((rc = poptGetNextOpt(optCon)) >= 0) {
- arg = (char *) poptGetOptArg(optCon);
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksOptions, NULL);
- switch (rc) {
- case 'g':
- loaderData->gateway = strdup(arg);
- break;
- case 'i':
- loaderData->ipv4 = strdup(arg);
- break;
- case 'n':
- loaderData->dns = strdup(arg);
- break;
- case 'm':
- loaderData->netmask = strdup(arg);
- break;
- case 'h':
- if (loaderData->hostname)
- free(loaderData->hostname);
- loaderData->hostname = strdup(arg);
- break;
- }
- }
-
- if (rc < -1) {
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
newtWinMessage(_("Kickstart Error"), _("OK"),
- _("Bad argument to kickstart network command %s: %s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- } else {
- poptFreeContext(optCon);
+ _("Bad argument to kickstart network command: %s"),
+ optErr->message);
+ g_error_free(optErr);
}
+ g_option_context_free(optCon);
+
/* if they've specified dhcp/bootp use dhcp for the interface */
if (bootProto && (!strncmp(bootProto, "dhcp", 4) ||
!strncmp(bootProto, "bootp", 4))) {
diff --git a/loader/nfsinstall.c b/loader/nfsinstall.c
index e405df976..cabad46ba 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -25,7 +25,6 @@
#include <fcntl.h>
#include <newt.h>
-#include <popt.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -369,29 +368,34 @@ char * mountNfsImage(struct installMethod * method,
void setKickstartNfs(struct loaderData_s * loaderData, int argc,
char ** argv) {
- char * host = NULL, * dir = NULL, * mountOpts = NULL;
char *substr = NULL;
- poptContext optCon;
- int rc;
- struct poptOption ksNfsOptions[] = {
- { "server", '\0', POPT_ARG_STRING, &host, 0, NULL, NULL },
- { "dir", '\0', POPT_ARG_STRING, &dir, 0, NULL, NULL },
- { "opts", '\0', POPT_ARG_STRING, &mountOpts, 0, NULL, NULL},
- { 0, 0, 0, 0, 0, 0, 0 }
+ gchar *host = NULL, *dir = NULL, *mountOpts = NULL;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksNfsOptions[] = {
+ { "server", 0, 0, G_OPTION_ARG_STRING, &host, NULL, NULL },
+ { "dir", 0, 0, G_OPTION_ARG_STRING, &dir, NULL, NULL },
+ { "opts", 0, 0, G_OPTION_ARG_STRING, &mountOpts, NULL, NULL },
+ { NULL },
};
logMessage(INFO, "kickstartFromNfs");
- optCon = poptGetContext(NULL, argc, (const char **) argv, ksNfsOptions, 0);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
+
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksNfsOptions, NULL);
+
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
startNewt();
newtWinMessage(_("Kickstart Error"), _("OK"),
_("Bad argument to NFS kickstart method "
- "command %s: %s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ "command: %s"), optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
return;
}
+ g_option_context_free(optCon);
+
if (!host || !dir) {
logMessage(ERROR, "host and directory for nfs kickstart not specified");
return;
diff --git a/loader/urlinstall.c b/loader/urlinstall.c
index b03efce7a..8279ec9f6 100644
--- a/loader/urlinstall.c
+++ b/loader/urlinstall.c
@@ -24,12 +24,12 @@
*/
#include <newt.h>
-#include <popt.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <unistd.h>
#include <errno.h>
+#include <glib.h>
#include "../isys/iface.h"
@@ -382,29 +382,33 @@ int kickstartFromUrl(char * url, struct loaderData_s * loaderData) {
void setKickstartUrl(struct loaderData_s * loaderData, int argc,
char ** argv) {
-
- char *url = NULL, *substr = NULL;
- char *proxy = NULL;
- poptContext optCon;
- int rc;
- struct poptOption ksUrlOptions[] = {
- { "url", '\0', POPT_ARG_STRING, &url, 0, NULL, NULL },
- { "proxy", '\0', POPT_ARG_STRING, &proxy, 0, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0 }
+ char *substr = NULL;
+ gchar *url = NULL, *proxy = NULL;
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ GOptionEntry ksUrlOptions[] = {
+ { "url", 0, 0, G_OPTION_ARG_STRING, &url, NULL, NULL },
+ { "proxy", 0, 0, G_OPTION_ARG_STRING, &proxy, NULL, NULL },
+ { NULL },
};
logMessage(INFO, "kickstartFromUrl");
- optCon = poptGetContext(NULL, argc, (const char **) argv, ksUrlOptions, 0);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
+
+ g_option_context_set_help_enabled(optCon, FALSE);
+ g_option_context_add_main_entries(optCon, ksUrlOptions, NULL);
+
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
startNewt();
newtWinMessage(_("Kickstart Error"), _("OK"),
- _("Bad argument to Url kickstart method "
- "command %s: %s"),
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
+ _("Bad argument to URL kickstart method "
+ "command: %s"), optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
return;
}
+ g_option_context_free(optCon);
+
if (!url) {
newtWinMessage(_("Kickstart Error"), _("OK"),
_("Must supply a --url argument to Url kickstart method."));
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 750f51515..bfc8fd426 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -27,8 +27,8 @@ if IS_S390
utils_PROGRAMS += geninitrdsz mk-s390-cdboot
endif
-modlist_CFLAGS = -I$(top_srcdir)/loader
-modlist_LDADD = $(POPT_LIBS)
+modlist_CFLAGS = -I$(top_srcdir)/loader $(GLIB_CFLAGS)
+modlist_LDADD = $(GLIB_LIBS)
modlist_SOURCES = modlist.c $(top_srcdir)/loader/moduleinfo.c
MAINTAINERCLEANFILES = Makefile.in
diff --git a/utils/modlist.c b/utils/modlist.c
index 5c88e323f..7aff56792 100644
--- a/utils/modlist.c
+++ b/utils/modlist.c
@@ -17,44 +17,53 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <glib.h>
#include "../isys/isys.h"
#include "moduleinfo.h"
int main(int argc, char ** argv) {
- poptContext optCon;
- char * modInfoFile = "/boot/module-info";
+ GOptionContext *optCon = g_option_context_new(NULL);
+ GError *optErr = NULL;
+ gchar *modInfoFile = "/boot/module-info";
+ gboolean ignoreMissing = FALSE, showModInfo = FALSE;
+ gchar **remaining = NULL;
enum driverMajor major;
const char * type;
const char * mod;
struct moduleInfo * list, * m;
- int rc, i;
- int showModInfo = 0;
- int ignoreMissing = 0;
+ int i, arg = 0;
moduleInfoSet mis;
struct moduleInfo * mi;
- struct poptOption optionTable[] = {
- { "ignore-missing", 'I', POPT_ARG_NONE, &ignoreMissing, 0,
- "Ignore modules not in modinfo file for --modinfo" },
- { "modinfo", 'm', POPT_ARG_NONE, &showModInfo, 0,
- "Give output in module-info file for listed args" },
- { "modinfo-file", 'f', POPT_ARG_STRING, &modInfoFile, 0,
- "Module info file to use"},
- POPT_AUTOHELP
- { 0, 0, 0, 0, 0 }
+ GOptionEntry optionTable[] = {
+ { "ignore-missing", 'I', 0, G_OPTION_ARG_NONE, &ignoreMissing,
+ "Ignore modules not in modinfo file for --modinfo", NULL },
+ { "modinfo", 'm', 0, G_OPTION_ARG_NONE, &showModInfo,
+ "Give output in module-info file for listed args", NULL },
+ { "modinfo-file", 'f', 0, G_OPTION_ARG_STRING, &modInfoFile,
+ "Module info file to use", NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
+ NULL, NULL },
+ { NULL },
};
- optCon = poptGetContext(NULL, argc, (const char **) argv, optionTable, 0);
+ g_option_context_add_main_entries(optCon, optionTable, NULL);
- if ((rc = poptGetNextOpt(optCon)) < -1) {
- fprintf(stderr, "bad option %s: %s\n",
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- exit(1);
+ if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
+ fprintf(stderr, "bad option: %s\n", optErr->message);
+ g_error_free(optErr);
+ g_option_context_free(optCon);
+ g_strfreev(remaining);
+ exit(1);
+ }
+
+ g_option_context_free(optCon);
+
+ if (remaining == NULL) {
+ exit(1);
}
mis = newModuleInfoSet();
@@ -65,7 +74,7 @@ int main(int argc, char ** argv) {
if (showModInfo) {
printf("Version 0\n");
- while ((mod = poptGetArg(optCon))) {
+ while ((mod = remaining[arg]) != NULL) {
mi = findModuleInfo(mis, mod);
if (mi) {
printf("%s\n", mi->moduleName);
@@ -84,6 +93,7 @@ int main(int argc, char ** argv) {
default:
fprintf(stderr, "unknown net minor type for %s\n",
mi->moduleName);
+ g_strfreev(remaining);
exit(1);
}
break;
@@ -91,6 +101,7 @@ int main(int argc, char ** argv) {
default:
fprintf(stderr, "unknown device type for %s (%d)\n",
mi->moduleName, mi->major);
+ g_strfreev(remaining);
exit(1);
}
@@ -101,11 +112,13 @@ int main(int argc, char ** argv) {
}
} else if (!ignoreMissing) {
fprintf(stderr, "I know nothing about %s\n", mod);
+ g_strfreev(remaining);
exit(1);
}
+ arg++;
}
} else {
- while ((type = poptGetArg(optCon))) {
+ while ((type = remaining[arg]) != NULL) {
if (!strcasecmp(type, "scsi")) {
major = DRIVER_SCSI;
} else if (!strcasecmp(type, "net")) {
@@ -116,6 +129,7 @@ int main(int argc, char ** argv) {
major = DRIVER_CDROM;
} else {
fprintf(stderr, "type must be one of scsi, net, fs, cdrom\n");
+ g_strfreev(remaining);
exit(1);
}
@@ -123,8 +137,10 @@ int main(int argc, char ** argv) {
for (m = list; m && m->moduleName; m++)
printf("%s\n", m->moduleName);
free(list);
+ arg++;
}
}
+ g_strfreev(remaining);
return 0;
}