]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Merge branch 'ldadd-cflags-warnings' of https://github.com/rudimeier/util-linux
authorKarel Zak <kzak@redhat.com>
Wed, 24 Feb 2016 12:51:10 +0000 (13:51 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Feb 2016 12:51:10 +0000 (13:51 +0100)
* 'ldadd-cflags-warnings' of https://github.com/rudimeier/util-linux:
  build-sys: disable unused parameter warnings for some test progs
  misc: fix compiler warnungs (unsigned/signed)
  misc: fix warnings "unused parameter" [-Wunused-parameter]
  libfdisk: fix warnings, "redundant redeclaration" [-Wredundant-decls]
  tests: fix compiler warnings [-Wmissing-prototypes]
  libfdisk: fix compiler warnings [-Wmissing-prototypes]
  libfdisk: fix missing symbol
  libblkid: fix compiler warnings [-Wmissing-prototypes]
  libmount: add mnt_fs_set_priority()
  build-sys: always add AM_CFLAGS
  build-sys: always use global LDADD

libsmartcols/samples/continuous.c
libsmartcols/src/column.c
libsmartcols/src/table.c
libsmartcols/src/table_print.c
misc-utils/findmnt.c
misc-utils/logger.c
schedutils/chrt.c
sys-utils/unshare.1

index 2fe720e2f852d69807c1925709401f1cc4c2dbce..02efd5de92ca4a4884dfe1977ba9fa130b56106d 100644 (file)
@@ -30,11 +30,12 @@ static double time_diff(struct timeval *a, struct timeval *b)
 /* add columns to the @tb */
 static void setup_columns(struct libscols_table *tb)
 {
-       if (!scols_table_new_column(tb, "#NUM", 0, SCOLS_FL_RIGHT))
+       scols_table_enable_maxout(tb, 1);
+       if (!scols_table_new_column(tb, "#NUM", 0.1, SCOLS_FL_RIGHT))
                goto fail;
-       if (!scols_table_new_column(tb, "DATA", 0, 0))
+       if (!scols_table_new_column(tb, "DATA", 0.7, 0))
                goto fail;
-       if (!scols_table_new_column(tb, "TIME", 0, 0))
+       if (!scols_table_new_column(tb, "TIME", 0.2, 0))
                goto fail;
        return;
 fail:
index 55c24da2215dad8773ca6607f35e4de67c3ea909..5e7050192853d2f149e60d2a343261f7ebe3ee9b 100644 (file)
@@ -119,7 +119,7 @@ err:
  * @cl: a pointer to a struct libscols_column instance
  * @whint: a width hint
  *
- * Sets the width hint of column @cl to @whint.
+ * Sets the width hint of column @cl to @whint. See scols_table_new_column().
  *
  * Returns: 0, a negative value in case of an error.
  */
index 59684789ebddf90c79fc3fd1524f7cb0d430792f..251fe216944d566d2d4ff0bfcf1a145477c2f271 100644 (file)
@@ -233,17 +233,19 @@ int scols_table_remove_columns(struct libscols_table *tb)
  *   scols_column_set_....(cl, ...);
  *   scols_table_add_column(tb, cl);
  *
- * The column width is possible to define by three ways:
+ * The column width is possible to define by:
  *
  *  @whint = 0..1    : relative width, percent of terminal width
  *
  *  @whint = 1..N    : absolute width, empty column will be truncated to
- *                     the column header width
+ *                     the column header width if no specified STRICTWIDTH flag
  *
- *  @whint = 1..N
+ * Note that if table has disabled "maxout" flag (disabled by default) than
+ * relative width is used as a hint only. It's possible that column will be
+ * narrow if the specified size is too large for column data.
  *
- * The column is necessary to address by
- * sequential number. The first defined column has the colnum = 0. For example:
+ * The column is necessary to address by sequential number. The first defined
+ * column has the colnum = 0. For example:
  *
  *     scols_table_new_column(tab, "FOO", 0.5, 0);             // colnum = 0
  *     scols_table_new_column(tab, "BAR", 0.5, 0);             // colnum = 1
index 8803c73d98cf1f1d5ad237870bca2d8cce0dde92..d1dcb65bdabb7a404ca8ece2dd0874e8cb54fc03 100644 (file)
@@ -177,9 +177,9 @@ static int line_ascii_art_to_buffer(struct libscols_table *tb,
        return buffer_append_data(buf, art);
 }
 
-static int is_last_column(struct libscols_table *tb, struct libscols_column *cl) 
+static int is_last_column(struct libscols_column *cl)
 {
-       int rc = list_entry_is_last(&cl->cl_columns, &tb->tb_columns);
+       int rc = list_entry_is_last(&cl->cl_columns, &cl->table->tb_columns);
        struct libscols_column *next;
 
        if (rc)
@@ -377,7 +377,7 @@ static int print_pending_data(
        for (i = len; i < width; i++)
                fputc(' ', tb->out);            /* padding */
 
-       if (is_last_column(tb, cl))
+       if (is_last_column(cl))
                return 0;
 
        fputs(colsep(tb), tb->out);             /* columns separator */
@@ -411,14 +411,14 @@ static int print_data(struct libscols_table *tb,
        switch (tb->format) {
        case SCOLS_FMT_RAW:
                fputs_nonblank(data, tb->out);
-               if (!is_last_column(tb, cl))
+               if (!is_last_column(cl))
                        fputs(colsep(tb), tb->out);
                return 0;
 
        case SCOLS_FMT_EXPORT:
                fprintf(tb->out, "%s=", scols_cell_get_data(&cl->header));
                fputs_quoted(data, tb->out);
-               if (!is_last_column(tb, cl))
+               if (!is_last_column(cl))
                        fputs(colsep(tb), tb->out);
                return 0;
 
@@ -429,7 +429,7 @@ static int print_data(struct libscols_table *tb,
                        fputs("null", tb->out);
                else
                        fputs_quoted(data, tb->out);
-               if (!is_last_column(tb, cl))
+               if (!is_last_column(cl))
                        fputs(", ", tb->out);
                return 0;
 
@@ -446,7 +446,7 @@ static int print_data(struct libscols_table *tb,
        width = cl->width;
        bytes = strlen(data);
 
-       if (is_last_column(tb, cl)
+       if (is_last_column(cl)
            && len < width
            && !scols_table_is_maxout(tb)
            && !scols_column_is_right(cl)
@@ -504,7 +504,7 @@ static int print_data(struct libscols_table *tb,
        for (i = len; i < width; i++)
                fputc(' ', tb->out);            /* padding */
 
-       if (is_last_column(tb, cl))
+       if (is_last_column(cl))
                return 0;
 
        if (len > width && !scols_column_is_trunc(cl))
@@ -956,6 +956,15 @@ static int count_column_width(struct libscols_table *tb,
 
        cl->width = 0;
 
+       if (!cl->width_min) {
+               if (cl->width_hint < 1 && scols_table_is_maxout(tb))
+                       cl->width_min = (size_t) (cl->width_hint * tb->termwidth) - (is_last_column(cl) ? 0 : 1);
+               if (scols_cell_get_data(&cl->header)) {
+                       size_t len = mbs_safe_width(scols_cell_get_data(&cl->header));
+                       cl->width_min = max(cl->width_min, len);
+               }
+       }
+
        scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
        while (scols_table_next_line(tb, &itr, &ln) == 0) {
                size_t len;
@@ -987,20 +996,15 @@ static int count_column_width(struct libscols_table *tb,
 
        if (count && cl->width_avg == 0) {
                cl->width_avg = sum / count;
-
                if (cl->width_max > cl->width_avg * 2)
                        cl->is_extreme = 1;
        }
 
-       /* check and set minimal column width */
-       if (scols_cell_get_data(&cl->header))
-               cl->width_min = mbs_safe_width(scols_cell_get_data(&cl->header));
-
        /* enlarge to minimal width */
        if (cl->width < cl->width_min && !scols_column_is_strict_width(cl))
                cl->width = cl->width_min;
 
-       /* use relative size for large columns */
+       /* use absolute size for large columns */
        else if (cl->width_hint >= 1 && cl->width < (size_t) cl->width_hint
                 && cl->width_min < (size_t) cl->width_hint)
 
@@ -1008,7 +1012,6 @@ static int count_column_width(struct libscols_table *tb,
 
 done:
        ON_DBG(COL, dbg_column(tb, cl));
-       DBG(COL, ul_debugobj(cl, "column width=%zu, rc=%d", cl->width, rc));
        return rc;
 }
 
@@ -1019,7 +1022,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
 {
        struct libscols_column *cl;
        struct libscols_iter itr;
-       size_t width = 0;               /* output width */
+       size_t width = 0, width_min = 0;        /* output width */
        int trunc_only, rc = 0;
        int extremes = 0;
 
@@ -1034,18 +1037,32 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                if (rc)
                        goto done;
 
-               width += cl->width + (is_last_column(tb, cl) ? 0 : 1);  /* separator for non-last column */
+               width += cl->width + (is_last_column(cl) ? 0 : 1);              /* separator for non-last column */
+               width_min += cl->width_min + (is_last_column(cl) ? 0 : 1);
                extremes += cl->is_extreme;
        }
 
        if (!tb->is_term) {
-               DBG(TAB, ul_debugobj(tb, "   non-terminal output"));
+               DBG(TAB, ul_debugobj(tb, " non-terminal output"));
                goto done;
        }
 
+       /* be paranoid */
+       if (width_min > tb->termwidth && scols_table_is_maxout(tb)) {
+               DBG(TAB, ul_debugobj(tb, " min width larger than terminal! [width=%zu, term=%zu]", width_min, tb->termwidth));
+
+               scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
+               while (width_min > tb->termwidth
+                      && scols_table_next_column(tb, &itr, &cl) == 0) {
+                       width_min--;
+                       cl->width_min--;
+               }
+               DBG(TAB, ul_debugobj(tb, " min width reduced to %zu", width_min));
+       }
+
        /* reduce columns with extreme fields */
        if (width > tb->termwidth && extremes) {
-               DBG(TAB, ul_debugobj(tb, "   reduce width (extreme columns)"));
+               DBG(TAB, ul_debugobj(tb, " reduce width (extreme columns)"));
 
                scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
                while (scols_table_next_column(tb, &itr, &cl) == 0) {
@@ -1068,7 +1085,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
 
        if (width < tb->termwidth) {
                if (extremes) {
-                       DBG(TAB, ul_debugobj(tb, "   enlarge width (extreme columns)"));
+                       DBG(TAB, ul_debugobj(tb, " enlarge width (extreme columns)"));
 
                        /* enlarge the first extreme column */
                        scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
@@ -1097,7 +1114,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                }
 
                if (width < tb->termwidth && scols_table_is_maxout(tb)) {
-                       DBG(TAB, ul_debugobj(tb, "   enlarge width (max-out)"));
+                       DBG(TAB, ul_debugobj(tb, " enlarge width (max-out)"));
 
                        /* try enlarging all columns */
                        while (width < tb->termwidth) {
@@ -1114,7 +1131,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                        struct libscols_column *col = list_entry(
                                tb->tb_columns.prev, struct libscols_column, cl_columns);
 
-                       DBG(TAB, ul_debugobj(tb, "   enlarge width (last column)"));
+                       DBG(TAB, ul_debugobj(tb, " enlarge width (last column)"));
 
                        if (!scols_column_is_right(col) && tb->termwidth - width > 0) {
                                col->width += tb->termwidth - width;
@@ -1131,7 +1148,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
        while (width > tb->termwidth) {
                size_t org = width;
 
-               DBG(TAB, ul_debugobj(tb, "   reduce width (current=%zu, "
+               DBG(TAB, ul_debugobj(tb, " reduce width (current=%zu, "
                                         "wanted=%zu, mode=%s)",
                                        width, tb->termwidth,
                                        trunc_only ? "trunc-only" : "all-relative"));
@@ -1139,7 +1156,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
                while (scols_table_next_column(tb, &itr, &cl) == 0) {
 
-                       DBG(TAB, ul_debugobj(cl, "     checking %s (width=%zu, treeart=%zu)",
+                       DBG(TAB, ul_debugobj(cl, "  checking %s (width=%zu, treeart=%zu)",
                                                cl->header.data, cl->width, cl->width_treeart));
 
                        if (width <= tb->termwidth)
@@ -1153,7 +1170,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                        if (cl->width == cl->width_min)
                                continue;
 
-                       DBG(TAB, ul_debugobj(tb, "     tring to reduce: %s (width=%zu)", cl->header.data, cl->width));
+                       DBG(TAB, ul_debugobj(tb, "  tring to reduce: %s (width=%zu)", cl->header.data, cl->width));
 
                        /* truncate column with relative sizes */
                        if (cl->width_hint < 1 && cl->width > 0 && width > 0 &&
@@ -1198,7 +1215,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                }
        }
 done:
-       DBG(TAB, ul_debugobj(tb, "  final width: %zu (rc=%d)", width, rc));
+       DBG(TAB, ul_debugobj(tb, " final width: %zu (rc=%d)", width, rc));
        ON_DBG(TAB, dbg_columns(tb));
 
        return rc;
index dd84671dcc1d8dbc6dcf02f2535c650b3ca05610..f72be14b9ef652e2572592fe70eb063357ca2cc2 100644 (file)
@@ -1165,7 +1165,7 @@ static int poll_table(struct libmnt_table *tb, const char *tabfile,
                }
 
                if (count) {
-                       rc = scols_print_table(table);
+                       rc = scols_table_print_range(table, NULL, NULL);
                        if (rc)
                                goto done;
                }
@@ -1175,6 +1175,7 @@ static int poll_table(struct libmnt_table *tb, const char *tabfile,
                tb = tb_new;
                tb_new = tmp;
 
+               /* remove allredy printed lines to reduce memory usage */
                scols_table_remove_lines(table);
                mnt_reset_table(tb_new);
 
index e6189d4b77bb68453d985a856ca47287e6ca19a2..4201e4335a23352e998de1d0be7efdf0cfa3de35 100644 (file)
@@ -905,6 +905,11 @@ static void logger_command_line(const struct logger_ctl *ctl, char **argv)
 
 static void logger_stdin(struct logger_ctl *ctl)
 {
+       /* note: we re-generate the the syslog header for each log message to
+        * update header timestamps and to reflect possible priority changes.
+        * The initial header is generated by logger_open().
+        */
+       int has_header = 1;
        int default_priority = ctl->pri;
        int last_pri = default_priority;
        size_t max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
@@ -935,7 +940,7 @@ static void logger_stdin(struct logger_ctl *ctl)
                                        ctl->pri = default_priority;
 
                                if (ctl->pri != last_pri) {
-                                       generate_syslog_header(ctl);
+                                       has_header = 0;
                                        max_usrmsg_size = ctl->max_message_size - strlen(ctl->hdr);
                                        last_pri = ctl->pri;
                                }
@@ -950,8 +955,12 @@ static void logger_stdin(struct logger_ctl *ctl)
                }
                buf[i] = '\0';
 
-               if (i > 0 || !ctl->skip_empty_lines)
+               if (i > 0 || !ctl->skip_empty_lines) {
+                       if (!has_header)
+                               generate_syslog_header(ctl);
                        write_output(ctl, buf);
+                       has_header = 0;
+               }
 
                if (c == '\n')  /* discard line terminator */
                        c = getchar();
index 030be572ddcb9b3f0bca06b8c0b5914408239170..363d6e1df3aff3c6be81be80a669ab388b8a9e3c 100644 (file)
@@ -168,17 +168,21 @@ static const char *get_policy_name(int policy)
        case SCHED_OTHER:
                return "SCHED_OTHER";
        case SCHED_FIFO:
+#ifdef SCHED_RESET_ON_FORK
        case SCHED_FIFO | SCHED_RESET_ON_FORK:
+#endif
                return "SCHED_FIFO";
 #ifdef SCHED_IDLE
        case SCHED_IDLE:
                return "SCHED_IDLE";
 #endif
        case SCHED_RR:
+#ifdef SCHED_RESET_ON_FORK
+       case SCHED_RR | SCHED_RESET_ON_FORK:
+#endif
                return "SCHED_RR";
 #ifdef SCHED_BATCH
        case SCHED_BATCH:
-       case SCHED_RR | SCHED_RESET_ON_FORK:
                return "SCHED_BATCH";
 #endif
 #ifdef SCHED_DEADLINE
index 71a0a3676c4ea3c57426c99bc559f9f78ff2e757..264f1396980994e394a44be5ca6d00aaf54a26e5 100644 (file)
@@ -62,7 +62,9 @@ by bind mount.
 .TP
 .BR \-m , " \-\-mount"[=\fIfile\fP]
 Unshare the mount namespace. If \fIfile\fP is specified then persistent namespace is created
-by bind mount.
+by bind mount. Note that \fIfile\fP has to be located on filesystem with
+propagation flag set to \fBprivate\fP. Use command \fBfindmnt -o+PROPAGATION\fP
+if not sure about the current setting. See also examples below.
 .TP
 .BR \-n , " \-\-net"[=\fIfile\fP]
 Unshare the network namespace. If \fIfile\fP is specified then persistent namespace is created
@@ -153,6 +155,21 @@ FOO
 .br
 Establish a persistent UTS namespace, modify hostname. The namespace maybe later entered
 by nsenter. The namespace is destroyed by umount the bind reference.
+
+.TP
+.TQ
+.B # mount --bind /root/namespaces /root/namespaces
+.TQ
+.B # mount --make-private /root/namespaces
+.TQ
+.B # touch /root/namespaces/mnt
+.TQ
+.B # unshare --mount=/root/namespaces/mnt
+.br
+Establish a persistent mount namespace referenced by the bind mount
+/root/namespaces/mnt. This example provides portable solution, because it makes
+sure that the bind mount is created on shared filesystem.
+
 .SH SEE ALSO
 .BR unshare (2),
 .BR clone (2),