Пример #1
0
Файл: ar.c Проект: pexip/os-dpkg
void
dpkg_ar_member_put_mem(const char *ar_name, int ar_fd,
                       const char *name, const void *data, size_t size)
{
    dpkg_ar_member_put_header(ar_name, ar_fd, name, size);

    /* Copy data contents. */
    if (fd_write(ar_fd, data, size) < 0)
        ohshite(_("unable to write file '%s'"), ar_name);

    if (size & 1)
        if (fd_write(ar_fd, "\n", 1) < 0)
            ohshite(_("unable to write file '%s'"), ar_name);
}
Пример #2
0
static void
file_treewalk_feed(const char *dir, int fd_out)
{
  int pipefd[2];
  pid_t pid;
  struct file_info *fi;
  struct file_info *symlist = NULL;
  struct file_info *symlist_end = NULL;

  m_pipe(pipefd);

  pid = subproc_fork();
  if (pid == 0) {
    m_dup2(pipefd[1], 1);
    close(pipefd[0]);
    close(pipefd[1]);

    if (chdir(dir))
      ohshite(_("failed to chdir to `%.255s'"), dir);

    execlp(FIND, "find", ".", "-path", "./" BUILDCONTROLDIR, "-prune", "-o",
           "-print0", NULL);
    ohshite(_("unable to execute %s (%s)"), "find", FIND);
  }
  close(pipefd[1]);

  /* We need to reorder the files so we can make sure that symlinks
   * will not appear before their target. */
  while ((fi = file_info_get(dir, pipefd[0])) != NULL) {
    if (S_ISLNK(fi->st.st_mode)) {
      file_info_list_append(&symlist, &symlist_end, fi);
    } else {
      if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
        ohshite(_("failed to write filename to tar pipe (%s)"),
                _("data member"));
      file_info_free(fi);
    }
  }

  close(pipefd[0]);
  subproc_wait_check(pid, "find", 0);

  for (fi = symlist; fi; fi = fi->next)
    if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
      ohshite(_("failed to write filename to tar pipe (%s)"), _("data member"));

  file_info_list_free(symlist);
}
Пример #3
0
static int on_socket_readable(void *socket, int *stdin_fd, zmq_msg_t *stdin_msg, size_t *stdin_msg_pos)
{
	while (1) {
		if (*stdin_msg_pos)
			return 0;
		if (zmq_msg_init(stdin_msg) == -1) {
			TRACE("zmq_msg_init() failed");
			return -1;
		}
		if (zmq_msg_recv(stdin_msg, socket, ZMQ_DONTWAIT) == -1) {
			if (errno == EAGAIN)
				return 0;
			TRACE_ERRNO("zmq_msg_recv() failed");
			return -1;
		}
		size_t msg_size = zmq_msg_size(stdin_msg);
		if (msg_size == 0) {
			TRACE("empty message received");
			return -1;
		}
		char *msg_data = zmq_msg_data(stdin_msg);
		TRACE("received message, type=%i, size=%zu", get_msg_type(stdin_msg), msg_size);
		if (msg_data[0] == msg_type_stdin) {
			*stdin_msg_pos = 1;
			if (fd_write(stdin_fd, stdin_msg, stdin_msg_pos) == -1)
				return -1;
		} else {
			TRACE("message with unexpected type received");
			return -1;
		}	
	}
}
Пример #4
0
void
statusfd_send(const char *fmt, ...)
{
	static struct varbuf vb;
	struct pipef *pipef;
	va_list args;

	if (!status_pipes)
		return;

	va_start(args, fmt);
	varbuf_reset(&vb);
	varbuf_vprintf(&vb, fmt, args);
	/* Sanitize string to not include new lines, as front-ends should be
	 * doing their own word-wrapping. */
	varbuf_map_char(&vb, '\n', ' ');
	varbuf_add_char(&vb, '\n');
	va_end(args);

	for (pipef = status_pipes; pipef; pipef = pipef->next) {
		if (fd_write(pipef->fd, vb.buf, vb.used) < 0)
			ohshite(_("unable to write to status fd %d"),
			        pipef->fd);
	}
}
Пример #5
0
static void
decompress_bzip2(int fd_in, int fd_out, const char *desc)
{
	char buffer[DPKG_BUFFER_SIZE];
	BZFILE *bzfile = BZ2_bzdopen(fd_in, "r");

	if (bzfile == NULL)
		ohshit(_("%s: error binding input to bzip2 stream"), desc);

	for (;;) {
		int actualread, actualwrite;

		actualread = BZ2_bzread(bzfile, buffer, sizeof(buffer));
		if (actualread < 0) {
			int bz_errnum = 0;
			const char *errmsg = BZ2_bzerror(bzfile, &bz_errnum);

			if (bz_errnum == BZ_IO_ERROR)
				errmsg = strerror(errno);
			ohshit(_("%s: internal bzip2 read error: '%s'"), desc,
			       errmsg);
		}
		if (actualread == 0) /* EOF. */
			break;

		actualwrite = fd_write(fd_out, buffer, actualread);
		if (actualwrite != actualread)
			ohshite(_("%s: internal bzip2 write error"), desc);
	}

	if (close(fd_out))
		ohshite(_("%s: internal bzip2 write error"), desc);
}
Пример #6
0
static size_t writev(int fd, struct iovec *iov, int n)
{
  if (n) {
    return fd_write(fd, iov->iov_base, iov->iov_len);
  }
  return 0;
}
Пример #7
0
static void
decompress_gzip(int fd_in, int fd_out, const char *desc)
{
	char buffer[DPKG_BUFFER_SIZE];
	gzFile gzfile = gzdopen(fd_in, "r");

	if (gzfile == NULL)
		ohshit(_("%s: error binding input to gzip stream"), desc);

	for (;;) {
		int actualread, actualwrite;

		actualread = gzread(gzfile, buffer, sizeof(buffer));
		if (actualread < 0) {
			int z_errnum = 0;
			const char *errmsg = gzerror(gzfile, &z_errnum);

			if (z_errnum == Z_ERRNO)
				errmsg = strerror(errno);
			ohshit(_("%s: internal gzip read error: '%s'"), desc,
			       errmsg);
		}
		if (actualread == 0) /* EOF. */
			break;

		actualwrite = fd_write(fd_out, buffer, actualread);
		if (actualwrite != actualread)
			ohshite(_("%s: internal gzip write error"), desc);
	}

	if (close(fd_out))
		ohshite(_("%s: internal gzip write error"), desc);
}
Пример #8
0
/**
 * @param b: a fobuf structure to use
 * @param buf: pointer to the data you want to write
 * @param len: size of data pointed to by buf
 *
 * Slow path for writing to the buffer, do not call directly instead
 * use fobuf_write().
 *
 * Return value: zero on error, non-zero on success.
 */
static int fobuf_write_slow(struct _fobuf *b, const void *buf, size_t len)
{
	/* fill up the buffer before flushing, we already know
	 * that len >= b->buf_len so a full buffer flush is
	 * inevitable.
	 */
	memcpy(b->ptr, buf, b->buf_len);
	buf += b->buf_len;
	len -= b->buf_len;
	b->ptr += b->buf_len;
	b->buf_len = 0;
	if ( !_fobuf_flush(b) )
		return 0;

	/* If the remaining data is the same size as the buffer then
	 * buffering is doing an un-necessary copy of the data.
	 *
	 * If the remaining data is bigger than the buffer then we
	 * must write it out right away anyway.
	 */
	if ( len >= b->buf_sz )
		return fd_write(b->fd, buf, len);

	/* normal write - len may be zero */
	memcpy(b->ptr, buf, len);
	b->ptr += len;
	b->buf_len -= len;

	return 1;
}
Пример #9
0
A_INT32 SocketWrite
(
	struct _Socket           *pSockInfo,
	A_UINT8                *buf,
	A_INT32                len
	)
{
	A_UINT32		res, iIndex;

	q_uiPrintf("SocketWrite:%d\n", len);
   

	res = fd_write(pSockInfo->sockfd, pSockInfo->port_num, (A_UINT8 *) buf, len);

    q_uiPrintf("Sent %d bytes of %d bytes\n", res, len);
    for(iIndex=0; iIndex<len; iIndex++) {
            q_uiPrintf("%x ", buf[iIndex]);
            if (!(iIndex % 32)) q_uiPrintf("\n");
    }

	if (res != len) {
		return 0;
	}
	else {
		return len;
	}
}
Пример #10
0
int main (int argc, char const *const *argv, char const *const *envp)
{
  unsigned int len ;
  int fd;
  PROG = "cgjoin" ;
  if (argc < 3) strerr_dieusage(100, USAGE) ;
  len = strlen(argv[1]) ;
  {
    char path[len + PREFIXLEN + SUFFIXLEN + 1] ;
    char pid[UINT_FMT + 1] ;
    unsigned int k ;
    // format this program's PID as a string
    k = uint_fmt(pid, getpid()) ;
    pid[k++] = 0 ;
    // Build up the path to the cgrup filesystem
    memcpy(path, PREFIX, PREFIXLEN);
    memcpy(path + PREFIXLEN, argv[1], len);
    memcpy(path + PREFIXLEN + len, SUFFIX, SUFFIXLEN);
    path[PREFIXLEN + len + SUFFIXLEN] = 0 ;
    doparents(path);
    // Write the pid to the cgroup's tasks file
    if ((fd = open_write(path)) < 0) strerr_dief2x(100, "cannot open cgroup tasks file: ", path) ;
    fd_write(fd, pid, k) ;
    close(fd) ;
  }
  pathexec_run(argv[2], argv+2, envp) ;
  strerr_dieexec(111, argv[2]) ;
}
Пример #11
0
/* Allocate a new buffer and put it at the end of the chain of buffers
 * scheduled for output. Return 1 if we have more bytes in buffers
 * than allowed afterwards.
 */
static INLINE int append_buffer(struct pike_string *s)
   /* 1=buffer full */
{
   struct buffer *b;

   debug_malloc_touch(s);

   if(THIS->fd!= -1)
   {
     fd_lseek(THIS->fd, THIS->pos, SEEK_SET);
     fd_write(THIS->fd, s->str, s->len);
     THIS->pos+=s->len;
     return 0;
   }
   else
   {
     nbuffers++;
     b=ALLOC_STRUCT(buffer);
     b->next=NULL;
     b->s=s;
     sbuffers += s->len;
     add_ref(s);

     if (THIS->lastbuffer)
       THIS->lastbuffer->next=b;
     else
       THIS->firstbuffer=b;

     THIS->lastbuffer=b;

     THIS->bytes_in_buffer+=s->len;
   }
   return THIS->bytes_in_buffer > MAX_BYTES_IN_BUFFER;
}
Пример #12
0
static int
file_write_internal(const char *file, const char *buf, ssize_t len, int oflags)
{
	int fd;

	IF_NULL_RETVAL(file, -1);
	IF_NULL_RETVAL(buf, -1);

	fd = open(file, oflags, 00666);
	if (fd < 0) {
		DEBUG("Could not open output file %s", file);
		return -1;
	}

	if (len < 0)
		len = strlen(buf);

	int bytes_written = fd_write(fd, buf, len);
	if (bytes_written < 0) {
		DEBUG("Could not write to output file %s", file);
		close(fd);
		return -1;
	}

	close(fd);
	return bytes_written;
}
Пример #13
0
static void trystart (void)
{
  int p[2] ;
  pid_t pid ;
  if (pipecoe(p) < 0)
  {
    settimeout(60) ;
    strerr_warnwu1sys("pipecoe (waiting 60 seconds)") ;
    return ;
  }
  pid = fork() ;
  if (pid < 0)
  {
    settimeout(60) ;
    strerr_warnwu1sys("fork (waiting 60 seconds)") ;
    fd_close(p[1]) ; fd_close(p[0]) ;
    return ;
  }
  else if (!pid)
  {
    char const *cargv[2] = { "run", 0 } ;
    PROG = "s6-supervise (child)" ;
    selfpipe_finish() ;
    fd_close(p[0]) ;
    if (unlink(S6_SUPERVISE_READY_FILENAME) < 0 && errno != ENOENT)
      strerr_warnwu1sys("unlink " S6_SUPERVISE_READY_FILENAME) ;
    if (flagsetsid) setsid() ;
    execve("./run", (char *const *)cargv, (char *const *)environ) ;
    fd_write(p[1], "", 1) ;
    strerr_dieexec(127, "run") ;
  }
  fd_close(p[1]) ;
  {
    char c ;
    switch (fd_read(p[0], &c, 1))
    {
      case -1 :
        fd_close(p[0]) ;
        settimeout(60) ;
        strerr_warnwu1sys("read pipe (waiting 60 seconds)") ;
        kill(pid, SIGKILL) ;
        return ;
      case 1 :
      {
        fd_close(p[0]) ;
        settimeout(10) ;
        strerr_warnwu1x("spawn ./run - waiting 10 seconds") ;
        return ;
      }
    }
  }
  fd_close(p[0]) ;
  settimeout_infinite() ;
  state = UP ;
  status.pid = pid ;
  tain_copynow(&status.stamp) ;
  announce() ;
  ftrigw_notifyb_nosig(S6_SUPERVISE_EVENTDIR, "u", 1) ;
}
Пример #14
0
long int sock_write(net_sock_t *nsock, const void *buf, size_t count, Net_timeout_t tm)
{
  network_sock_t *sock = (network_sock_t *)nsock;   

  if (sock == NULL) return(-1);   //** If closed return

  return(fd_write(sock->fd, buf, count, tm));
}
Пример #15
0
static int fd_puts(BIO *bp, const char *str)
{
    int n, ret;

    n = strlen(str);
    ret = fd_write(bp, str, n);
    return (ret);
}
Пример #16
0
pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to)
{
  int e ;
  int syncp[2] ;
  pid_t pid ;
  if (coe(p[0]) < 0 || pipecoe(syncp) < 0)
  {
    e = errno ;
    fd_close(p[1]) ;
    fd_close(p[0]) ;
    errno = e ;
    return 0 ;
  }
  pid = fork() ;
  if (pid < 0)
  {
    e = errno ;
    fd_close(syncp[1]) ;
    fd_close(syncp[0]) ;
    fd_close(p[1]) ;
    fd_close(p[0]) ;
    errno = e ;
    return 0 ;
  }
  if (!pid)
  {
    fd_close(syncp[0]) ;
    fd_close(p[!(to & 1)]) ;
    if (fd_move(to & 1, p[to & 1]) < 0) goto err ;
    if ((to & 2) && (fd_copy(!(to & 1), to & 1) < 0)) goto err ;
    sig_blocknone() ;
    pathexec_run(prog, argv, envp) ;
err:
    e = errno ;
    fd_write(syncp[1], (char *)&e, sizeof(e)) ;
    _exit(127) ;
  }
  fd_close(syncp[1]) ;
  fd_close(p[to & 1]) ;
  syncp[1] = fd_read(syncp[0], (char *)&e, sizeof(e)) ;
  if (syncp[1] < 0)
  {
    e = errno ;
    fd_close(syncp[0]) ;
    fd_close(p[!(to & 1)]) ;
    errno = e ;
    return 0 ;
  }
  fd_close(syncp[0]) ;
  if (syncp[1] == sizeof(e))
  {
    fd_close(p[!(to & 1)]) ;
    wait_pid(pid, &syncp[1]) ;
    errno = e ;
    return 0 ;
  }
  return pid ;
}
Пример #17
0
gint sock_write(SockInfo *sock, const gchar *buf, gint len)
{
	g_return_val_if_fail(sock != NULL, -1);

#if USE_SSL
	if (sock->ssl)
		return ssl_write(sock->ssl, buf, len);
#endif
	return fd_write(sock->sock, buf, len);
}
Пример #18
0
static void
file_treewalk_feed(const char *dir, int fd_out)
{
  struct treeroot *tree;
  struct treenode *node;
  struct file_info *fi;
  struct file_info *symlist = NULL;
  struct file_info *symlist_end = NULL;

  tree = treewalk_open(dir, TREEWALK_NONE, NULL);
  for (node = treewalk_node(tree); node ; node = treewalk_next(tree)) {
    const char *virtname = treenode_get_virtname(node);
    char *nodename;

    if (strncmp(virtname, BUILDCONTROLDIR, strlen(BUILDCONTROLDIR)) == 0)
      continue;

    nodename = str_fmt("./%s", virtname);

    if (strchr(nodename, '\n'))
      ohshit(_("newline not allowed in pathname '%s'"), nodename);

    /* We need to reorder the files so we can make sure that symlinks
     * will not appear before their target. */
    if (S_ISLNK(treenode_get_mode(node))) {
      fi = file_info_new(nodename);
      file_info_list_append(&symlist, &symlist_end, fi);
    } else {
      if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0)
        ohshite(_("failed to write filename to tar pipe (%s)"),
                _("data member"));
    }

    free(nodename);
  }
  treewalk_close(tree);

  for (fi = symlist; fi; fi = fi->next)
    if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
      ohshite(_("failed to write filename to tar pipe (%s)"), _("data member"));

  file_info_list_free(symlist);
}
Пример #19
0
/* リングバッファ構造体に buf の内容を加える */
static errr insert_ringbuf(char *buf)
{
	int len;
	len = strlen(buf) + 1; /* +1は終端文字分 */

	if (movie_mode)
	{
		fd_write(movie_fd, buf, len);
#ifdef CHUUKEI
		if (!chuukei_server) return 0;
#else
		return 0;
#endif
	}

	/* バッファをオーバー */
	if (ring.inlen + len >= RINGBUF_SIZE)
	{
#ifdef CHUUKEI
		if (chuukei_server) disable_chuukei_server();
		else chuukei_client = FALSE;

		prt("送受信バッファが溢れました。サーバとの接続を切断します。", 0, 0);
		inkey();

		close(sd);
#endif
		return (-1);
	}

	/* バッファの終端までに収まる */
	if (ring.wptr + len < RINGBUF_SIZE)
	{
		memcpy(ring.buf + ring.wptr, buf, len);
		ring.wptr += len;
	}
	/* バッファの終端までに収まらない(ピッタリ収まる場合も含む) */
	else
	{
		int head = RINGBUF_SIZE - ring.wptr;  /* 前半 */
		int tail = len - head;               /* 後半 */

		memcpy(ring.buf + ring.wptr, buf, head);
		memcpy(ring.buf, buf + head, tail);
		ring.wptr = tail;
	}

	ring.inlen += len;

	/* Success */
	return (0);
}
Пример #20
0
static int fd_puts(BIO *bp, const char *str)
#endif
	{
	int n,ret;

	n=strlen(str);
#ifndef BIO_FD
	ret=sock_write(bp,str,n);
#else
	ret=fd_write(bp,str,n);
#endif
	return(ret);
	}
Пример #21
0
static int
php_phttpd_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
    int sent_bytes;

	sent_bytes = fd_write(PHG(cip)->fd, str, str_length);

	if (sent_bytes == -1) {
		php_handle_aborted_connection();
	}

    return sent_bytes;
}
Пример #22
0
Файл: ar.c Проект: pexip/os-dpkg
void
dpkg_ar_member_put_header(const char *ar_name, int ar_fd,
                          const char *name, off_t size)
{
    char header[sizeof(struct ar_hdr) + 1];
    int n;

    n = sprintf(header, "%-16s%-12lu0     0     100644  %-10jd`\n",
                name, time(NULL), (intmax_t)size);
    if (n != sizeof(struct ar_hdr))
        ohshit(_("generated corrupt ar header for '%s'"), ar_name);

    if (fd_write(ar_fd, header, n) < 0)
        ohshite(_("unable to write file '%s'"), ar_name);
}
Пример #23
0
gint fd_write_all(gint fd, const gchar *buf, gint len)
{
	gint n, wrlen = 0;

	while (len) {
		n = fd_write(fd, buf, len);
		if (n <= 0)
			return -1;
		len -= n;
		wrlen += n;
		buf += n;
	}

	return wrlen;
}
Пример #24
0
Файл: save.c Проект: fph/mortsil
/*
 * Hack -- write the current "block" to the savefile
 */
static errr wr_block(void)
{
	errr err;

	byte fake[4];

	/* Save the type and size */
	fake[0] = (byte)(data_type);
	fake[1] = (byte)(data_type >> 8);
	fake[2] = (byte)(data_size);
	fake[3] = (byte)(data_size >> 8);

	/* Dump the head */
	err = fd_write(data_fd, (cptr)&fake, sizeof(fake));

	/* Dump the actual data */
	err = fd_write(data_fd, (cptr)data_head, data_size);

	/* XXX XXX XXX */
	fake[0] = 0;
	fake[1] = 0;
	fake[2] = 0;
	fake[3] = 0;

	/* Dump the tail */
	err = fd_write(data_fd, (cptr)&fake, sizeof(fake));

	/* Hack -- reset */
	data_next = data_head;

	/* Wipe the data block */
	C_WIPE(data_head, 65535, byte);

	/* Success */
	return (0);
}
Пример #25
0
int s6_svc_write (char const *fifo, char const *data, unsigned int datalen)
{
  int fd = open_write(fifo) ;
  if (fd < 0) return (errno == ENXIO) ? 0 : -1 ;
  else if (ndelay_off(fd) == -1) return -1 ;
  else if (fd_write(fd, data, datalen) == -1)
  {
    register int e = errno ;
    fd_close(fd) ;
    errno = e ;
    return -1 ;
  }
  fd_close(fd) ;
  return 1 ;
}
Пример #26
0
void 
write_log (int whichlog, char *fmt, ...)
{
	char buf[BUFSIZE];
	va_list ap;
	char *logtime;
	mythread_t *mt = thread_check_created ();
	int fd = get_log_fd (whichlog);


		va_start(ap, fmt);
		vsnprintf(buf, BUFSIZE, fmt, ap);
  
		if (!mt)
			fprintf (stderr, "WARNING: No mt while outputting [%s]", buf);

		logtime = get_log_time();

		if (strstr (buf, "%s") != NULL) {
			fprintf (stderr, "WARNING, write_log () called with '%%s' formatted string [%s]!", buf);
			free (logtime);
			return;
		}

		if (mt && fd != -1) {
			if ((whichlog != ANDROID_LOG_VERBOSE) || (info.logfiledebuglevel > -1)) {
				fd_write (fd, "[%s] [%d:%s] %s\n", logtime, mt->id, nullcheck_string (mt->name), buf);
			}
		}

		if (whichlog != ANDROID_LOG_VERBOSE)
		{
			free (logtime);
			va_end (ap);
			return;
		}

		if (running == SERVER_RUNNING) {
			printf("\r[%s] %s\n", logtime, buf);
			fflush(stdout);
		} else
			fprintf (stderr, "[%s] %s\n", logtime, buf);

		if (logtime)
			free(logtime);
		va_end (ap);
	
}
Пример #27
0
gint sock_write(SockInfo *sock, const gchar *buf, gint len)
{
	gint ret;

	cm_return_val_if_fail(sock != NULL, -1);

#ifdef USE_GNUTLS
	if (sock->ssl)
		ret = ssl_write(sock->ssl, buf, len);
	else
#endif
		ret = fd_write(sock->sock, buf, len);

	if (ret < 0)
		sock->state = CONN_DISCONNECTED;
	return ret;
}
Пример #28
0
static void
filter_lzma(struct io_lzma *io, int fd_in, int fd_out)
{
	uint8_t buf_in[DPKG_BUFFER_SIZE];
	uint8_t buf_out[DPKG_BUFFER_SIZE];
	lzma_stream s = LZMA_STREAM_INIT;
	lzma_ret ret;

	s.next_out = buf_out;
	s.avail_out = sizeof(buf_out);

	io->action = LZMA_RUN;
	io->status = DPKG_STREAM_INIT;
	io->init(io, &s);
	io->status = (io->status & DPKG_STREAM_FILTER) | DPKG_STREAM_RUN;

	do {
		ssize_t len;

		if (s.avail_in == 0 && io->action != LZMA_FINISH) {
			len = fd_read(fd_in, buf_in, sizeof(buf_in));
			if (len < 0)
				ohshite(_("%s: lzma read error"), io->desc);
			if (len == 0)
				io->action = LZMA_FINISH;
			s.next_in = buf_in;
			s.avail_in = len;
		}

		ret = io->code(io, &s);

		if (s.avail_out == 0 || ret == LZMA_STREAM_END) {
			len = fd_write(fd_out, buf_out, s.next_out - buf_out);
			if (len < 0)
				ohshite(_("%s: lzma write error"), io->desc);
			s.next_out = buf_out;
			s.avail_out = sizeof(buf_out);
		}
	} while (ret != LZMA_STREAM_END);

	io->done(io, &s);

	if (close(fd_out))
		ohshite(_("%s: lzma close error"), io->desc);
}
Пример #29
0
static void
control_treewalk_feed(const char *dir, int fd_out)
{
  struct treeroot *tree;
  struct treenode *node;

  tree = treewalk_open(dir, TREEWALK_NONE, NULL);
  for (node = treewalk_node(tree); node; node = treewalk_next(tree)) {
    char *nodename;

    nodename = str_fmt("./%s", treenode_get_virtname(node));
    if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0)
      ohshite(_("failed to write filename to tar pipe (%s)"),
              _("control member"));
    free(nodename);
  }
  treewalk_close(tree);
}
Пример #30
0
void 
log_no_thread (int whichlog, char *fmt, ...)
{
	char buf[BUFSIZE];
	va_list ap;
	char *logtime;
	int fd = get_log_fd (whichlog);


		va_start(ap, fmt);
		vsnprintf(buf, BUFSIZE, fmt, ap);
  
		logtime = get_log_time();

		if (strstr (buf, "%s") != NULL) {
			fprintf (stderr, "WARNING, write_log () called with '%%s' formatted string [%s]!", buf);
			logtime = get_log_time();
			return;
		}

		if (fd != -1) {
			if ((whichlog != ANDROID_LOG_VERBOSE) || (info.logfiledebuglevel > -1)) {
				fd_write (fd, "[%s] %s\n", logtime, buf);
			}
		}

		if (whichlog != ANDROID_LOG_VERBOSE)
		{
			free (logtime);
			va_end (ap);
			return;
		}

		if (running == SERVER_RUNNING) {
			printf("\r[%s] %s\n", logtime, buf);
			fflush(stdout);
		} else
			fprintf (stderr, "[%s] %s\n", logtime, buf);

		if (logtime)
			free(logtime);
		va_end (ap);

}