[PATCH 3/6] Better string handling in DD code, error checking and cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 loader/driverdisk.c |   49 ++++++++++++++++++++++++-------------------------
 1 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index b32b7f1..a94a20d 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -69,13 +69,9 @@ int modprobeDDmode()
   FILE *f = fopen("/etc/depmod.d/ddmode.conf", "w");
   if(f){
     struct utsname unamedata;
-    if(uname(&unamedata)){
-      fprintf(f, " pblacklist /lib/modules\n");
-    }
-    else{
-      fprintf(f, " pblacklist /lib/modules/%s\n", unamedata.release);
-    }
-
+    
+    if(uname(&unamedata)) fprintf(f, " pblacklist /lib/modules\n");
+    else fprintf(f, " pblacklist /lib/modules/%s\n", unamedata.release);
     fclose(f);
   }
 
@@ -126,7 +122,7 @@ int dlabelFilter(const char* name, struct stat *fstat, void *userptr)
   l-=3;
 
   /* and we want only .ko files */
-  if(strncmp(".ko", name+l, 3)) return 1;
+  if(strcmp(".ko", name+l)) return 1;
 
   /* TODO we are unpacking kernel module, read it's description */
 
@@ -140,15 +136,15 @@ char* moduleDescription(const char* modulePath)
   char *description = NULL;
   int size;
   
-  command = rstrscat(NULL, "modinfo --description '", modulePath, "'", NULL);
-  if(!command) return NULL;
-
+  checked_asprintf(&command, "modinfo --description '%s'", modulePath);
   f = popen(command, "r");
   free(command);
 
   if(f==NULL) return NULL;
   
   description = malloc(sizeof(char)*256);
+  if(!description) return NULL;
+
   size = fread(description, 1, 255, f);
   if(size==0){
     free(description);
@@ -180,27 +176,25 @@ int dlabelUnpackRPMDir(char* rpmdir, char* destination)
 
   /* set the cwd to destination */
   if(chdir(destination)){
+    logMessage(ERROR, _("We weren't able to CWD to %s"), destination)
     free(oldcwd);
     return 1;
   }
 
   /* get running kernel version */
-  if(uname(&unamedata)){
-    kernelver = rstrscat(NULL, "kernel-modules-", "unknown", NULL);
-  }
-  else{
-    kernelver = rstrscat(NULL, "kernel-modules-", unamedata.release, NULL);
-  }
+  rc = uname(&unamedata);
+  checked_asprintf(&kernelver, "kernel-modules-%s",
+          rc ? "unknown" : unamedata.release);
   logMessage(DEBUGLVL, "Kernel version: %s\n", kernelver);
 
-  globpattern = rstrscat(NULL, rpmdir, "/*.rpm", NULL);
+  checked_asprintf(&globpattern, "%s/*.rpm", rpmdir);
   glob_t globres;
   char** globitem;
   if(!glob(globpattern, GLOB_NOSORT|GLOB_NOESCAPE, globErrFunc, &globres)){
     /* iterate over all rpm files */
     globitem = globres.gl_pathv;
     while(globres.gl_pathc>0 && globitem!=NULL){
-      explodeRPM(*globitem, dlabelFilter, dlabelProvides, dlabelDeps, kernelver);
+      explodeRPM(*globitem, dlabelFilter, dlabelProvides, NULL, kernelver);
     }
     globfree(&globres);
     /* end of iteration */
@@ -209,7 +203,7 @@ int dlabelUnpackRPMDir(char* rpmdir, char* destination)
 
   /* restore CWD */
   if(chdir(oldcwd)){
-   /* FIXME: too bad.. */
+   logMessage(WARNING, _("We weren't able to restore CWD to %s"), oldcwd)
   }
 
   /* cleanup */
@@ -239,7 +233,7 @@ static int verifyDriverDisk(char *mntpt) {
     if (!sb.st_size)
         return LOADER_BACK;
     for (fnPtr = driverDiskFiles; *fnPtr; fnPtr++) {
-        sprintf(file, "%s/%s/%s", mntpt, getProductArch(), *fnPtr);
+        snprintf(file, 200, "%s/%s/%s", mntpt, getProductArch(), *fnPtr);
         if (access(file, R_OK)) {
             logMessage(ERROR, "cannot find %s, bad driver disk", file);
             return LOADER_BACK;
@@ -297,9 +291,7 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
 
     location = malloc(sizeof(struct moduleBallLocation));
     location->title = strdup(title);
-
     checked_asprintf(&location->path, DD_MODULES);
-    checked_asprintf(&fwdir, DD_FIRMWARE);
 
     sprintf(dest, DD_RPMDIR_TEMPLATE, disknum);
     sprintf(src, "%s/rpms/%s", mntpt, getProductArch());
@@ -307,14 +299,19 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
 
     /* unpack packages from dest into location->path */
     if(dlabelUnpackRPMDir(dest, DD_EXTRACTED)){
-      /* TODO error handler */
+      /* fatal error, log this and jump to exception handler */
+      logMessage(ERROR, _("Error unpacking RPMs from driver disc no.%d"),
+              disknum);
+      goto loadDriverDiscException;
     }
 
     /* run depmod to refresh modules db */
     if(system("depmod -a")){
-        /* FIXME: depmod didn't run */
+      /* this is not really fatal error, it might still work, log it */
+      logMessage(ERROR, _("Error running depmod -a for driverdisc no.%d"));
     }
 
+    checked_asprintf(&fwdir, DD_FIRMWARE);
     if (!access(fwdir, R_OK|X_OK)) {
         add_fw_search_dir(loaderData, fwdir);
         stop_fw_loader(loaderData);
@@ -328,6 +325,8 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
      * readModuleInfo(file, modInfo, location, 1);
      */
 
+loadDriverDiscException:
+
     if (!FL_CMDLINE(flags))
         newtPopWindow();
 
-- 
1.6.4.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux