[PATCH 5/6] Coding style change to match Anaconda style better

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

 



---
 loader/cpio.c       |    6 +-
 loader/driverdisk.c |  219 ++++++++++++++++++++++++++-------------------------
 loader/loader.c     |   10 +-
 loader/rpmextract.c |  182 +++++++++++++++++++++---------------------
 4 files changed, 209 insertions(+), 208 deletions(-)

diff --git a/loader/cpio.c b/loader/cpio.c
index 36335fc..b352efb 100644
--- a/loader/cpio.c
+++ b/loader/cpio.c
@@ -78,7 +78,7 @@ int cpioReadFileHdr(FD_t fd, struct stat * st, char** name)
     char paddingBuffer[4];
 
     rc = Fread(&hdr, PHYS_HDR_SIZE, 1, fd);
-    if(rc!=1) return CPIOERR_BAD_HEADER;
+    if (rc!=1) return CPIOERR_BAD_HEADER;
 
     if (strncmp(CPIO_CRC_MAGIC, hdr.magic, sizeof(CPIO_CRC_MAGIC)-1) &&
         strncmp(CPIO_NEWC_MAGIC, hdr.magic, sizeof(CPIO_NEWC_MAGIC)-1))
@@ -105,7 +105,7 @@ int cpioReadFileHdr(FD_t fd, struct stat * st, char** name)
     //  return CPIOERR_BAD_HEADER;
     
     long padding = (nameSize+PHYS_HDR_SIZE)%4;
-    if(padding>0) padding = 4-padding;
+    if (padding>0) padding = 4-padding;
 
     {   char * t = malloc(nameSize + 1);
         rc = Fread(t, nameSize, 1, fd);
@@ -117,7 +117,7 @@ int cpioReadFileHdr(FD_t fd, struct stat * st, char** name)
         *name = t;
     }
 
-    if(padding){
+    if (padding){
       rc = Fread(paddingBuffer, padding, 1, fd);
       if (rc != 1) {
         free(*name);
diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index a94a20d..d439b1c 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -66,29 +66,29 @@ extern uint64_t flags;
 /* modprobe DD mode */
 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);
-    fclose(f);
-  }
+    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);
+        fclose(f);
+    }
 
-  return f==NULL;
+    return f==NULL;
 }
 
 int modprobeNormalmode()
 {
-  unlink("/etc/depmod.d/ddmode.conf");
+    unlink("/etc/depmod.d/ddmode.conf");
 
-  /* run depmod to refresh modules db */
-  if(system("depmod -a")){
-      logMessage(ERROR, "depmod -a failed");
-      return -1;
-  }
+    /* run depmod to refresh modules db */
+    if (system("depmod -a")) {
+        logMessage(ERROR, "depmod -a failed");
+        return -1;
+    }
 
-  return 0;
+    return 0;
 }
 
 /*
@@ -98,11 +98,11 @@ int modprobeNormalmode()
  */
 int dlabelProvides(const char* dep, void *userptr)
 {
-  char *kernelver = (char*)userptr;
+    char *kernelver = (char*)userptr;
 
-  logMessage(DEBUGLVL, "Provides: %s\n", dep);
+    logMessage(DEBUGLVL, "Provides: %s\n", dep);
 
-  return strcmp(dep, kernelver);
+    return strcmp(dep, kernelver);
 }
 
 /*
@@ -111,105 +111,106 @@ int dlabelProvides(const char* dep, void *userptr)
  */
 int dlabelFilter(const char* name, struct stat *fstat, void *userptr)
 {
-  int l = strlen(name);
-  
-  logMessage(DEBUGLVL, "Unpacking %s (%lluB)\n", name, fstat->st_size);
+    int l = strlen(name);
+
+    logMessage(DEBUGLVL, "Unpacking %s (%lluB)\n", name, fstat->st_size);
 
-  /* we want firmware files */
-  if(!strncmp("lib/firmware/", name, 13)) return 0; 
+    /* we want firmware files */
+    if (!strncmp("lib/firmware/", name, 13)) return 0; 
 
-  if(l<3) return 1;
-  l-=3;
+    if (l<3) return 1;
+    l-=3;
 
-  /* and we want only .ko files */
-  if(strcmp(".ko", name+l)) return 1;
+    /* and we want only .ko files */
+    if (strcmp(".ko", name+l)) return 1;
 
-  /* TODO we are unpacking kernel module, read it's description */
+    /* TODO we are unpacking kernel module, read it's description */
 
-  return 0;
+    return 0;
 }
 
 char* moduleDescription(const char* modulePath)
 {
-  char *command = NULL;
-  FILE *f = NULL;
-  char *description = NULL;
-  int size;
-  
-  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);
-    return NULL;
-  }
-
-  description[size-1]=0; /* strip the trailing newline */
-  pclose(f);
-
-  return description;
+    char *command = NULL;
+    FILE *f = NULL;
+    char *description = NULL;
+    int size;
+
+    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);
+        return NULL;
+    }
+
+    description[size-1]=0; /* strip the trailing newline */
+    pclose(f);
+
+    return description;
 }
 
 int globErrFunc(const char *epath, int eerrno)
 {
-  /* TODO check fatal errors */
-  return 0;
+    /* TODO check fatal errors */
+
+    return 0;
 }
 
 int dlabelUnpackRPMDir(char* rpmdir, char* destination)
 {
-  char *kernelver;
-  struct utsname unamedata;
-  char *oldcwd;
-  char *globpattern;
-  int rc;
- 
-  /* get current working directory */ 
-  oldcwd = getcwd(NULL, 0);
-
-  /* set the cwd to destination */
-  if(chdir(destination)){
-    logMessage(ERROR, _("We weren't able to CWD to %s"), destination)
+    char *kernelver;
+    struct utsname unamedata;
+    char *oldcwd;
+    char *globpattern;
+    int rc;
+
+    /* get current working directory */ 
+    oldcwd = getcwd(NULL, 0);
+
+    /* 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 */
+    rc = uname(&unamedata);
+    checked_asprintf(&kernelver, "kernel-modules-%s",
+            rc ? "unknown" : unamedata.release);
+    logMessage(DEBUGLVL, "Kernel version: %s\n", kernelver);
+
+    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, NULL, kernelver);
+        }
+        globfree(&globres);
+        /* end of iteration */
+    }
+    free(globpattern);
+
+    /* restore CWD */
+    if (chdir(oldcwd)) {
+        logMessage(WARNING, _("We weren't able to restore CWD to %s"), oldcwd)
+    }
+
+    /* cleanup */
+    free(kernelver);
     free(oldcwd);
-    return 1;
-  }
-
-  /* get running kernel version */
-  rc = uname(&unamedata);
-  checked_asprintf(&kernelver, "kernel-modules-%s",
-          rc ? "unknown" : unamedata.release);
-  logMessage(DEBUGLVL, "Kernel version: %s\n", kernelver);
-
-  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, NULL, kernelver);
-    }
-    globfree(&globres);
-    /* end of iteration */
-  }
-  free(globpattern);
-
-  /* restore CWD */
-  if(chdir(oldcwd)){
-   logMessage(WARNING, _("We weren't able to restore CWD to %s"), oldcwd)
-  }
-
-  /* cleanup */
-  free(kernelver);
-  free(oldcwd);
-  return rc;
+    return rc;
 }
 
 
@@ -298,7 +299,7 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
     copyDirectory(src, dest, copyWarnFn, copyErrorFn);
 
     /* unpack packages from dest into location->path */
-    if(dlabelUnpackRPMDir(dest, DD_EXTRACTED)){
+    if (dlabelUnpackRPMDir(dest, DD_EXTRACTED)) {
       /* fatal error, log this and jump to exception handler */
       logMessage(ERROR, _("Error unpacking RPMs from driver disc no.%d"),
               disknum);
@@ -306,7 +307,7 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
     }
 
     /* run depmod to refresh modules db */
-    if(system("depmod -a")){
+    if (system("depmod -a")) {
       /* this is not really fatal error, it might still work, log it */
       logMessage(ERROR, _("Error running depmod -a for driverdisc no.%d"));
     }
@@ -417,7 +418,7 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData,
             int nump = 0, num = 0;
 
             /* Do not crash if the device disappeared */
-            if(!part_list){
+            if (!part_list) {
               stage = DEV_DEVICE;
               break;
             }
@@ -491,7 +492,7 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData,
         }
 
         case DEV_LOADFILE: {
-            if(ddfile == NULL) {
+            if (ddfile == NULL) {
                 logMessage(DEBUGLVL, "trying to load dd from NULL");
                 stage = DEV_CHOOSEFILE;
                 break;
@@ -812,25 +813,25 @@ GSList* findDriverDiskByLabel(void)
     blkid_dev_iterate bIter;
     blkid_dev bDev;
 
-    if(blkid_get_cache(&bCache, NULL)<0){
+    if (blkid_get_cache(&bCache, NULL)<0) {
       logMessage(ERROR, _("Cannot initialize cache instance for blkid"));
       return NULL;
     }
-    if((res = blkid_probe_all(bCache))<0){
+    if ((res = blkid_probe_all(bCache))<0) {
       logMessage(ERROR, _("Cannot probe devices in blkid: %d"), res);
       return NULL;
     }
 
-    if((ddDevice = g_slist_alloc())==NULL){
+    if ((ddDevice = g_slist_alloc())==NULL) {
       logMessage(ERROR, _("Cannot allocate space for list of devices"));
       return NULL;
     }
 
     bIter = blkid_dev_iterate_begin(bCache);
     blkid_dev_set_search(bIter, "LABEL", ddLabel);
-    while((res = blkid_dev_next(bIter, &bDev))!=0){
+    while ((res = blkid_dev_next(bIter, &bDev))!=0) {
         bDev = blkid_verify(bCache, bDev);
-        if(!bDev)
+        if (!bDev)
           continue;
         logMessage(DEBUGLVL, _("Adding driver disc %s to the list of available DDs."), blkid_dev_devname(bDev));
         ddDevice = g_slist_prepend(ddDevice, blkid_dev_devname(bDev));
diff --git a/loader/loader.c b/loader/loader.c
index 4d7d5d7..c7f9938 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1889,7 +1889,7 @@ int main(int argc, char ** argv) {
 
     /* XXX if RHEL, enable the AUTODD feature by default,
      * but we should come with more general way how to control this */
-    if(!strncmp(getProductName(), "Red Hat", 7)){
+    if (!strncmp(getProductName(), "Red Hat", 7)) {
         flags |= LOADER_FLAGS_AUTOMODDISK;
     }
 
@@ -1960,16 +1960,16 @@ int main(int argc, char ** argv) {
     /* Setup depmod & modprobe so we can load multiple DDs */
     modprobeDDmode();
 
-    if(FL_AUTOMODDISK(flags)){
+    if (FL_AUTOMODDISK(flags)) {
         /* Load all autodetected DDs */
         logMessage(INFO, "Trying to detect vendor driver discs");
         dd = findDriverDiskByLabel();
         dditer = dd;
-        while(dditer){
-            if(loadDriverDiskFromPartition(&loaderData, dditer->device)){
+        while(dditer) {
+            if (loadDriverDiskFromPartition(&loaderData, dditer->device)) {
                 logMessage(ERROR, "Automatic driver disk loader failed for %s.", dditer->device);
             }
-            else{
+            else {
                 logMessage(INFO, "Automatic driver disk loader succeeded for %s.", dditer->device);
             }
             dditer = g_slist_next(dditer);
diff --git a/loader/rpmextract.c b/loader/rpmextract.c
index ca741ad..19c5845 100644
--- a/loader/rpmextract.c
+++ b/loader/rpmextract.c
@@ -76,41 +76,41 @@ int explodeRPM(const char *source,
     }
 
     /* Retrieve all dependencies and run them through deps function */
-    while(deps){
+    while (deps){
         struct rpmtd_s td;
         const char *depname;
 
         if (!headerGet(h, RPMTAG_REQUIRENAME, &td, HEADERGET_MINMEM))
-          break;
+            break;
 
         /* iterator */
         while ((depname = rpmtdNextString(&td))) {
-          if(deps(depname, userptr)){
-            Fclose(fdi);
-            return EXIT_BADDEPS;
-          }
+            if (deps(depname, userptr)) {
+                Fclose(fdi);
+                return EXIT_BADDEPS;
+            }
         }
         rpmtdFreeData(&td);
         break;
     }
 
     /* Retrieve all provides and run them through provides function */
-    while(provides){
+    while (provides){
         struct rpmtd_s td;
         const char *depname;
         int found = 0;
 
         if (!headerGet(h, RPMTAG_PROVIDES, &td, HEADERGET_MINMEM))
-          break;
+            break;
 
         /* iterator */
         while ((depname = rpmtdNextString(&td))) {
-          if(!provides(depname, userptr)){
-            found++;
-          }
+            if (!provides(depname, userptr)) {
+                found++;
+            }
         }
         rpmtdFreeData(&td);
-        if(found<=0)
+        if (found<=0)
             return EXIT_BADDEPS;
         break;
     }
@@ -118,7 +118,7 @@ int explodeRPM(const char *source,
     /* Retrieve type of payload compression. */
     {   
         const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
-        if(compr && strcmp(compr, "gzip")) rpmio_flags = rstrscat(NULL, "r.", compr, "dio", NULL);
+        if (compr && strcmp(compr, "gzip")) rpmio_flags = rstrscat(NULL, "r.", compr, "dio", NULL);
         else rpmio_flags = rstrscat(NULL, "r.", "gzdio", NULL);
     }
 
@@ -130,94 +130,94 @@ int explodeRPM(const char *source,
         return EXIT_FAILURE;
     }
 
-    while(!rc){
-      char *filename = NULL;
-      struct stat fstat;
-      int offset = 0;
-      int towrite = 1;
+    while (!rc){
+        char *filename = NULL;
+        struct stat fstat;
+        int offset = 0;
+        int towrite = 1;
+
+        rc = cpioReadFileHdr(gzdi, &fstat, &filename);
+        if (rc == CPIOERR_HDR_TRAILER) {
+            rc = 0;
+            break;
+        } else if (rc != 0) {
+            break;
+        }
 
-      rc = cpioReadFileHdr(gzdi, &fstat, &filename);
-      if(rc == CPIOERR_HDR_TRAILER){
-        rc = 0;
-        break;
-      } else if(rc != 0){
-        break;
-      }
-
-      /* Strip leading slashes */
-      while(filename[offset] == '/') offset+=1;
-      /* Strip leading ./ */
-      while(filename[offset] == '.' && filename[offset+1] == '/') offset+=2;
-
-      /* Other file type - we do not care except special cases */
-      if(!S_ISREG(fstat.st_mode)) towrite = 1;
-      else towrite = 2;
-
-      if(filter && filter(filename+offset, &fstat, userptr)){
-        /* filter this file */
-        towrite = 0;
-      }
-
-      /* Create directories */
-      char* dirname = strdup(filename+offset);
-      char* dirptr = dirname;
-      while(dirptr!=NULL && *dirptr!=0){
-        dirptr = strchr(dirptr, '/');
-        if(dirptr){
-          *dirptr = 0;
-          mkdir(dirname, 0700);
-          *dirptr = '/';
-          dirptr++;
+        /* Strip leading slashes */
+        while (filename[offset] == '/') offset+=1;
+        /* Strip leading ./ */
+        while (filename[offset] == '.' && filename[offset+1] == '/') offset+=2;
+
+        /* Other file type - we do not care except special cases */
+        if (!S_ISREG(fstat.st_mode)) towrite = 1;
+        else towrite = 2;
+
+        if (filter && filter(filename+offset, &fstat, userptr)) {
+            /* filter this file */
+            towrite = 0;
         }
-      }
-      free(dirname);
-      
-      /* Regular file */
-      long readbytes = 0;
-      long padding = fstat.st_size%4;
-      FILE *fdout = NULL;
-      if(padding>0) padding = 4-padding;
-
-      if(towrite>=2){
-        fdout = fopen(filename+offset, "w");
-
-        if(fdout==NULL){
-          free(filename);
-          rc = 33;
-          break;
+
+        /* Create directories */
+        char* dirname = strdup(filename+offset);
+        char* dirptr = dirname;
+        while (dirptr!=NULL && *dirptr!=0){
+            dirptr = strchr(dirptr, '/');
+            if (dirptr) {
+                *dirptr = 0;
+                mkdir(dirname, 0700);
+                *dirptr = '/';
+                dirptr++;
+            }
         }
-      }
-
-      while(1){
-        long toread = (BUFFERSIZE>fstat.st_size) ? fstat.st_size : BUFFERSIZE;
-        if(toread<=0) break;
-        readbytes = Fread(buffer, toread, 1, gzdi);
-        if(readbytes<=0){
-          rc = 34; //truncated archive? set error flag...
-          break;
+        free(dirname);
+
+        /* Regular file */
+        long readbytes = 0;
+        long padding = fstat.st_size%4;
+        FILE *fdout = NULL;
+        if (padding>0) padding = 4-padding;
+
+        if (towrite>=2){
+            fdout = fopen(filename+offset, "w");
+
+            if (fdout==NULL){
+                free(filename);
+                rc = 33;
+                break;
+            }
         }
-        else{
-          fstat.st_size-=toread;
-          if(towrite>=2)
-            if(fwrite(buffer, toread, 1, fdout)!=1){
-              /* TODO: error handling */
+
+        while (1) {
+            long toread = (BUFFERSIZE>fstat.st_size) ? fstat.st_size : BUFFERSIZE;
+            if (toread<=0) break;
+            readbytes = Fread(buffer, toread, 1, gzdi);
+            if (readbytes<=0) {
+                rc = 34; //truncated archive? set error flag...
+                break;
+            }
+            else {
+                fstat.st_size-=toread;
+                if (towrite>=2)
+                    if (fwrite(buffer, toread, 1, fdout)!=1) {
+                        /* TODO: error handling */
+                    }
+                buffer[toread] = 0;
             }
-          buffer[toread] = 0;
         }
-      }
 
-      /* symlink, we assume that the path comtained in symlink
-       * is shorter than BUFFERSIZE */
-      if(towrite && !rc && S_ISLNK(fstat.st_mode)){
-        if(symlink(buffer, filename+offset)){
-          /* TODO: error handling */
+        /* symlink, we assume that the path comtained in symlink
+         * is shorter than BUFFERSIZE */
+        if (towrite && !rc && S_ISLNK(fstat.st_mode)) {
+            if (symlink(buffer, filename+offset)) {
+                /* TODO: error handling */
+            }
         }
-      }
 
-      free(filename);
-      if(towrite>=2) fclose(fdout);
+        free(filename);
+        if (towrite>=2) fclose(fdout);
 
-      if(padding) readbytes = Fread(buffer, padding, 1, gzdi);
+        if (padding) readbytes = Fread(buffer, padding, 1, gzdi);
     }
 
 
-- 
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