Index: src/dird/ua_cmds.c
===================================================================
RCS file: /var/lib/cvs/bupdater36/dird/ua_cmds.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- src/dird/ua_cmds.c	21 Oct 2004 15:34:10 -0000	1.1.1.1
+++ src/dird/ua_cmds.c	18 Nov 2004 11:17:34 -0000	1.3
@@ -89,6 +89,7 @@
 static int setip_cmd(UAContext *ua, const char *cmd);
 static void do_job_delete(UAContext *ua, JobId_t JobId);
 static void delete_job_id_range(UAContext *ua, char *tok);
+static int upgrade_client_cmd(UAContext *ua, const char *cmd);
 
 int qhelp_cmd(UAContext *ua, const char *cmd);
 int quit_cmd(UAContext *ua, const char *cmd);
@@ -134,6 +135,7 @@
  { N_("var"),        var_cmd,       _("does variable expansion")},
  { N_("version"),    version_cmd,   _("print Director version")},
  { N_("wait"),       wait_cmd,      _("wait until no jobs are running")},
+ { N_("upgrade"),    upgrade_client_cmd,      _("upgrade client to new version")},
 	     };
 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
 
@@ -2025,5 +2027,61 @@
       if (ua->jcr) {
 	 ua->jcr->db = NULL;
       }
+   }
+}
+
+static int upgrade_client_cmd(UAContext *ua, const char *cmd)
+{
+   CLIENT *client = NULL;
+   BSOCK *fd;
+   
+   if (!open_db(ua)) {
+   	return 1;
+   }
+   Dmsg1(20, "upgrade_client_cmd:%s\n", cmd);
+
+   if (ua->argc == 1) {
+     bsendmsg(ua, _("Please, put a client name to upgrade\n"));
+     bsendmsg(ua, _("Ex: upgrade myclientname-fd URL\n"));
+     return 1;
+   } else if (ua->argc == 2) {
+     bsendmsg(ua, _("Please, put a URL where download update\n"));
+     bsendmsg(ua, _("Ex: upgrade %s URL\n"),_(ua->argk[1]));
+     return 1;
+   }
+   
+      
+   client = (CLIENT *)GetResWithName(R_CLIENT, ua->argk[1]);
+   if (client) {
+      ua->jcr->client = client;
+      if (ua->jcr->sd_auth_key) {
+      	 free(ua->jcr->sd_auth_key);
+      }
+   ua->jcr->sd_auth_key = bstrdup("dummy");
+   
+   bsendmsg(ua, _("Connecting to client %s at %s:%d\n"),
+      client->hdr.name, client->address, client->FDport);
+   if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
+      bsendmsg(ua, _("Failed to connect to client %s,\n====\n"),
+         client->hdr.name);
+      if (ua->jcr->file_bsock) {
+         bnet_close(ua->jcr->file_bsock);
+         ua->jcr->file_bsock = NULL;
+      }
+      return 1;
+   }
+   Dmsg0(20, _("Connected to file daemon\n"));
+   fd = ua->jcr->file_bsock;
+   bnet_fsend(fd, "upgrade %s",ua->argk[2]);
+   while (bnet_recv(fd) >=0) {
+      bsendmsg(ua, "%s", fd->msg);
+   }
+   bnet_sig(fd, BNET_TERMINATE);
+   bnet_close(fd);
+   ua->jcr->file_bsock = NULL;
+   return 0;
+   } else {
+   bsendmsg(ua, _("Error: Client resource %s does not exist.\n"), ua->argk[1]);
+   return 1;
    }
 }
Index: src/filed/job.c
===================================================================
RCS file: /var/lib/cvs/bupdater36/filed/job.c,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -r1.1.1.1 -r1.4
--- src/filed/job.c	21 Oct 2004 15:34:10 -0000	1.1.1.1
+++ src/filed/job.c	18 Nov 2004 11:17:43 -0000	1.4
@@ -60,7 +60,7 @@
 static int runafter_cmd(JCR *jcr);
 static int run_cmd(JCR *jcr, char *cmd, const char *name);
 static void set_options(findFOPTS *fo, const char *opts);
-
+static int upgrade_cmd(JCR *jcr);
 
 /* Exported functions */
 
@@ -93,6 +93,7 @@
    {"bootstrap",    bootstrap_cmd, 0},
    {"RunBeforeJob", runbefore_cmd, 0},
    {"RunAfterJob",  runafter_cmd,  0},
+   {"upgrade",      upgrade_cmd,  0},
    {NULL,	NULL}		       /* list terminator */
 };
 
@@ -106,6 +107,7 @@
 static char estimatecmd[] = "estimate listing=%d\n";
 static char runbefore[]   = "RunBeforeJob %s\n";
 static char runafter[]    = "RunAfterJob %s\n";
+static char upgradecmd[]  = "upgrade %s\n";
 
 /* Responses sent to Director */
 static char errmsg[]      = "2999 Invalid command\n";
@@ -1616,4 +1618,38 @@
    }
 
    return stat;
+}
+
+
+static int upgrade_cmd(JCR *jcr)
+{
+   BSOCK *dir = jcr->dir_bsock;
+   POOLMEM *cmd = get_memory(dir->msglen+1);
+   POOLMEM *run = get_memory(dir->msglen+1);
+
+   Dmsg1(100, " upgrade_cmd: %s", dir->msg);
+   if (sscanf(dir->msg, upgradecmd, cmd) != 1) {
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      Jmsg1(jcr, M_FATAL, 0, _("Bad upgrade command: %s\n"), jcr->errmsg);
+      bnet_fsend(dir, "2905 Bad upgrade command.\n");
+      free_memory(run);
+      free_memory(cmd);
+      return 0;
+   }
+   unbash_spaces(cmd);
+   
+   bnet_fsend(dir, "2000 Upgrade command successfully received. Now in progress.\n");
+
+   /* Run the command now */   
+   Dmsg1(100, " url: %s", cmd);
+   pm_strcpy (run, "/bin/bupdater.sh ");
+   pm_strcat (run,cmd);
+   Dmsg1(100, " run_cmd: %s", run);
+   bnet_sig(dir, BNET_TERMINATE);
+   free_memory(cmd);
+   system(run);
+   
+   /* If all is ok, it will never reach this.  */
+   free_memory(run);
+return 0;
 }
Index: src/lib/bpipe.c
===================================================================
RCS file: /var/lib/cvs/bupdater36/lib/bpipe.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- src/lib/bpipe.c	21 Oct 2004 15:34:10 -0000	1.1.1.1
+++ src/lib/bpipe.c	12 Nov 2004 12:07:53 -0000	1.2
@@ -220,7 +220,7 @@
       if (WIFEXITED(chldstatus)) {    /* process exit()ed */
 	 stat = WEXITSTATUS(chldstatus);
 	 if (stat != 0) {
-            Dmsg1(100, "Non-zero status %s returned from child.\n", stat);
+            Dmsg1(100, "Non-zero status %d returned from child.\n", stat);
 	    stat |= b_errno_exit;	 /* exit status returned */
 	 }
          Dmsg1(200, "child status=%d\n", stat & ~b_errno_exit);
@@ -229,7 +229,7 @@
          Dmsg1(200, "Child died from signale %d\n", stat);
 	 stat |= b_errno_signal;      /* exit signal returned */
       }
-   }	   
+   }      
    if (bpipe->timer_id) {
       stop_child_timer(bpipe->timer_id);
    }
