[BACK]Return to child.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rsync

Annotation of src/usr.bin/rsync/child.c, Revision 1.2

1.1       benno       1: /*     $Id$ */
                      2: /*
                      3:  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #include <sys/stat.h>
                     18:
                     19: #include <assert.h>
                     20: #include <stdint.h>
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: #include <string.h>
                     24: #include <unistd.h>
                     25:
                     26: #include "extern.h"
                     27:
                     28: /*
                     29:  * This is run on the client machine to initiate a connection with the
                     30:  * remote machine in --server mode.
                     31:  * It does not return, as it executes into the remote shell.
                     32:  *
                     33:  * Pledges: exec, stdio.
                     34:  */
                     35: void
                     36: rsync_child(const struct opts *opts, int fd, const struct fargs *f)
                     37: {
                     38:        struct sess       sess;
                     39:        char            **args;
                     40:        size_t            i;
                     41:
                     42:        memset(&sess, 0, sizeof(struct sess));
                     43:        sess.opts = opts;
                     44:
                     45:        /* Construct the remote shell command. */
                     46:
                     47:        if (NULL == (args = fargs_cmdline(&sess, f))) {
                     48:                ERRX1(&sess, "fargs_cmdline");
                     49:                exit(EXIT_FAILURE);
                     50:        }
                     51:
                     52:        for (i = 0; NULL != args[i]; i++)
                     53:                LOG2(&sess, "exec[%zu] = %s", i, args[i]);
                     54:
                     55:        /* Make sure the child's stdin is from the sender. */
                     56:
                     57:        if (-1 == dup2(fd, STDIN_FILENO)) {
                     58:                ERR(&sess, "dup2");
                     59:                exit(EXIT_FAILURE);
                     60:        } if (-1 == dup2(fd, STDOUT_FILENO)) {
                     61:                ERR(&sess, "dup2");
                     62:                exit(EXIT_FAILURE);
                     63:        }
                     64:
                     65:        /* Here we go... */
                     66:
                     67:        execvp(args[0], args);
                     68:
                     69:        ERR(&sess, "%s: execvp", args[0]);
                     70:        exit(EXIT_FAILURE);
                     71:        /* NOTREACHED */
                     72: }