]> git.saurik.com Git - apt.git/blobdiff - methods/rsh.cc
fix program name detection in rsh method
[apt.git] / methods / rsh.cc
index 44aa7084d02b3592eedbf1bbb2ef2109031bc546..9d82a99e3dd8aa2e366bebec11ce87d7346b8fd8 100644 (file)
@@ -34,7 +34,6 @@
 #include <apti18n.h>
                                                                        /*}}}*/
 
-const char *Prog;
 unsigned long TimeOut = 120;
 Configuration::Item const *RshOptions = 0;
 time_t RSHMethod::FailTime = 0;
@@ -44,8 +43,8 @@ int RSHMethod::FailFd = -1;
 // RSHConn::RSHConn - Constructor                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-RSHConn::RSHConn(URI Srv) : Len(0), WriteFd(-1), ReadFd(-1),
-                            ServerName(Srv), Process(-1) {
+RSHConn::RSHConn(std::string const &pProg, URI Srv) : Len(0), WriteFd(-1), ReadFd(-1),
+                            ServerName(Srv), Prog(pProg), Process(-1) {
    Buffer[0] = '\0';
 }
                                                                        /*}}}*/
@@ -128,7 +127,7 @@ bool RSHConn::Connect(std::string Host, unsigned int Port, std::string User)
       // Probably should do
       // dup2(open("/dev/null",O_RDONLY),STDERR_FILENO);
 
-      Args[i++] = Prog;
+      Args[i++] = Prog.c_str();
 
       // Insert user-supplied command line options
       Configuration::Item const *Opts = RshOptions;
@@ -387,7 +386,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
 // RSHMethod::RSHMethod - Constructor                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
+RSHMethod::RSHMethod(std::string const &pProg) : aptMethod(pProg.c_str(),"1.0",SendConfig), Prog(pProg)
 {
    signal(SIGTERM,SigTerm);
    signal(SIGINT,SigTerm);
@@ -399,15 +398,13 @@ RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
 // ---------------------------------------------------------------------
 bool RSHMethod::Configuration(std::string Message)
 {
-   char ProgStr[100];
-  
-   if (pkgAcqMethod::Configuration(Message) == false)
+   if (aptMethod::Configuration(Message) == false)
       return false;
 
-   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Timeout", Prog);
-   TimeOut = _config->FindI(ProgStr,TimeOut);
-   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Options", Prog);
-   RshOptions = _config->Tree(ProgStr);
+   std::string const timeconf = std::string("Acquire::") + Prog + "::Timeout";
+   TimeOut = _config->FindI(timeconf, TimeOut);
+   std::string const optsconf = std::string("Acquire::") + Prog + "::Options";
+   RshOptions = _config->Tree(optsconf.c_str());
 
    return true;
 }
@@ -445,7 +442,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
    // Connect to the server
    if (Server == 0 || Server->Comp(Get) == false) {
       delete Server;
-      Server = new RSHConn(Get);
+      Server = new RSHConn(Prog, Get);
    }
 
    // Could not connect is a transient error..
@@ -548,8 +545,6 @@ int main(int, const char *argv[])
 {
    setlocale(LC_ALL, "");
 
-   RSHMethod Mth;
-   Prog = strrchr(argv[0],'/');
-   Prog++;
+   RSHMethod Mth(flNotDir(argv[0]));
    return Mth.Run();
 }