Imported Upstream version 2016.6

This commit is contained in:
Simon McVittie committed 2016-06-26 12:12:26 +01:00
1 parent a7b5654e44
commit 24762929e2
115 files changed
+4857 -2074

No files matched your search

+58 -42
View File
@@ -177,22 +177,9 @@ printpad (const char *padbuf,
fwrite (padbuf, 1, r, stdout);
}
/**
* glnx_console_progress_text_percent:
* @text: Show this text before the progress bar
* @percentage: An integer in the range of 0 to 100
*
* On a tty, print to the console @text followed by an ASCII art
* progress bar whose percentage is @percentage. If stdout is not a
* tty, a more basic line by line change will be printed.
*
* You must have called glnx_console_lock() before invoking this
* function.
*
*/
void
glnx_console_progress_text_percent (const char *text,
guint percentage)
static void
text_percent_internal (const char *text,
int percentage)
{
static const char equals[] = "====================";
const guint n_equals = sizeof (equals) - 1;
@@ -201,10 +188,6 @@ glnx_console_progress_text_percent (const char *text,
const guint ncolumns = glnx_console_columns ();
const guint bar_min = 10;
const guint input_textlen = text ? strlen (text) : 0;
guint textlen;
guint barlen;
g_return_if_fail (percentage >= 0 && percentage <= 100);
if (text && !*text)
text = NULL;
@@ -236,36 +219,69 @@ glnx_console_progress_text_percent (const char *text,
(void) fwrite (beginbuf, 1, sizeof (beginbuf), stdout);
}
textlen = MIN (input_textlen, ncolumns - bar_min);
barlen = ncolumns - textlen;
if (textlen > 0)
if (percentage == -1)
{
fwrite (text, 1, textlen, stdout);
fputc (' ', stdout);
const guint spacelen = ncolumns - input_textlen;
fwrite (text, 1, input_textlen, stdout);
printpad (spaces, n_spaces, spacelen);
}
{
const guint nbraces = 2;
const guint textpercent_len = 5;
const guint bar_internal_len = barlen - nbraces - textpercent_len;
const guint eqlen = bar_internal_len * (percentage / 100.0);
const guint spacelen = bar_internal_len - eqlen;
else
{
const guint textlen = MIN (input_textlen, ncolumns - bar_min);
const guint barlen = ncolumns - (textlen + 1);;
fputc ('[', stdout);
printpad (equals, n_equals, eqlen);
printpad (spaces, n_spaces, spacelen);
fputc (']', stdout);
fprintf (stdout, " %3d%%", percentage);
}
if (textlen > 0)
{
fwrite (text, 1, textlen, stdout);
fputc (' ', stdout);
}
{ const guint spacelen = ncolumns - textlen - barlen;
printpad (spaces, n_spaces, spacelen);
}
{
const guint nbraces = 2;
const guint textpercent_len = 5;
const guint bar_internal_len = barlen - nbraces - textpercent_len;
const guint eqlen = bar_internal_len * (percentage / 100.0);
const guint spacelen = bar_internal_len - eqlen;
fputc ('[', stdout);
printpad (equals, n_equals, eqlen);
printpad (spaces, n_spaces, spacelen);
fputc (']', stdout);
fprintf (stdout, " %3d%%", percentage);
}
}
fflush (stdout);
}
/**
* glnx_console_progress_text_percent:
* @text: Show this text before the progress bar
* @percentage: An integer in the range of 0 to 100
*
* On a tty, print to the console @text followed by an ASCII art
* progress bar whose percentage is @percentage. If stdout is not a
* tty, a more basic line by line change will be printed.
*
* You must have called glnx_console_lock() before invoking this
* function.
*
*/
void
glnx_console_progress_text_percent (const char *text,
guint percentage)
{
g_return_if_fail (percentage >= 0 && percentage <= 100);
text_percent_internal (text, percentage);
}
void
glnx_console_text (const char *text)
{
text_percent_internal (text, -1);
}
/**
* glnx_console_unlock:
*
+2
View File
@@ -33,6 +33,8 @@ typedef struct GLnxConsoleRef GLnxConsoleRef;
void glnx_console_lock (GLnxConsoleRef *ref);
void glnx_console_text (const char *text);
void glnx_console_progress_text_percent (const char *text,
guint percentage);
+37 -21
View File
@@ -277,20 +277,17 @@ glnx_fdrel_abspath (int dfd,
}
/**
* glnx_mkdtempat:
* @dfd: Directory fd
* @tmpl: (type filename): template directory name
* @mode: permissions to create the temporary directory with
* @error: Error
* glnx_gen_temp_name:
* @tmpl: (type filename): template directory name, the last 6 characters will be replaced
*
* Similar to g_mkdtemp_full, but using openat.
* Replace the last 6 characters of @tmpl with random ASCII. You must
* use this in combination with a mechanism to ensure race-free file
* creation such as `O_EXCL`.
*/
gboolean
glnx_mkdtempat (int dfd,
gchar *tmpl,
int mode,
GError **error)
void
glnx_gen_temp_name (gchar *tmpl)
{
size_t len;
char *XXXXXX;
int count;
static const char letters[] =
@@ -300,17 +297,11 @@ glnx_mkdtempat (int dfd,
GTimeVal tv;
static int counter = 0;
g_return_val_if_fail (tmpl != NULL, -1);
g_return_if_fail (tmpl != NULL);
len = strlen (tmpl);
g_return_if_fail (len >= 6);
/* find the last occurrence of "XXXXXX" */
XXXXXX = g_strrstr (tmpl, "XXXXXX");
if (!XXXXXX || strncmp (XXXXXX, "XXXXXX", 6))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
"Invalid temporary directory template '%s'", tmpl);
return FALSE;
}
XXXXXX = tmpl + (len - 6);
/* Get some more or less random data. */
g_get_current_time (&tv);
@@ -332,6 +323,31 @@ glnx_mkdtempat (int dfd,
XXXXXX[4] = letters[v % NLETTERS];
v /= NLETTERS;
XXXXXX[5] = letters[v % NLETTERS];
}
}
/**
* glnx_mkdtempat:
* @dfd: Directory fd
* @tmpl: (type filename): template directory name, last 6 characters will be replaced
* @mode: permissions to create the temporary directory with
* @error: Error
*
* Similar to g_mkdtemp_full, but using openat.
*/
gboolean
glnx_mkdtempat (int dfd,
gchar *tmpl,
int mode,
GError **error)
{
int count;
g_return_val_if_fail (tmpl != NULL, -1);
for (count = 0; count < 100; count++)
{
glnx_gen_temp_name (tmpl);
if (mkdirat (dfd, tmpl, mode) == -1)
{
+2
View File
@@ -81,6 +81,8 @@ gboolean glnx_opendirat (int dfd,
char *glnx_fdrel_abspath (int dfd,
const char *path);
void glnx_gen_temp_name (gchar *tmpl);
gboolean glnx_mkdtempat (int dfd,
gchar *tmpl,
int mode,
+30
View File
@@ -746,5 +746,35 @@ glnx_file_replace_contents_with_perms_at (int dfd,
ret = TRUE;
out:
if (!ret)
(void) unlink (tmppath);
return ret;
}
/**
* glnx_stream_fstat:
* @stream: A stream containing a Unix file descriptor
* @stbuf: Memory location to write stat buffer
* @error:
*
* Some streams created via libgsystem are #GUnixInputStream; these do
* not support e.g. g_file_input_stream_query_info(). This function
* allows dropping to the raw unix fstat() call for these types of
* streams, while still conveniently wrapped with the normal GLib
* handling of @error.
*/
gboolean
glnx_stream_fstat (GFileDescriptorBased *stream,
struct stat *stbuf,
GError **error)
{
int fd = g_file_descriptor_based_get_fd (stream);
if (fstat (fd, stbuf) == -1)
{
glnx_set_prefix_error_from_errno (error, "%s", "fstat");
return FALSE;
}
return TRUE;
}
+6
View File
@@ -21,6 +21,7 @@
#pragma once
#include <glnx-backport-autocleanups.h>
#include <gio/gfiledescriptorbased.h>
#include <limits.h>
#include <dirent.h>
#include <sys/stat.h>
@@ -121,4 +122,9 @@ glnx_file_copy_at (int src_dfd,
GCancellable *cancellable,
GError **error);
gboolean
glnx_stream_fstat (GFileDescriptorBased *stream,
struct stat *stbuf,
GError **error);
G_END_DECLS
+8 -3
View File
@@ -274,6 +274,14 @@ glnx_libcontainer_run_chroot_private (const char *dest,
if (chdir ("/") != 0)
_perror_fatal ("chdir: ");
/* Environment variables like PATH in the end are distribution
* specific. The most correct thing would be to run through PAM,
* but that's a huge level of pain. We'd like to drive towards a
* standard /usr/bin (i.e. unified sbin too), but for now this is
* pretty compatible.
*/
setenv ("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 1);
if (binary[0] == '/')
{
if (execv (binary, argv) != 0)
@@ -281,9 +289,6 @@ glnx_libcontainer_run_chroot_private (const char *dest,
}
else
{
/* Set PATH to something sane. */
setenv ("PATH", "/usr/sbin:/usr/bin", 1);
if (execvp (binary, argv) != 0)
_perror_fatal ("execvp: ");
}
+7 -2
View File
@@ -21,6 +21,7 @@
#pragma once
#include <gio/gio.h>
#include <errno.h>
G_BEGIN_DECLS
@@ -195,13 +196,17 @@ GLNX_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, glnx_local_keyfile_unref, g_key_file_un
static inline void
glnx_cleanup_close_fdp (int *fdp)
{
int fd;
int fd, errsv;
g_assert (fdp);
fd = *fdp;
if (fd != -1)
(void) close (fd);
{
errsv = errno;
(void) close (fd);
errno = errsv;
}
}
/**