本文整理汇总了C++中rs_trace函数的典型用法代码示例。如果您正苦于以下问题:C++ rs_trace函数的具体用法?C++ rs_trace怎么用?C++ rs_trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rs_trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dcc_select_for_write
int dcc_select_for_write(int fd, int timeout)
{
fd_set fds;
int rs;
struct timeval tv;
tv.tv_sec = timeout;
tv.tv_usec = 0;
while (1) {
FD_ZERO(&fds);
FD_SET(fd, &fds);
rs_trace("select for write on fd%d", fd);
rs = select(fd + 1, NULL, &fds, &fds, &tv);
if (rs == -1 && errno == EINTR) {
rs_trace("select was interrupted");
continue;
} else if (rs == -1) {
rs_log_error("select failed: %s", strerror(errno));
return EXIT_IO_ERROR;
} else {
return 0;
}
}
}
示例2: dcc_spawn_child
/**
* Run @p argv in a child asynchronously.
*
* stdin, stdout and stderr are redirected as shown, unless those
* filenames are NULL. In that case they are left alone.
*
* @warning When called on the daemon, where stdin/stdout may refer to random
* network sockets, all of the standard file descriptors must be redirected!
**/
int dcc_spawn_child(char **argv, pid_t *pidptr,
const char *stdin_file,
const char *stdout_file,
const char *stderr_file)
{
pid_t pid;
dcc_trace_argv("forking to execute", argv);
pid = fork();
if (pid == -1) {
rs_log_error("failed to fork: %s", strerror(errno));
return EXIT_OUT_OF_MEMORY; /* probably */
} else if (pid == 0) {
/* If this is a remote compile,
* put the child in a new group, so we can
* kill it and all its descendents without killing distccd
* FIXME: if you kill distccd while it's compiling, and
* the compiler has an infinite loop bug, the new group
* will run forever until you kill it.
*/
if (stdout_file != NULL) {
if (dcc_new_pgrp() != 0)
rs_trace("Unable to start a new group\n");
}
dcc_inside_child(argv, stdin_file, stdout_file, stderr_file);
/* !! NEVER RETURN FROM HERE !! */
} else {
*pidptr = pid;
rs_trace("child started as pid%d", (int) pid);
return 0;
}
}
示例3: rs_scoop_readahead
/** Read from scoop without advancing.
*
* Ask for LEN bytes of input from the stream. If that much data is available,
* then return a pointer to it in PTR, advance the stream input pointer over
* the data, and return RS_DONE. If there's not enough data, then accept
* whatever is there into a buffer, advance over it, and return RS_BLOCKED.
*
* The data is not actually removed from the input, so this function lets you
* do readahead. If you want to keep any of the data, you should also call
* rs_scoop_advance() to skip over it. */
rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
{
rs_buffers_t *stream = job->stream;
rs_job_check(job);
if (!job->scoop_avail && stream->avail_in >= len) {
/* The scoop is empty and there's enough data in the input. */
*ptr = stream->next_in;
rs_trace("got " FMT_SIZE " bytes direct from input", len);
return RS_DONE;
} else if (job->scoop_avail < len && stream->avail_in) {
/* There is not enough data in the scoop. */
rs_trace("scoop has less than " FMT_SIZE " bytes, scooping from "
FMT_SIZE " input bytes", len, stream->avail_in);
rs_scoop_input(job, len);
}
if (job->scoop_avail >= len) {
/* There is enough data in the scoop now. */
rs_trace("scoop has at least " FMT_SIZE " bytes, this is enough",
job->scoop_avail);
*ptr = job->scoop_next;
return RS_DONE;
} else if (stream->eof_in) {
/* Not enough input data and at EOF. */
rs_trace("reached end of input stream");
return RS_INPUT_ENDED;
} else {
/* Not enough input data yet. */
rs_trace("blocked with insufficient input data");
return RS_BLOCKED;
}
}
示例4: rs_buffers_copy
/**
* \brief Copy up to \p max_len bytes from input of \b stream to its output.
*
* Return the number of bytes actually copied, which may be less than
* LEN if there is not enough space in one or the other stream.
*
* This always does the copy immediately. Most functions should call
* rs_tube_copy() to cause the copy to happen gradually as space
* becomes available.
*/
int rs_buffers_copy(rs_buffers_t *stream, int max_len)
{
int len = max_len;
assert(len > 0);
if ((unsigned) len > stream->avail_in) {
rs_trace("copy limited to "FMT_SIZE" available input bytes", stream->avail_in);
len = stream->avail_in;
}
if ((unsigned) len > stream->avail_out) {
rs_trace("copy limited to "FMT_SIZE" available output bytes", stream->avail_out);
len = stream->avail_out;
}
if (!len)
return 0;
/* rs_trace("stream copied chunk of %d bytes", len); */
memcpy(stream->next_out, stream->next_in, len);
stream->next_out += len;
stream->avail_out -= len;
stream->next_in += len;
stream->avail_in -= len;
return len;
}
示例5: rs_sig_s_generate
/*
* State of reading a block and trying to generate its sum.
*/
static rs_result
rs_sig_s_generate(rs_job_t *job)
{
rs_result result;
size_t len;
void *block;
/* must get a whole block, otherwise try again */
len = job->block_len;
result = rs_scoop_read(job, len, &block);
/* unless we're near eof, in which case we'll accept
* whatever's in there */
if ((result == RS_BLOCKED && rs_job_input_is_ending(job))) {
result = rs_scoop_read_rest(job, &len, &block);
} else if (result == RS_INPUT_ENDED) {
return RS_DONE;
} else if (result != RS_DONE) {
rs_trace("generate stopped: %s", rs_strerror(result));
return result;
}
rs_trace("got %ld byte block", (long) len);
return rs_sig_do_block(job, block, len);
}
示例6: update_section
/*
* Update the ELF file residing at @p path, replacing all occurrences
* of @p search with @p replace in the section named @p desired_section_name.
* The replacement string must be the same length or shorter than
* the search string.
*/
static void update_section(const char *path,
const void *base,
off_t size,
const char *desired_section_name,
const char *search,
const char *replace) {
const void *desired_section = NULL;
int desired_section_size = 0;
if (FindElfSection(base, size, desired_section_name,
&desired_section, &desired_section_size)
&& desired_section_size > 0) {
/* The local variable below works around a bug in some versions
* of gcc (4.2.1?), which issues an erroneous warning if
* 'desired_section_rw' is replaced with '(void *) desired_section'
* in the call below, causing compile errors with -Werror.
*/
void *desired_section_rw = (void *) desired_section;
int count = replace_string(desired_section_rw, desired_section_size,
search, replace);
if (count == 0) {
rs_trace("\"%s\" section of file %s has no occurrences of \"%s\"",
desired_section_name, path, search);
} else {
rs_log_info("updated \"%s\" section of file \"%s\": "
"replaced %d occurrences of \"%s\" with \"%s\"",
desired_section_name, path, count, search, replace);
if (count > 1) {
rs_log_warning("only expected to replace one occurrence!");
}
}
} else {
rs_trace("file %s has no \"%s\" section", path, desired_section_name);
}
}
示例7: dcc_set_output
/**
* Change object file or suffix of -o to @p ofname
* Frees the old value, if it exists.
*
* It's crucially important that in every case where an output file is
* detected by dcc_scan_args(), it's also correctly identified here.
* It might be better to make the code shared.
**/
int dcc_set_output(char **a, char *ofname)
{
int i;
for (i = 0; a[i]; i++)
if (0 == strcmp(a[i], "-o") && a[i+1] != NULL) {
rs_trace("changed output from \"%s\" to \"%s\"", a[i+1], ofname);
free(a[i+1]);
a[i+1] = strdup(ofname);
if (a[i+1] == NULL) {
rs_log_crit("failed to allocate space for output parameter");
return EXIT_OUT_OF_MEMORY;
}
dcc_trace_argv("command after", a);
return 0;
} else if (0 == strncmp(a[i], "-o", 2)) {
char *newptr;
rs_trace("changed output from \"%s\" to \"%s\"", a[i]+2, ofname);
free(a[i]);
if (asprintf(&newptr, "-o%s", ofname) == -1) {
rs_log_crit("failed to allocate space for output parameter");
return EXIT_OUT_OF_MEMORY;
}
a[i] = newptr;
dcc_trace_argv("command after", a);
return 0;
}
rs_log_error("failed to find \"-o\"");
return EXIT_DISTCC_FAILED;
}
示例8: dcc_trim_path
/**
* Search through the $PATH looking for a directory containing a file called
* @p compiler_name, which is a symbolic link containing the string "distcc".
*
* Trim the path to just after the *last* such directory.
*
* If we find a distcc masquerade dir on the PATH, remove all the dirs up
* to that point.
**/
int dcc_trim_path(const char *compiler_name)
{
const char *envpath, *newpath, *p, *n;
char linkbuf[MAXPATHLEN], *buf;
struct stat sb;
size_t len;
if (!(envpath = getenv("PATH"))) {
rs_trace("PATH seems not to be defined");
return 0;
}
rs_trace("original PATH %s", envpath);
rs_trace("looking for \"%s\"", compiler_name);
/* Allocate a buffer that will let us append "/cc" onto any PATH
* element, even if there is only one item in the PATH. */
if (!(buf = malloc(strlen(envpath)+1+strlen(compiler_name)+1))) {
rs_log_error("failed to allocate buffer for PATH munging");
return EXIT_OUT_OF_MEMORY;
}
for (n = p = envpath, newpath = NULL; *n; p = n) {
n = strchr(p, ':');
if (n)
len = n++ - p;
else {
len = strlen(p);
n = p + len;
}
strncpy(buf, p, len);
sprintf(buf + len, "/%s", compiler_name);
if (lstat(buf, &sb) == -1)
continue; /* ENOENT, EACCESS, etc */
if (!S_ISLNK(sb.st_mode))
break;
if ((len = readlink(buf, linkbuf, sizeof linkbuf)) <= 0)
continue;
linkbuf[len] = '\0';
if (strstr(linkbuf, "distcc")) {
/* Set newpath to the part of the PATH past our match. */
newpath = n;
}
}
if (newpath) {
int ret = dcc_set_path(newpath);
if (ret)
return ret;
} else
rs_trace("not modifying PATH");
free(buf);
return 0;
}
示例9: rs_infilebuf_fill
/*
* If the stream has no more data available, read some from F into
* BUF, and let the stream use that. On return, SEEN_EOF is true if
* the end of file has passed into the stream.
*/
rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
void *opaque)
{
int len;
rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
FILE *f = fb->f;
/* This is only allowed if either the buf has no input buffer
* yet, or that buffer could possibly be BUF. */
if (buf->next_in != NULL) {
assert(buf->avail_in <= fb->buf_len);
assert(buf->next_in >= fb->buf);
assert(buf->next_in <= fb->buf + fb->buf_len);
} else {
assert(buf->avail_in == 0);
}
if (buf->eof_in || (buf->eof_in = feof(f))) {
rs_trace("seen end of file on input");
buf->eof_in = 1;
return RS_DONE;
}
if (buf->avail_in)
/* Still some data remaining. Perhaps we should read
anyhow? */
return RS_DONE;
len = fread(fb->buf, 1, fb->buf_len, f);
if (len <= 0) {
/* This will happen if file size is a multiple of input block len
*/
if (feof(f)) {
rs_trace("seen end of file on input");
buf->eof_in = 1;
return RS_DONE;
}
if (ferror(f)) {
rs_error("error filling buf from file: %s",
strerror(errno));
return RS_IO_ERROR;
} else {
rs_error("no error bit, but got %d return when trying to read",
len);
return RS_IO_ERROR;
}
}
buf->avail_in = len;
buf->next_in = fb->buf;
return RS_DONE;
}
示例10: dcc_check_compiler_masq
/**
* Find the absolute path for the first occurrence of @p compiler_name on the
* PATH. Print a warning if it looks like a symlink to distcc.
*
* We want to guard against somebody accidentally running the server with a
* masqueraded compiler on its $PATH. The worst that's likely to happen here
* is wasting some time running a distcc or ccache client that does nothing,
* so it's not a big deal. (This could be easy to do if it's on the default
* PATH and they start the daemon from the command line.)
*
* At the moment we don't look for the compiler too.
**/
static int dcc_check_compiler_masq(char *compiler_name)
{
const char *envpath, *p, *n;
char *buf = NULL;
struct stat sb;
int len;
char linkbuf[MAXPATHLEN];
if (compiler_name[0] == '/')
return 0;
if (!(envpath = getenv("PATH"))) {
rs_trace("PATH seems not to be defined");
return 0;
}
for (n = p = envpath; *n; p = n) {
n = strchr(p, ':');
if (n)
len = n++ - p;
else {
len = strlen(p);
n = p + len;
}
if (asprintf(&buf, "%.*s/%s", len, p, compiler_name) == -1) {
rs_log_crit("asnprintf failed");
return EXIT_DISTCC_FAILED;
}
if (lstat(buf, &sb) == -1)
continue; /* ENOENT, EACCESS, etc */
if (!S_ISLNK(sb.st_mode)) {
rs_trace("%s is not a symlink", buf);
break; /* found it */
}
if ((len = readlink(buf, linkbuf, sizeof linkbuf)) <= 0)
continue;
linkbuf[len] = '\0';
if (strstr(linkbuf, "distcc")) {
rs_log_warning("%s on distccd's path is %s and really a link to %s",
compiler_name, buf, linkbuf);
break; /* but use it anyhow */
} else {
rs_trace("%s is a safe symlink to %s", buf, linkbuf);
break; /* found it */
}
}
free(buf);
return 0;
}
示例11: dcc_pump_sendfile
/*
* Transmit the body of a file using sendfile().
*
* Linux at the moment requires the input be page-based -- ie a disk file, and
* only on particular filesystems. If the sendfile() call fails in a way that
* makes us think that regular IO might work, then we try that instead. For
* example, the /tmp filesystem may not support sendfile().
*/
int
dcc_pump_sendfile(int ofd, int ifd, size_t size)
{
ssize_t sent;
off_t offset = 0;
int ret;
while (size) {
/* Handle possibility of partial transmission, e.g. if
* sendfile() is interrupted by a signal. size is decremented
* as we go. */
sent = sys_sendfile(ofd, ifd, &offset, size);
if (sent == -1) {
if ((errno == ENOSYS || errno == EINVAL) && offset == 0) {
/* The offset==0 tests is because we may be part way through
* the file. We can't just naively go back to read/write
* because sendfile() does not update the file pointer: we
* would need to lseek() first. That case is not handled at
* the moment because it's unlikely that sendfile() would
* suddenly be unsupported while we're using it. A failure
* halfway through probably indicates a genuine error.*/
rs_log_info("decided to use read/write rather than sendfile");
return dcc_pump_readwrite(ofd, ifd, size);
} else if (errno == EAGAIN) {
/* Sleep until we're able to write out more data. */
if ((ret = dcc_select_for_write(ofd, dcc_io_timeout)) != 0)
return ret;
rs_trace("select() returned, continuing to write");
} else if (errno == EINTR) {
rs_trace("sendfile() interrupted, continuing");
} else {
rs_log_error("sendfile failed: %s", strerror(errno));
return EXIT_IO_ERROR;
}
} else if (sent == 0) {
rs_log_error("sendfile returned 0? can't cope");
return EXIT_IO_ERROR;
} else if (sent != (ssize_t) size) {
/* offset is automatically updated by sendfile. */
size -= sent;
rs_log_notice("sendfile: partial transmission of %ld bytes; retrying %ld @%ld",
(long) sent, (long) size, (long) offset);
} else {
/* normal case, everything was sent. */
break;
}
}
return 0;
}
示例12: dcc_mon_do_file
/**
* Read in @p filename from inside @p dirname, and try to parse it as
* a status file.
*
* If a new entry is read, a pointer to it is returned in @p lp.
**/
static int dcc_mon_do_file(char *dirname, char *filename,
struct dcc_task_state **lp)
{
int fd;
char *fullpath;
int ret;
*lp = NULL;
/* Is this a file we want to see */
if (!str_startswith(dcc_state_prefix, filename)) {
/* rs_trace("skipped"); */
return 0;
}
checked_asprintf(&fullpath, "%s/%s", dirname, filename);
if (fullpath == NULL) {
return EXIT_OUT_OF_MEMORY;
}
rs_trace("process %s", fullpath);
/* Remember that the file might disappear at any time, so open it
* now so that we can hang on. */
if ((fd = open(fullpath, O_RDONLY|O_BINARY, 0)) == -1) {
if (errno == ENOENT) {
rs_trace("%s disappeared", fullpath);
ret = 0;
goto out_free;
} else { /* hm */
rs_log_warning("failed to open %s: %s",
fullpath, strerror(errno));
ret = EXIT_IO_ERROR;
goto out_free;
}
}
if ((ret = dcc_mon_kill_old(fd, fullpath))) {
/* closes fd on failure */
goto out_free;
}
ret = dcc_mon_load_state(fd, fullpath, lp);
dcc_close(fd);
out_free:
free(fullpath);
return ret; /* ok */
}
示例13: rs_patch_s_copying
/**
* Called when we're executing a COPY command and waiting for all the
* data to be retrieved from the callback.
*/
static rs_result rs_patch_s_copying(rs_job_t *job)
{
rs_result result;
size_t desired_len, len;
void *ptr;
rs_buffers_t *buffs = job->stream;
/* copy only as much as will fit in the output buffer, so that we
* don't have to block or store the input. */
desired_len = len = (buffs->avail_out < job->basis_len) ? buffs->avail_out : job->basis_len;
if (!len)
return RS_BLOCKED;
rs_trace("copy " PRINTF_FORMAT_U64 " bytes from basis at offset " PRINTF_FORMAT_U64 "",
PRINTF_CAST_U64(len), PRINTF_CAST_U64(job->basis_pos));
ptr = buffs->next_out;
result = (job->copy_cb)(job->copy_arg, job->basis_pos, &len, &ptr);
if (result != RS_DONE)
return result;
else
rs_trace("copy callback returned %s", rs_strerror(result));
rs_trace("got " PRINTF_FORMAT_U64 " bytes back from basis callback", PRINTF_CAST_U64(len));
if (len > desired_len) {
rs_trace("warning: copy_cb returned more than the requested length.");
len = desired_len;
}
/* copy back to out buffer only if the callback has used its own buffer */
if (ptr != buffs->next_out)
memcpy(buffs->next_out, ptr, len);
buffs->next_out += len;
buffs->avail_out -= len;
job->basis_pos += len;
job->basis_len -= len;
if (!job->basis_len) {
/* Done! */
job->statefn = rs_patch_s_cmdbyte;
}
return RS_RUNNING;
}
示例14: dcc_recursion_safeguard
int dcc_recursion_safeguard(void)
{
char *env = getenv(dcc_safeguard_name);
if (env) {
rs_trace("safeguard: %s", env);
if (!(dcc_safeguard_level = atoi(env)))
dcc_safeguard_level = 1;
}
else
dcc_safeguard_level = 0;
rs_trace("safeguard level=%d", dcc_safeguard_level);
return dcc_safeguard_level;
}
示例15: dcc_connect_by_name
/**
* Open a socket to a tcp remote host with the specified port.
**/
int dcc_connect_by_name(const char *host, int port, int *p_fd)
{
struct addrinfo hints;
struct addrinfo *res;
int error;
int ret;
char portname[20];
rs_trace("connecting to %s port %d", host, port);
/* Unfortunately for us, getaddrinfo wants the port (service) as a string */
snprintf(portname, sizeof portname, "%d", port);
memset(&hints, 0, sizeof(hints));
/* set-up hints structure */
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(host, portname, &hints, &res);
if (error) {
rs_log_error("failed to resolve host %s port %d: %s", host, port,
gai_strerror(error));
return EXIT_CONNECT_FAILED;
}
/* Try each of the hosts possible addresses. */
do {
ret = dcc_connect_by_addr(res->ai_addr, res->ai_addrlen, p_fd);
} while (ret != 0 && (res = res->ai_next));
return ret;
}