9 #include "SpawningUploadClient.h"
11 SpawningUploadClient::SpawningUploadClient()
20 SpawningUploadClient::~SpawningUploadClient()
23 kill(fCommandPid
, SIGTERM
);
24 kill(fCommandPid
, SIGKILL
);
26 wait_for_thread(fCommandPid
, &ret
);
31 SpawningUploadClient::Connect(const string
& server
, const string
& login
, const string
& passwd
)
35 // fCommand += server;
42 SpawningUploadClient::SpawnCommand()
46 //XXX: should use a system-provided TerminalCommand class
47 BString shellcmd
= "exec";
48 const char *args
[] = { "/bin/sh", "-c", NULL
, NULL
};
49 fPty
= getpty(ptypath
, ttypath
);
53 shellcmd
<< " 0<" << ttypath
;
54 shellcmd
<< " 1>" << ttypath
;
57 shellcmd
<< "export TTY=" << ttypath
<< "; "; // BeOS hack
58 shellcmd
<< "export LC_ALL=C; export LANG=C; ";
60 shellcmd
<< fCommand
.c_str();
61 printf("spawning: '%s'\n", shellcmd
.String());
62 args
[2] = shellcmd
.String();
63 fCommandPid
= load_image(3, args
, (const char **)environ
);
66 resume_thread(fCommandPid
);
72 SpawningUploadClient::SetCommandLine(const char *command
)
80 SpawningUploadClient::SendCommand(const char *cmd
)
82 return write(InputPipe(), cmd
, strlen(cmd
));
87 SpawningUploadClient::ReadReply(BString
*to
)
92 len
= read(OutputPipe(), buff
, 1024);
95 to
->Append(buff
, len
);
101 SpawningUploadClient::ParseReply()
108 SpawningUploadClient::getpty(char *pty
, char *tty
)
110 static const char major
[] = "pqrs";
111 static const char minor
[] = "0123456789abcdef";
115 for (i
= 0; i
< sizeof(major
); i
++)
117 for (j
= 0; j
< sizeof(minor
); j
++)
119 sprintf(pty
, "/dev/pt/%c%c", major
[i
], minor
[j
]);
120 sprintf(tty
, "/dev/tt/%c%c", major
[i
], minor
[j
]);
121 fd
= open(pty
, O_RDWR
|O_NOCTTY
);
133 /* the rest is empty */
137 SpawningUploadClient::ChangeDir(const string
& dir
)
145 SpawningUploadClient::ListDirContents(string
& listing
)
153 SpawningUploadClient::PrintWorkingDir(string
& dir
)
161 SpawningUploadClient::PutFile(const string
& local
, const string
& remote
, ftp_mode mode
)
169 SpawningUploadClient::GetFile(const string
& remote
, const string
& local
, ftp_mode mode
)
176 // Note: this only works for local remote moves, cross filesystem moves
179 SpawningUploadClient::MoveFile(const string
& oldPath
, const string
& newPath
)
187 SpawningUploadClient::Chmod(const string
& path
, const string
& mod
)
195 SpawningUploadClient::SetPassive(bool on
)