Explorar o código

* apt-pkg/acquire-worker.cc:
- check return of write() as gcc recommends
* apt-pkg/acquire.cc:
- check return of write() as gcc recommends
* apt-pkg/cdrom.cc:
- check return of chdir() and link() as gcc recommends
* apt-pkg/clean.cc:
- check return of chdir() as gcc recommends
* apt-pkg/contrib/netrc.cc:
- check return of asprintf() as gcc recommends

David Kalnischkies %!s(int64=14) %!d(string=hai) anos
pai
achega
31bda50001
Modificáronse 6 ficheiros con 58 adicións e 12 borrados
  1. 17 1
      apt-pkg/acquire-worker.cc
  2. 17 1
      apt-pkg/acquire.cc
  3. 4 2
      apt-pkg/cdrom.cc
  4. 7 4
      apt-pkg/clean.cc
  5. 1 2
      apt-pkg/contrib/netrc.cc
  6. 12 2
      debian/changelog

+ 17 - 1
apt-pkg/acquire-worker.cc

@@ -431,7 +431,23 @@ bool pkgAcquire::Worker::MediaChange(string Message)
 	     << Drive  << ":"     // drive
 	     << msg.str()         // l10n message
 	     << endl;
-      write(status_fd, status.str().c_str(), status.str().size());
+
+      std::string const dlstatus = status.str();
+      size_t done = 0;
+      size_t todo = dlstatus.size();
+      errno = 0;
+      int res = 0;
+      do
+      {
+	 res = write(status_fd, dlstatus.c_str() + done, todo);
+	 if (res < 0 && errno == EINTR)
+	    continue;
+	 if (res < 0)
+	    break;
+	 done += res;
+	 todo -= res;
+      }
+      while (res > 0 && todo > 0);
    }
 
    if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"),

+ 17 - 1
apt-pkg/acquire.cc

@@ -872,7 +872,23 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
 	     << ":"  << (CurrentBytes/float(TotalBytes)*100.0) 
 	     << ":" << msg 
 	     << endl;
-      write(fd, status.str().c_str(), status.str().size());
+
+      std::string const dlstatus = status.str();
+      size_t done = 0;
+      size_t todo = dlstatus.size();
+      errno = 0;
+      int res = 0;
+      do
+      {
+	 res = write(fd, dlstatus.c_str() + done, todo);
+	 if (res < 0 && errno == EINTR)
+	    continue;
+	 if (res < 0)
+	    break;
+	 done += res;
+	 todo -= res;
+      }
+      while (res > 0 && todo > 0);
    }
 
    return true;

+ 4 - 2
apt-pkg/cdrom.cc

@@ -430,7 +430,8 @@ bool pkgCdrom::WriteDatabase(Configuration &Cnf)
 
    Out.close();
    
-   link(DFile.c_str(),string(DFile + '~').c_str());
+   if (FileExists(DFile) == true && link(DFile.c_str(),string(DFile + '~').c_str()) != 0)
+      return _error->Errno("link", "Failed to link %s to %s~", DFile.c_str(), DFile.c_str());
    if (rename(NewFile.c_str(),DFile.c_str()) != 0)
       return _error->Errno("rename","Failed to rename %s.new to %s",
 			   DFile.c_str(),DFile.c_str());
@@ -697,7 +698,8 @@ bool pkgCdrom::Add(pkgCdromStatus *log)					/*{{{*/
       return false;
    }
 
-   chdir(StartDir.c_str());
+   if (chdir(StartDir.c_str()) != 0)
+      return _error->Errno("chdir","Unable to change to %s", StartDir.c_str());
 
    if (_config->FindB("Debug::aptcdrom",false) == true)
    {

+ 7 - 4
apt-pkg/clean.cc

@@ -54,9 +54,11 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
       struct stat St;
       if (stat(Dir->d_name,&St) != 0)
       {
-	 chdir(StartDir.c_str());
+	 _error->Errno("stat",_("Unable to stat %s."),Dir->d_name);
 	 closedir(D);
-	 return _error->Errno("stat",_("Unable to stat %s."),Dir->d_name);
+	 if (chdir(StartDir.c_str()) != 0)
+	    return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str());
+	 return false;
       }
       
       // Grab the package name
@@ -115,8 +117,9 @@ bool pkgArchiveCleaner::Go(std::string Dir,pkgCache &Cache)
       Erase(Dir->d_name,Pkg,Ver,St);
    };
    
-   chdir(StartDir.c_str());
    closedir(D);
-   return true;   
+   if (chdir(StartDir.c_str()) != 0)
+      return _error->Errno("chdir", _("Unable to change to %s"), StartDir.c_str());
+   return true;
 }
 									/*}}}*/

+ 1 - 2
apt-pkg/contrib/netrc.cc

@@ -68,8 +68,7 @@ int parsenetrc (char *host, char *login, char *password, char *netrcfile = NULL)
     if (!home)
       return -1;
 
-    asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC);
-    if(!netrcfile)
+    if (asprintf (&netrcfile, "%s%s%s", home, DIR_CHAR, NETRC) == -1 || netrcfile == NULL)
       return -1;
     else
       netrc_alloc = true;

+ 12 - 2
debian/changelog

@@ -3,14 +3,24 @@ apt (0.8.16~exp14) UNRELEASED; urgency=low
   [ Michael Vogt ]
   * apt-pkg/packagemanager.cc:
     - fix inconsistent clog/cout usage in the debug output
-  
+
   [ David Kalnischkies ]
   * apt-pkg/packagemanager.cc:
     - recheck all dependencies if we changed a package in SmartConfigure
       as this could break an earlier dependency (LP: #940396)
     - recheck dependencies in SmartUnpack after a change, too
+  * apt-pkg/acquire-worker.cc:
+    - check return of write() as gcc recommends
+  * apt-pkg/acquire.cc:
+    - check return of write() as gcc recommends
+  * apt-pkg/cdrom.cc:
+    - check return of chdir() and link() as gcc recommends
+  * apt-pkg/clean.cc:
+    - check return of chdir() as gcc recommends
+  * apt-pkg/contrib/netrc.cc:
+    - check return of asprintf() as gcc recommends
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Tue, 13 Mar 2012 12:38:35 +0100
+ -- David Kalnischkies <kalnischkies@gmail.com>  Tue, 20 Mar 2012 17:00:14 +0100
 
 apt (0.8.16~exp13) experimental; urgency=low