}
-void print_child_argv(char **cmd)
+static void print_child_argv(char **cmd)
{
rprintf(FINFO, "opening connection using ");
for (; *cmd; cmd++) {
static pid_t all_pids[10];
static int num_pids;
-/* fork and record the pid of the child */
+/** Fork and record the pid of the child. **/
pid_t do_fork(void)
{
pid_t newpid = fork();
- if (newpid) {
+ if (newpid != 0 && newpid != -1) {
all_pids[num_pids++] = newpid;
}
return newpid;
}
-/* kill all children */
+/**
+ * Kill all children.
+ *
+ * @todo It would be kind of nice to make sure that they are actually
+ * all our children before we kill them, because their pids may have
+ * been recycled by some other process. Perhaps when we wait for a
+ * child, we should remove it from this array. Alternatively we could
+ * perhaps use process groups, but I think that would not work on
+ * ancient Unix versions that don't support them.
+ **/
void kill_all(int sig)
{
int i;
- for (i=0;i<num_pids;i++) {
- if (all_pids[i] != getpid())
- kill(all_pids[i], sig);
+
+ for (i = 0; i < num_pids; i++) {
+ /* Let's just be a little careful where we
+ * point that gun, hey? See kill(2) for the
+ * magic caused by negative values. */
+ pid_t p = all_pids[i];
+
+ if (p == getpid())
+ continue;
+ if (p <= 0)
+ continue;
+
+ kill(p, sig);
}
}
+
/* turn a user name into a uid */
int name_to_uid(char *name, uid_t *uid)
{
unsigned long diff = msdiff(&start_time, now);
double rate = diff ? (double) (ofs-start_ofs) * 1000.0 / diff / 1024.0 : 0;
const char *units;
- double remain = rate ? (double) (size-ofs) / rate / 1000.0: 0.0;
+ /* If we've finished transferring this file, show the time taken;
+ * otherwise show expected time to complete. That's kind of
+ * inconsistent, but people can probably cope. Hopefully we'll
+ * get more consistent and complete progress reporting soon. --
+ * mbp */
+ double remain = is_last
+ ? (double) diff / 1000.0
+ : rate ? (double) (size-ofs) / rate / 1000.0 : 0.0;
int remain_h, remain_m, remain_s;
if (rate > 1024*1024) {