void pup_cd_eject_continue(PupDevice *dev, PupOperation *operation)
{
	gint fd = open(PUP_VOLUME(dev)->unix_dev, O_NONBLOCK | O_RDWR);
	if (fd < 0)
	{
		pup_operation_return(operation, FALSE, g_io_error_from_errno(errno),
		                     "Couldn't open %s: %s", PUP_VOLUME(dev)->unix_dev,
		                     g_strerror(errno));
		return;
	}
	if (ioctl(fd, CDROMEJECT, 0) < 0)
	{
		pup_operation_return(operation, FALSE, g_io_error_from_errno(errno),
		                     "Couldn't eject %s: %s", PUP_DEVICE(dev)->sysname,  
		                     g_strerror(errno));
		close(fd);
		return;
	}
	PupVMMonitor *monitor = pup_vm_monitor_get();
	PupCDDrive *drive = PUP_CD_DRIVE(pup_vm_monitor_lookup_drive
	                                 (monitor, dev->sysname, FALSE));
	g_return_if_fail(drive);
	pup_cd_drive_probe_disk_cb(monitor, drive);
	close(fd);

	pup_operation_return(operation, TRUE, 0, " ");
}
示例#2
0
/*
 * Connects to the i3 IPC socket and returns the file descriptor for the
 * socket.
 */
static int get_file_descriptor(const char *socket_path, GError **err) {
  GError *tmp_error = NULL;

  int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);

  if (sockfd == -1) {
    tmp_error = g_error_new(G_IO_ERROR, g_io_error_from_errno(errno), "Could not create socket (%s)\n", strerror(errno));
    g_propagate_error(err, tmp_error);
    return -1;
  }

  (void)fcntl(sockfd, F_SETFD, FD_CLOEXEC);

  struct sockaddr_un addr;
  memset(&addr, 0, sizeof(struct sockaddr_un));
  addr.sun_family = AF_LOCAL;
  strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);

  if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0) {
    tmp_error = g_error_new(G_IO_ERROR, g_io_error_from_errno(errno), "Could not connect to i3 (%s)\n", strerror(errno));
    g_propagate_error(err, tmp_error);
    return -1;
  }

  return sockfd;
}
示例#3
0
static gssize
g_unix_output_stream_write (GOutputStream  *stream,
                            const void     *buffer,
                            gsize           count,
                            GCancellable   *cancellable,
                            GError        **error)
{
    GUnixOutputStream *unix_stream;
    gssize res;
    GPollFD poll_fds[2];
    int poll_ret;

    unix_stream = G_UNIX_OUTPUT_STREAM (stream);

    if (g_cancellable_make_pollfd (cancellable, &poll_fds[1]))
    {
        poll_fds[0].fd = unix_stream->priv->fd;
        poll_fds[0].events = G_IO_OUT;
        do
            poll_ret = g_poll (poll_fds, 2, -1);
        while (poll_ret == -1 && errno == EINTR);
        g_cancellable_release_fd (cancellable);

        if (poll_ret == -1)
        {
            int errsv = errno;

            g_set_error (error, G_IO_ERROR,
                         g_io_error_from_errno (errsv),
                         _("Error writing to unix: %s"),
                         g_strerror (errsv));
            return -1;
        }
    }

    while (1)
    {
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
            return -1;

        res = write (unix_stream->priv->fd, buffer, count);
        if (res == -1)
        {
            int errsv = errno;

            if (errsv == EINTR)
                continue;

            g_set_error (error, G_IO_ERROR,
                         g_io_error_from_errno (errsv),
                         _("Error writing to unix: %s"),
                         g_strerror (errsv));
        }

        break;
    }

    return res;
}
示例#4
0
/**
 * ot_util_ensure_directory_and_fsync:
 * @dir: Path to a directory
 * @cancellable: Cancellable
 * @error: Error
 *
 * Create @dir (and all intermediate parent directories), ensuring
 * that all entries are on disk.
 */
gboolean
ot_util_ensure_directory_and_fsync (GFile         *dir,
                                    GCancellable  *cancellable,
                                    GError       **error)
{
  gboolean ret = FALSE;
  int parentfd = -1;
  const char *basename = gs_file_get_basename_cached (dir);
  g_autoptr(GFile) parent = g_file_get_parent (dir);
  
 again:
  parentfd = open (gs_file_get_path_cached (parent),
                   O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC);
  if (parentfd == -1)
    {
      if (errno == ENOENT)
        {
          if (!ot_util_ensure_directory_and_fsync (parent, cancellable, error))
            goto out;
          goto again;
        }
      else
        {
          int errsv = errno;
          g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                       "opendir: %s", g_strerror (errsv));
          goto out;
        }
    }
  
  if (mkdirat (parentfd, basename, 0777) == -1)
    {
      if (errno == EEXIST)
        {
          ;
        }
      else
        {
          int errsv = errno;
          g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                       "mkdirat: %s", g_strerror (errsv));
          goto out;
        }
    }

  if (fsync (parentfd) == -1)
    {
      int errsv = errno;
      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                   "fsync: %s", g_strerror (errsv));
      goto out;
    }

  ret = TRUE;
 out:
  if (parentfd != -1)
    (void) close (parentfd);
  return ret;
}
示例#5
0
MuxMaildirFile*
mux_maildir_file_new (const char *path, const char *root_maildir,
                      GError **err)
{
    MuxMaildirFlags	 flags;
    MuxMaildirFile	*self;
    struct stat	 statbuf;
    char		*basename;

    g_return_val_if_fail (path, NULL);

    if (G_UNLIKELY(!g_path_is_absolute (path) ||
                   (root_maildir && !g_path_is_absolute (root_maildir)))) {
        g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "path and root-maildir must be absolute");
        return NULL;
    }

    if (G_UNLIKELY(root_maildir && !g_str_has_prefix (path, root_maildir))) {
        g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED,
                     "maildir must be a prefix of path");
        return NULL;
    }

    if (G_UNLIKELY(access (path, R_OK) != 0)) {
        g_set_error (err, G_IO_ERROR, g_io_error_from_errno(errno),
                     "cannot read '%s'", path);
        return NULL;
    }

    if (G_UNLIKELY(stat (path, &statbuf) != 0)) {
        g_set_error (err, G_IO_ERROR, g_io_error_from_errno(errno),
                     "cannot stat'%s'", path);
        return NULL;
    }

    basename  = mux_maildir_path_parse (
                    path, &flags, root_maildir ? TRUE: FALSE, err);
    if (G_UNLIKELY(!basename))
        return NULL;
    g_free (basename);

    self = MUX_MAILDIR_FILE(g_object_new(MUX_TYPE_MAILDIR_FILE, NULL));

    self->priv->path	= g_strdup (path);
    self->priv->flags	= flags;
    self->priv->root	= g_strdup (root_maildir);
    self->priv->tstamp	= (gint64)statbuf.st_mtime;
    self->priv->size	= (gint64)statbuf.st_size;
    self->priv->uid		= mux_maildir_file_uid_for_path (path);

    if (root_maildir)
        self->priv->maildir = determine_maildir (path, root_maildir);

    return self;
}
示例#6
0
/* Create a netlink socket, bind to it and wrap it in a GSocket */
static gboolean
create_netlink_socket (GUPnPLinuxContextManager *self, GError **error)
{
        struct sockaddr_nl sa;
        int fd, status;
        GSocket *sock;
        GError *inner_error;

        inner_error = NULL;

        fd = socket (PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
        if (fd == -1) {
                g_set_error_literal (error,
                                     G_IO_ERROR,
                                     g_io_error_from_errno (errno),
                                     "Failed to bind to netlink socket");
                return FALSE;
        }

        memset (&sa, 0, sizeof (sa));
        sa.nl_family = AF_NETLINK;
        /* Listen for interface changes and IP address changes */
        sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;

        status = bind (fd, (struct sockaddr *) &sa, sizeof (sa));
        if (status == -1) {
                g_set_error_literal (error,
                                     G_IO_ERROR,
                                     g_io_error_from_errno (errno),
                                     "Failed to bind to netlink socket");
                close (fd);

                return FALSE;
        }

        sock = g_socket_new_from_fd (fd, &inner_error);
        if (sock == NULL) {
                close (fd);
                g_propagate_prefixed_error (error,
                                            inner_error,
                                            "Failed to create GSocket from "
                                            "netlink socket");

                return FALSE;
        }

        g_socket_set_blocking (sock, FALSE);

        self->priv->netlink_socket = sock;

        return TRUE;
}
示例#7
0
gboolean
mux_maildir_make (const char* path, mode_t mode, GError **err)
{
    gboolean	rv;
    guint		u;
    const gchar* subdirs[] = {"new", "cur", "tmp"};

    g_return_val_if_fail (path, FALSE);

    for (u = 0, rv = TRUE; rv && u != G_N_ELEMENTS(subdirs); ++u) {

        char	*fullpath;

        rv	 = FALSE;
        fullpath = g_build_path (G_DIR_SEPARATOR_S,
                                 path, subdirs[u], NULL);

        /* existing dir is okay */
        if (access (fullpath, F_OK|R_OK|W_OK) == 0) {
            struct stat statbuf;
            if (stat (fullpath, &statbuf) != 0) {
                g_set_error (err, G_IO_ERROR,
                             g_io_error_from_errno(errno),
                             "can't stat %s: %s", fullpath,
                             strerror (errno));
                goto done;
            }

            if (!S_ISDIR(statbuf.st_mode)) {
                g_set_error (err, G_IO_ERROR, G_IO_ERROR_EXISTS,
                             "%s already exists", fullpath);
                goto done;
            }
        }

        if (g_mkdir_with_parents (fullpath, (int)mode) != 0) {
            g_set_error (err, G_IO_ERROR,
                         g_io_error_from_errno(errno),
                         "can't create %s: %s", fullpath,
                         strerror (errno));
            goto done;
        }

        rv = TRUE;

done:
        g_free (fullpath);
    }

    return rv;
}
static gchar *
gis_page_util_get_image_version (const gchar *path,
                                 GError     **error)
{
  ssize_t attrsize;
  g_autofree gchar *value = NULL;

  g_return_val_if_fail (path != NULL, NULL);

  attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, NULL, 0);
  if (attrsize >= 0)
    {
      value = g_malloc (attrsize + 1);
      value[attrsize] = 0;

      attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, value,
                           attrsize);
    }

  if (attrsize >= 0)
    {
      return g_steal_pointer (&value);
    }
  else
    {
      int errsv = errno;
      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                   "Error examining " EOS_IMAGE_VERSION_XATTR " on %s: %s",
                   path, g_strerror (errsv));
      return NULL;
    }
}
static gint
mbox_folder_lock (CamelLocalFolder *lf,
                  CamelLockType type,
                  GError **error)
{
#ifndef G_OS_WIN32
	CamelMboxFolder *mf = (CamelMboxFolder *) lf;

	/* make sure we have matching unlocks for locks, camel-local-folder class should enforce this */
	g_return_val_if_fail (mf->lockfd == -1, -1);

	mf->lockfd = open (lf->folder_path, O_RDWR | O_LARGEFILE, 0);
	if (mf->lockfd == -1) {
		g_set_error (
			error, G_IO_ERROR,
			g_io_error_from_errno (errno),
			_("Cannot create folder lock on %s: %s"),
			lf->folder_path, g_strerror (errno));
		return -1;
	}

	if (camel_lock_folder (lf->folder_path, mf->lockfd, type, error) == -1) {
		close (mf->lockfd);
		mf->lockfd = -1;
		return -1;
	}
#endif
	return 0;
}
static gint
nntp_stream_fill (CamelNNTPStream *is,
                  GCancellable *cancellable,
                  GError **error)
{
	gint left = 0;

	if (is->source) {
		left = is->end - is->ptr;
		memcpy (is->buf, is->ptr, left);
		is->end = is->buf + left;
		is->ptr = is->buf;
		left = camel_stream_read (
			is->source, (gchar *) is->end,
			CAMEL_NNTP_STREAM_SIZE - (is->end - is->buf),
			cancellable, error);
		if (left > 0) {
			is->end += left;
			is->end[0] = '\n';
			return is->end - is->ptr;
		} else {
			if (left == 0) {
				errno = ECONNRESET;
				g_set_error (
					error, G_IO_ERROR,
					g_io_error_from_errno (errno),
					"%s", g_strerror (errno));
			}
			return -1;
		}
	}

	return 0;
}
示例#11
0
static gboolean 
open_idle_cb (gpointer data)
{
  GVfsJobOpenForRead *job = data;
  int fd;

  if (g_vfs_job_is_cancelled (G_VFS_JOB (job)))
    {
      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
			G_IO_ERROR_CANCELLED,
			_("Operation was cancelled"));
      return FALSE;
    }
  
  fd = g_open (job->filename, O_RDONLY);
  if (fd == -1)
    {
      int errsv = errno;

      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
			g_io_error_from_errno (errsv),
			"Error opening file %s: %s",
			job->filename, g_strerror (errsv));
    }
  else
    {
      g_vfs_job_open_for_read_set_can_seek (job, TRUE);
      g_vfs_job_open_for_read_set_handle (job, GINT_TO_POINTER (fd));
      g_vfs_job_succeeded (G_VFS_JOB (job));
    }
  return FALSE;
}
示例#12
0
static void
do_query_info_on_read (GVfsBackend *backend,
		       GVfsJobQueryInfoRead *job,
		       GVfsBackendHandle handle,
		       GFileInfo *info,
		       GFileAttributeMatcher *attribute_matcher)
{
  int fd, res;
  struct stat statbuf;
    
  fd = GPOINTER_TO_INT (handle);

  res = fstat (fd, &statbuf);

  if (res == -1)
    {
      int errsv = errno;

      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
			g_io_error_from_errno (errsv),
			"Error querying info in file: %s",
			g_strerror (errsv));
    }
  else
    {
      g_file_info_set_size (info, statbuf.st_size);
      g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_DEVICE,
					statbuf.st_dev);
      g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED, statbuf.st_mtime);
      g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS, statbuf.st_atime);
      g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CHANGED, statbuf.st_ctime);

      g_vfs_job_succeeded (G_VFS_JOB (job));
    }
}
示例#13
0
static void
do_seek_on_read (GVfsBackend *backend,
		 GVfsJobSeekRead *job,
		 GVfsBackendHandle handle,
		 goffset    offset,
		 GSeekType  type)
{
  int whence;
  int fd;
  off_t final_offset;

  g_print ("seek_on_read (%d, %u)\n", (int)offset, type);

  if ((whence = gvfs_seek_type_to_lseek (type)) == -1)
    whence = SEEK_SET;
  
  fd = GPOINTER_TO_INT (handle);

  final_offset = lseek (fd, offset, whence);
  
  if (final_offset == (off_t)-1)
    {
      int errsv = errno;

      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
			g_io_error_from_errno (errsv),
			"Error seeking in file: %s",
			g_strerror (errsv));
    }
  else
    {
      g_vfs_job_seek_read_set_offset (job, offset);
      g_vfs_job_succeeded (G_VFS_JOB (job));
    }
}
示例#14
0
static gboolean 
read_idle_cb (gpointer data)
{
  GVfsJobRead *job = data;
  int fd;
  ssize_t res;

  fd = GPOINTER_TO_INT (job->handle);

  res = read (fd, job->buffer, job->bytes_requested);

  if (res == -1)
    {
      int errsv = errno;

      g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
			g_io_error_from_errno (errsv),
			"Error reading from file: %s",
			g_strerror (errsv));
    }
  else
    {
      g_vfs_job_read_set_size (job, res);
      g_vfs_job_succeeded (G_VFS_JOB (job));
    }
  
  return FALSE;
}
示例#15
0
/*
 * ev_dir_ensure_exists:
 * @dir: the directory name
 * @mode: permissions to use when creating the directory
 * @error: a location to store a #GError
 *
 * Create @dir recursively with permissions @mode.
 *
 * Returns: %TRUE on success, or %FALSE on error with @error filled in
 */
static gboolean
_ev_dir_ensure_exists (const gchar *dir,
                       int          mode,
                       GError     **error)
{
        int errsv;
        char *display_name;

        g_return_val_if_fail (dir != NULL, FALSE);

        errno = 0;
	if (g_mkdir_with_parents (dir, mode) == 0)
		return TRUE;

        errsv = errno;
	if (errsv == EEXIST && g_file_test (dir, G_FILE_TEST_IS_DIR))
                return TRUE;

        display_name = g_filename_display_name (dir);
        g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
                     "Failed to create directory '%s': %s",
                     display_name, g_strerror (errsv));
        g_free (display_name);

	return FALSE;
}
示例#16
0
文件: png2ctx.c 项目: ev3dev/grx
/**
 * grx_context_load_from_png:
 * @context: (nullable): Context to be loaded or %NULL to use the global context
 * @filename: (type filename): Name of jpeg file
 * @use_alpha: if %TRUE, use alpha channel if available
 * @error: pointer to hold an error or %NULL to ignore
 *
 * Load a context from a PNG file
 *
 * If context dimensions are less than png dimensions,
 * the routine loads as much as it can
 *
 * If color mode is not in RGB mode, the routine allocates as
 * many colors as it can
 *
 * Returns: %TRUE on success, otherwise %FALSE
 */
gboolean grx_context_load_from_png(GrxContext *grc, const char *pngfn, int use_alpha, GError **error)
{
  GrxContext grcaux;
  FILE *f;
  gboolean r;
  
  f = fopen( pngfn,"rb" );
  if (f == NULL) {
    g_set_error(error, G_IO_ERROR, g_io_error_from_errno(errno),
      "Failed to open '%s'", pngfn);
    return FALSE;
  }

  grx_save_current_context( &grcaux );
  if( grc != NULL ) grx_set_current_context( grc );
  r = readpng( f,grc,use_alpha );
  grx_set_current_context( &grcaux );

  fclose( f );

  if (!r) {
    g_set_error(error, GRX_ERROR, GRX_ERROR_PNG_ERROR,
      "Error while reading '%s'", pngfn);
  }

  return r;
}
示例#17
0
static gboolean
g_unix_input_stream_close (GInputStream  *stream,
			   GCancellable  *cancellable,
			   GError       **error)
{
  GUnixInputStream *unix_stream;
  int res;

  unix_stream = G_UNIX_INPUT_STREAM (stream);

  if (!unix_stream->priv->close_fd)
    return TRUE;
  
  /* This might block during the close. Doesn't seem to be a way to avoid it though. */
  res = close (unix_stream->priv->fd);
  if (res == -1)
    {
      int errsv = errno;

      g_set_error (error, G_IO_ERROR,
		   g_io_error_from_errno (errsv),
		   _("Error closing file descriptor: %s"),
		   g_strerror (errsv));
    }
  
  return res != -1;
}
示例#18
0
static gboolean
g_local_file_output_stream_seek (GFileOutputStream  *stream,
				 goffset             offset,
				 GSeekType           type,
				 GCancellable       *cancellable,
				 GError            **error)
{
  GLocalFileOutputStream *file;
  off_t pos;

  file = G_LOCAL_FILE_OUTPUT_STREAM (stream);

  pos = lseek (file->priv->fd, offset, seek_type_to_lseek (type));

  if (pos == (off_t)-1)
    {
      int errsv = errno;

      g_set_error (error, G_IO_ERROR,
		   g_io_error_from_errno (errsv),
		   _("Error seeking in file: %s"),
		   g_strerror (errsv));
      return FALSE;
    }
  
  return TRUE;
}
示例#19
0
文件: ctx2png.c 项目: ev3dev/grx
/**
 * grx_context_save_to_png:
 * @context: (nullable): Context to be saved or %NULL to use the global context
 * @filename: (type filename): Name of png file
 * @error: pointer to hold an error or %NULL to ignore
 *
 * Dump a context in a PNG file
 *
 * This routine works both in RGB and palette modes
 *
 * Returns: %TRUE on success, otherwise %FALSE
 */
gboolean grx_context_save_to_png(GrxContext *grc, char *pngfn, GError **error)
{
  GrxContext grcaux;
  FILE *f;
  gboolean r;
  
  f = fopen( pngfn,"wb" );
  if (f == NULL) {
    g_set_error(error, G_IO_ERROR, g_io_error_from_errno(errno),
      "Failed to open '%s'", pngfn);
    return FALSE;
  }

  grx_save_current_context( &grcaux );
  if( grc != NULL ) grx_set_current_context( grc );
  r = writepng( f,grc );
  grx_set_current_context( &grcaux );

  fclose( f );

  if (!r) {
    g_set_error(error, GRX_ERROR, GRX_ERROR_PNG_ERROR,
      "Problem with PNG data in '%s'", pngfn);
  }

  return r;
}
static gboolean
g_local_file_input_stream_close (GInputStream  *stream,
				 GCancellable  *cancellable,
				 GError       **error)
{
  GLocalFileInputStream *file;
  int res;

  file = G_LOCAL_FILE_INPUT_STREAM (stream);

  if (!file->priv->do_close)
    return TRUE;

  if (file->priv->fd == -1)
    return TRUE;

  while (1)
    {
      res = close (file->priv->fd);
      if (res == -1)
        {
          int errsv = errno;

          g_set_error (error, G_IO_ERROR,
                       g_io_error_from_errno (errsv),
                       _("Error closing file: %s"),
                       g_strerror (errsv));
        }
      break;
    }

  return res != -1;
}
示例#21
0
static gssize
g_local_file_output_stream_write (GOutputStream  *stream,
				  const void     *buffer,
				  gsize           count,
				  GCancellable   *cancellable,
				  GError        **error)
{
  GLocalFileOutputStream *file;
  gssize res;

  file = G_LOCAL_FILE_OUTPUT_STREAM (stream);

  while (1)
    {
      if (g_cancellable_set_error_if_cancelled (cancellable, error))
	return -1;
      res = write (file->priv->fd, buffer, count);
      if (res == -1)
	{
          int errsv = errno;

	  if (errsv == EINTR)
	    continue;
	  
	  g_set_error (error, G_IO_ERROR,
		       g_io_error_from_errno (errsv),
		       _("Error writing to file: %s"),
		       g_strerror (errsv));
	}
      
      break;
    }
  
  return res;
}
示例#22
0
/**
 * test_pipe:
 * @is: (out) (allow-none): used to return a #GInputStream
 * @os: (out) (allow-none): used to return a #GOutputStream
 * @error: used to raise an error
 *
 * Return a "pipe to self" connecting @is to @os. This can be used
 * as a unidirectional pipe to or from a child process, for instance.
 *
 * See test_bidi_pipe() if you want to emulate a bidirectional pipe
 * via a pair of unidirectional pipes.
 *
 * Returns: %TRUE on success
 */
gboolean
test_pipe (GInputStream  **is,
           GOutputStream **os,
           GError        **error)
{
    int pipefd[2];
    int ret;

    ret = pipe (pipefd);

    if (ret != 0)
    {
        int e = errno;

        g_set_error (error, G_IO_ERROR, g_io_error_from_errno (e),
                     "%s", g_strerror (e));
        return FALSE;
    }

    if (is != NULL)
        *is = g_unix_input_stream_new (pipefd[0], TRUE);
    else
        close (pipefd[0]);

    if (os != NULL)
        *os = g_unix_output_stream_new (pipefd[1], TRUE);
    else
        close (pipefd[1]);

    return TRUE;
}
GFileEnumerator *
_g_local_file_enumerator_new (GLocalFile *file,
			      const char           *attributes,
			      GFileQueryInfoFlags   flags,
			      GCancellable         *cancellable,
			      GError              **error)
{
  GLocalFileEnumerator *local;
  char *filename = g_file_get_path (G_FILE (file));

#ifdef USE_GDIR
  GError *dir_error;
  GDir *dir;
  
  dir_error = NULL;
  dir = g_dir_open (filename, 0, error != NULL ? &dir_error : NULL);
  if (dir == NULL) 
    {
      if (error != NULL)
	{
	  convert_file_to_io_error (error, dir_error);
	  g_error_free (dir_error);
	}
      g_free (filename);
      return NULL;
    }
#else
  DIR *dir;
  int errsv;

  dir = opendir (filename);
  if (dir == NULL)
    {
      errsv = errno;

      g_set_error_literal (error, G_IO_ERROR,
                           g_io_error_from_errno (errsv),
                           g_strerror (errsv));
      g_free (filename);
      return NULL;
    }

#endif
  
  local = g_object_new (G_TYPE_LOCAL_FILE_ENUMERATOR,
                        "container", file,
                        NULL);

  local->dir = dir;
  local->filename = filename;
  local->matcher = g_file_attribute_matcher_new (attributes);
#ifndef USE_GDIR
  local->reduced_matcher = g_file_attribute_matcher_subtract_attributes (local->matcher,
                                                                         G_LOCAL_FILE_INFO_NOSTAT_ATTRIBUTES","
                                                                         "standard::type");
#endif
  local->flags = flags;
  
  return G_FILE_ENUMERATOR (local);
}
static gboolean
delete_conf_files (GError **error)
{
  gboolean rval = TRUE;
  GDir *zramconfd;
  gchar *filename = NULL;
  const gchar *name;

  filename = g_build_filename (PACKAGE_MODLOAD_DIR, "/zram.conf", NULL);

  if (g_unlink (filename))
    {
      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),"%m");
      rval = FALSE;
      goto out;
    }

  g_free (filename);
  filename = g_build_filename (PACKAGE_MODPROBE_DIR, "/zram.conf", NULL);

  if (g_unlink (filename))
    {
      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),"%m");
      rval = FALSE;
      goto out;
    }

  zramconfd = g_dir_open (PACKAGE_ZRAMCONF_DIR, 0, error);
  if (! zramconfd)
  {
    rval = FALSE;
    goto out;
  }

  while ((name = g_dir_read_name (zramconfd)))
  {
    g_free (filename);
    filename = g_build_filename (PACKAGE_ZRAMCONF_DIR, name, NULL);
    g_unlink (filename);
  }
  g_dir_close (zramconfd);

out:
  g_free (filename);
  return rval;

}
示例#25
0
/**
 * gs_set_error_from_errno:
 * @error: (allow-none): Error
 * @saved_errno: errno value
 * 
 * Set @error to an error with domain %G_IO_ERROR, and code based on
 * the value of @saved_errno.  The error message is set using a
 * literal return from g_strerror().
 */
void
gs_set_error_from_errno (GError **error, gint saved_errno)
{
  g_set_error_literal (error,
                       G_IO_ERROR,
                       g_io_error_from_errno (saved_errno),
                       g_strerror (saved_errno));
  errno = saved_errno;
}
static gint
camel_movemail_copy_file (gint sfd,
                          gint dfd,
                          GError **error)
{
    gint nread, nwrote;
    gchar buf[4096];

    while (1) {
        gint written = 0;

        nread = read (sfd, buf, sizeof (buf));
        if (nread == 0)
            break;
        else if (nread == -1) {
            if (errno == EINTR)
                continue;
            g_set_error (
                error, G_IO_ERROR,
                g_io_error_from_errno (errno),
                _("Error reading mail file: %s"),
                g_strerror (errno));
            return -1;
        }

        while (nread) {
            nwrote = write (dfd, buf + written, nread);
            if (nwrote == -1) {
                if (errno == EINTR)
                    continue; /* continues inner loop */
                g_set_error (
                    error, G_IO_ERROR,
                    g_io_error_from_errno (errno),
                    _("Error writing mail temp file: %s"),
                    g_strerror (errno));
                return -1;
            }
            written += nwrote;
            nread -= nwrote;
        }
    }

    return 0;
}
示例#27
0
文件: pty.c 项目: gbl/vte
/**
 * vte_pty_set_utf8:
 * @pty: a #VtePty
 * @utf8: whether or not the pty is in UTF-8 mode
 * @error: (allow-none): return location to store a #GError, or %NULL
 *
 * Tells the kernel whether the terminal is UTF-8 or not, in case it can make
 * use of the info.  Linux 2.6.5 or so defines IUTF8 to make the line
 * discipline do multibyte backspace correctly.
 *
 * Returns: %TRUE on success, %FALSE on failure with @error filled in
 */
gboolean
vte_pty_set_utf8(VtePty *pty,
                 gboolean utf8,
                 GError **error)
{
#if defined(HAVE_TCSETATTR) && defined(IUTF8)
        VtePtyPrivate *priv;
	struct termios tio;
	tcflag_t saved_cflag;

        g_return_val_if_fail(VTE_IS_PTY(pty), FALSE);

        priv = pty->priv;
        g_return_val_if_fail (priv->pty_fd > 0, FALSE);

        if (tcgetattr(priv->pty_fd, &tio) == -1) {
                int errsv = errno;
                g_set_error(error, G_IO_ERROR, g_io_error_from_errno(errsv),
                            "%s failed: %s", "tcgetattr", g_strerror(errsv));
                errno = errsv;
                return FALSE;
        }

        saved_cflag = tio.c_iflag;
        if (utf8) {
                tio.c_iflag |= IUTF8;
        } else {
              tio.c_iflag &= ~IUTF8;
        }

        /* Only set the flag if it changes */
        if (saved_cflag != tio.c_iflag &&
            tcsetattr(priv->pty_fd, TCSANOW, &tio) == -1) {
                int errsv = errno;
                g_set_error(error, G_IO_ERROR, g_io_error_from_errno(errsv),
                            "%s failed: %s", "tcgetattr", g_strerror(errsv));
                errno = errsv;
                return FALSE;
	}
#endif

        return TRUE;
}
示例#28
0
void
_rpmostree_set_error_from_errno (GError    **error,
                                 gint        errsv)
{
  g_set_error_literal (error,
                       G_IO_ERROR,
                       g_io_error_from_errno (errsv),
                       g_strerror (errsv));
  errno = errsv;
}
static gssize
g_local_file_input_stream_skip (GInputStream  *stream,
				gsize          count,
				GCancellable  *cancellable,
				GError       **error)
{
  off_t res, start;
  GLocalFileInputStream *file;

  file = G_LOCAL_FILE_INPUT_STREAM (stream);
  
  if (g_cancellable_set_error_if_cancelled (cancellable, error))
    return -1;
  
  start = lseek (file->priv->fd, 0, SEEK_CUR);
  if (start == -1)
    {
      int errsv = errno;

      g_set_error (error, G_IO_ERROR,
		   g_io_error_from_errno (errsv),
		   _("Error seeking in file: %s"),
		   g_strerror (errsv));
      return -1;
    }
  
  res = lseek (file->priv->fd, count, SEEK_CUR);
  if (res == -1)
    {
      int errsv = errno;

      g_set_error (error, G_IO_ERROR,
		   g_io_error_from_errno (errsv),
		   _("Error seeking in file: %s"),
		   g_strerror (errsv));
      return -1;
    }

  return res - start;
}
示例#30
0
static gboolean
close_async_cb (CloseAsyncData *data)
{
  GUnixInputStream *unix_stream;
  GSimpleAsyncResult *simple;
  GError *error = NULL;
  gboolean result;
  int res;

  unix_stream = G_UNIX_INPUT_STREAM (data->stream);

  if (!unix_stream->priv->close_fd)
    {
      result = TRUE;
      goto out;
    }
  
  while (1)
    {
      res = close (unix_stream->priv->fd);
      if (res == -1)
        {
          int errsv = errno;

          g_set_error (&error, G_IO_ERROR,
                       g_io_error_from_errno (errsv),
                       _("Error closing unix: %s"),
                       g_strerror (errsv));
        }
      break;
    }
  
  result = res != -1;

 out:
  simple = g_simple_async_result_new (G_OBJECT (data->stream),
				      data->callback,
				      data->user_data,
				      g_unix_input_stream_close_async);

  if (!result)
    {
      g_simple_async_result_set_from_error (simple, error);
      g_error_free (error);
    }

  /* Complete immediately, not in idle, since we're already in a mainloop callout */
  g_simple_async_result_complete (simple);
  g_object_unref (simple);
  
  return FALSE;
}