From 9a1a98220697f922a4c0d8460b899987ad0e1c61 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 31 May 2019 13:13:10 +0200 Subject: su: More descriptive error message on malformed user entry With users coming from LDAP, it is often the case that the entry in LDAP does not contain one or more attributes required by su or, because of misconfigured access control rights, the attribute might not be readable by the LDAP client. In that case, su just tells the user that the user does not exist. It might be more user-friendly to tell the user to check the user entry for all required fields. --- login-utils/su-common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/login-utils/su-common.c b/login-utils/su-common.c index caabe23a6..4d91b22e4 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -1446,7 +1446,9 @@ int su_main(int argc, char **argv, int mode) || !su->pwd->pw_passwd || !su->pwd->pw_name || !*su->pwd->pw_name || !su->pwd->pw_dir || !*su->pwd->pw_dir) - errx(EXIT_FAILURE, _("user %s does not exist"), su->new_user); + errx(EXIT_FAILURE, + _("user %s does not exist or the user entry does not " + "contain all the required fields"), su->new_user); su->new_user = su->pwd->pw_name; su->old_user = xgetlogin(); -- cgit v1.2.3-55-g7522 From 0c93519e78018202052fff6cfb5c0a98eb587ae9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 17 Jun 2019 12:55:25 +0200 Subject: docs: we have 2019 already Signed-off-by: Karel Zak --- NEWS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 1ae6216c6..a17abe0e5 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,12 @@ -util-linux 2.34: Jun 14 2018 +util-linux 2.34: Jun 14 2019 * see Documentation/releases/v2.34-ReleaseNotes or the complete changelog at https://www.kernel.org/pub/linux/utils/util-linux/v2.34/v2.34-ChangeLog -util-linux 2.34-rc2: May 30 2018 +util-linux 2.34-rc2: May 30 2019 * see Documentation/releases/v2.34-ReleaseNotes or the complete changelog at https://www.kernel.org/pub/linux/utils/util-linux/v2.34/v2.34-rc2-ChangeLog -util-linux 2.34-rc1: Apr 30 2018 +util-linux 2.34-rc1: Apr 30 2019 * see Documentation/releases/v2.34-ReleaseNotes or the complete changelog at https://www.kernel.org/pub/linux/utils/util-linux/v2.34/v2.34-rc1-ChangeLog -- cgit v1.2.3-55-g7522 From cf3b6b71ebb1f3da975ad12d95a6fa3a15591e63 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 6 Jun 2019 14:05:26 +0200 Subject: lscpu: add a new columns to --cache References: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu Signed-off-by: Karel Zak --- sys-utils/lscpu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- sys-utils/lscpu.h | 9 ++++++++- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 0e775805e..7411994fa 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -178,6 +178,11 @@ enum { COL_CACHE_ONESIZE, COL_CACHE_TYPE, COL_CACHE_WAYS, + COL_CACHE_ALLOCPOL, + COL_CACHE_WRITEPOL, + COL_CACHE_PHYLINE, + COL_CACHE_SETS, + COL_CACHE_COHERENCYSIZE }; @@ -215,7 +220,12 @@ static struct lscpu_coldesc coldescs_cache[] = [COL_CACHE_NAME] = { "NAME", N_("cache name") }, [COL_CACHE_ONESIZE] = { "ONE-SIZE", N_("size of one cache"), SCOLS_FL_RIGHT }, [COL_CACHE_TYPE] = { "TYPE", N_("cache type") }, - [COL_CACHE_WAYS] = { "WAYS", N_("ways of associativity"), SCOLS_FL_RIGHT } + [COL_CACHE_WAYS] = { "WAYS", N_("ways of associativity"), SCOLS_FL_RIGHT }, + [COL_CACHE_ALLOCPOL] = { "ALLOC-POLICY", N_("allocation policy") }, + [COL_CACHE_WRITEPOL] = { "WRITE-POLICY", N_("write policy") }, + [COL_CACHE_PHYLINE] = { "PHY-LINE", N_("number of physical cache line per cache t"), SCOLS_FL_RIGHT }, + [COL_CACHE_SETS] = { "SETS", N_("number of sets in the cache; set lines has the same cache index"), SCOLS_FL_RIGHT }, + [COL_CACHE_COHERENCYSIZE] = { "COHERENCY-SIZE", N_("minimum amount of data in bytes transferred from memory to cache"), SCOLS_FL_RIGHT } }; @@ -1354,9 +1364,19 @@ read_cache(struct lscpu_desc *desc, int idx) ca->name = xstrdup(buf); - /* cache ways */ - ul_path_readf_s32(desc->syscpu, &ca->ways, + ul_path_readf_u32(desc->syscpu, &ca->ways_of_associativity, "cpu%d/cache/index%d/ways_of_associativity", num, i); + ul_path_readf_u32(desc->syscpu, &ca->physical_line_partition, + "cpu%d/cache/index%d/physical_line_partition", num, i); + ul_path_readf_u32(desc->syscpu, &ca->number_of_sets, + "cpu%d/cache/index%d/number_of_sets", num, i); + ul_path_readf_u32(desc->syscpu, &ca->coherency_line_size, + "cpu%d/cache/index%d/coherency_line_size", num, i); + + ul_path_readf_string(desc->syscpu, &ca->allocation_policy, + "cpu%d/cache/index%d/allocation_policy", num, i); + ul_path_readf_string(desc->syscpu, &ca->write_policy, + "cpu%d/cache/index%d/write_policy", num, i); /* cache size */ if (ul_path_readf_buffer(desc->syscpu, buf, sizeof(buf), @@ -1682,9 +1702,10 @@ print_caches_readable(struct lscpu_desc *desc, int cols[], int ncols, break; } case COL_CACHE_WAYS: - if (ca->ways) - xasprintf(&data, "%d", ca->ways); + if (ca->ways_of_associativity) + xasprintf(&data, "%u", ca->ways_of_associativity); break; + case COL_CACHE_TYPE: if (ca->type) data = xstrdup(ca->type); @@ -1693,6 +1714,26 @@ print_caches_readable(struct lscpu_desc *desc, int cols[], int ncols, if (ca->level) xasprintf(&data, "%d", ca->level); break; + case COL_CACHE_ALLOCPOL: + if (ca->allocation_policy) + data = xstrdup(ca->allocation_policy); + break; + case COL_CACHE_WRITEPOL: + if (ca->write_policy) + data = xstrdup(ca->write_policy); + break; + case COL_CACHE_PHYLINE: + if (ca->physical_line_partition) + xasprintf(&data, "%u", ca->physical_line_partition); + break; + case COL_CACHE_SETS: + if (ca->number_of_sets) + xasprintf(&data, "%u", ca->number_of_sets); + break; + case COL_CACHE_COHERENCYSIZE: + if (ca->coherency_line_size) + xasprintf(&data, "%u", ca->coherency_line_size); + break; } if (data && scols_line_refer_data(line, c, data)) @@ -2414,6 +2455,9 @@ int main(int argc, char *argv[]) columns[ncolumns++] = COL_CACHE_WAYS; columns[ncolumns++] = COL_CACHE_TYPE; columns[ncolumns++] = COL_CACHE_LEVEL; + columns[ncolumns++] = COL_CACHE_SETS; + columns[ncolumns++] = COL_CACHE_PHYLINE; + columns[ncolumns++] = COL_CACHE_COHERENCYSIZE; } print_caches_readable(desc, columns, ncolumns, mod); break; diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index 56c97e2e8..5bbdb348e 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -49,10 +49,17 @@ enum { struct cpu_cache { char *name; char *type; + char *allocation_policy; + char *write_policy; + int level; - int ways; uint64_t size; + unsigned int ways_of_associativity; + unsigned int physical_line_partition; + unsigned int number_of_sets; + unsigned int coherency_line_size; + int nsharedmaps; cpu_set_t **sharedmaps; }; -- cgit v1.2.3-55-g7522 From bfdca6d7287bedb8c40c9750fc3523544bbf5022 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 7 Jun 2019 12:20:53 +0200 Subject: libfdisk: add fdisk_script_set_table() This small change improves possibility to modify by script described PT and use script API in another tools as primary way to create partitions. All you need is to compose script by fdisk_script_set_header() and fdisk_script_set_table() and than apply by fdisk_apply_script(). Requested-by: Lennart Poettering Signed-off-by: Karel Zak --- libfdisk/docs/libfdisk-sections.txt | 1 + libfdisk/src/libfdisk.h.in | 1 + libfdisk/src/libfdisk.sym | 4 ++ libfdisk/src/script.c | 76 ++++++++++++++++++++++++++++++------- 4 files changed, 69 insertions(+), 13 deletions(-) diff --git a/libfdisk/docs/libfdisk-sections.txt b/libfdisk/docs/libfdisk-sections.txt index f6675fe46..d0d362f60 100644 --- a/libfdisk/docs/libfdisk-sections.txt +++ b/libfdisk/docs/libfdisk-sections.txt @@ -132,6 +132,7 @@ fdisk_ref_script fdisk_script_enable_json fdisk_script_get_header fdisk_script_get_nlines +fdisk_script_set_table fdisk_script_get_table fdisk_script_has_force_label fdisk_script_read_context diff --git a/libfdisk/src/libfdisk.h.in b/libfdisk/src/libfdisk.h.in index 47e778a67..69c6fd820 100644 --- a/libfdisk/src/libfdisk.h.in +++ b/libfdisk/src/libfdisk.h.in @@ -757,6 +757,7 @@ void fdisk_unref_script(struct fdisk_script *dp); const char *fdisk_script_get_header(struct fdisk_script *dp, const char *name); int fdisk_script_set_header(struct fdisk_script *dp, const char *name, const char *data); struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp); +int fdisk_script_set_table(struct fdisk_script *dp, struct fdisk_table *tb); int fdisk_script_get_nlines(struct fdisk_script *dp); int fdisk_script_has_force_label(struct fdisk_script *dp); diff --git a/libfdisk/src/libfdisk.sym b/libfdisk/src/libfdisk.sym index 8f80d7964..8ce943acc 100644 --- a/libfdisk/src/libfdisk.sym +++ b/libfdisk/src/libfdisk.sym @@ -303,3 +303,7 @@ FDISK_2.33 { fdisk_get_devmodel; fdisk_get_devno; } FDISK_2.32; + +FDISK_2.35 { + fdisk_script_set_table; +} FDISK_2.33; diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 66be4f08c..0a165aad4 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -7,13 +7,33 @@ /** * SECTION: script * @title: Script - * @short_description: text based sfdisk compatible description of partition table + * @short_description: complex way to create and dump partition table * - * The libfdisk scripts are based on original sfdisk script (dumps). Each + * This interface allows to compose in-memory partition table with all details, + * write all partition table description to human readable text file, read it + * from the file, and apply the script to on-disk label. + * + * The libfdisk scripts are based on original sfdisk script (dumps). Each * script has two parts: script headers and partition table entries - * (partitions). + * (partitions). The script is possible to dump in JSON too (read JSON is not + * implemented yet). * * For more details about script format see sfdisk man page. + * + * There are four ways how to build the script: + * + * - read the current on-disk partition table by fdisk_script_read_context()) + * - read it from text file by fdisk_script_read_file() + * - read it interactively from user by fdisk_script_read_line() and fdisk_script_set_fgets() + * - manually in code by fdisk_script_set_header() and fdisk_script_set_table() + * + * The read functions fdisk_script_read_context() and fdisk_script_read_file() + * creates always a new script partition table. The table (see + * fdisk_script_get_table()) is possible to modify by standard + * fdisk_table_...() functions and than apply by fdisk_apply_script(). + * + * Note that script API is fully non-interactive and forces libfdisk to not use + * standard dialog driven partitioning as we have in fdisk(8). */ /* script header (e.g. unit: sectors) */ @@ -76,12 +96,6 @@ struct fdisk_script *fdisk_new_script(struct fdisk_context *cxt) dp->cxt = cxt; fdisk_ref_context(cxt); - dp->table = fdisk_new_table(); - if (!dp->table) { - fdisk_unref_script(dp); - return NULL; - } - INIT_LIST_HEAD(&dp->headers); return dp; } @@ -317,11 +331,11 @@ int fdisk_script_set_header(struct fdisk_script *dp, * fdisk_script_get_table: * @dp: script * - * The table (container with partitions) is possible to create by - * fdisk_script_read_context() or fdisk_script_read_file(), otherwise - * this function returns NULL. + * The table represents partitions holded by the script. The table is possible to + * fill by fdisk_script_read_context() or fdisk_script_read_file(). All the "read" + * functions reset the table. See also fdisk_script_set_table(). * - * Returns: NULL or script. + * Returns: NULL or script table. */ struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp) { @@ -329,6 +343,40 @@ struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp) return dp ? dp->table : NULL; } +/** + * fdisk_script_set_table: + * @dp: script + * @tb: table + * + * Replaces table used by script and creates a new reference to @tb. This + * function allows to generate a new script table independently on the current + * context and without any file reading. + * + * This is useful for example to create partition table with the same basic + * settings (e.g. label-id, ...) but with different partitions -- just call + * fdisk_script_read_context() to get current settings and than + * fdisk_script_set_table() to set a different layout. + * + * If @tb is NULL than the current script table is unreferenced. + * + * Note that script read_ functions (e.g. fdisk_script_read_context()) create + * always a new script table. + * + * Returns: 0 on success, <0 on error + */ +int fdisk_script_set_table(struct fdisk_script *dp, struct fdisk_table *tb) +{ + if (!dp) + return -EINVAL; + + fdisk_ref_table(tb); + fdisk_unref_table(dp->table); + dp->table = tb; + + DBG(SCRIPT, ul_debugobj(dp, "table replaced")); + return 0; +} + static struct fdisk_label *script_get_label(struct fdisk_script *dp) { assert(dp); @@ -911,6 +959,7 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) assert(dp); assert(s); + assert(dp->table); DBG(SCRIPT, ul_debugobj(dp, " parse script line: '%s'", s)); @@ -1106,6 +1155,7 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) assert(dp); assert(s); + assert(dp->table); pa = fdisk_new_partition(); if (!pa) -- cgit v1.2.3-55-g7522 From 9335bfc84503dbb3993a9a07e9a001dd987468cb Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 7 Jun 2019 13:21:23 +0200 Subject: libfdisk: (docs) add notes about fdisk_enable_wipe() Signed-off-by: Karel Zak --- libfdisk/src/context.c | 31 ++++++++++++++++++++++--------- libfdisk/src/label.c | 3 ++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 56ebb6c1e..1171f28a8 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -17,13 +17,13 @@ * * The library distinguish between three types of partitioning objects. * - * on-disk data + * on-disk lebel data * - disk label specific * - probed and read by disklabel drivers when assign device to the context * or when switch to another disk label type * - only fdisk_write_disklabel() modify on-disk data * - * in-memory data + * in-memory label data * - generic data and disklabel specific data stored in struct fdisk_label * - all partitioning operations are based on in-memory data only * @@ -31,8 +31,12 @@ * - provides abstraction to present partitions to users * - fdisk_partition is possible to gather to fdisk_table container * - used as unified template for new partitions + * - used (with fdisk_table) in fdisk scripts * - the struct fdisk_partition is always completely independent object and * any change to the object has no effect to in-memory (or on-disk) label data + * + * Don't forget to inform kernel about changes by fdisk_reread_partition_table() + * or more smart fdisk_reread_changes(). */ /** @@ -574,14 +578,23 @@ static void reset_context(struct fdisk_context *cxt) * @fname: path to the device to be handled * @readonly: how to open the device * - * Open the device, discovery topology, geometry, detect disklabel and switch - * the current label driver to reflect the probing result. + * Open the device, discovery topology, geometry, detect disklabel, check for + * collisions and switch the current label driver to reflect the probing + * result. + * + * If in standard mode (!= non-listonly mode) than also detects for collisions. + * The result is accessible by fdisk_get_collision() and + * fdisk_is_ptcollision(). The collision (e.g. old obsolete PT) may be removed + * by fdisk_enable_wipe(). Note that new PT and old PT may be on different + * locations. + * + * Note that this function resets all generic setting in context. * - * Note that this function resets all generic setting in context. If the @cxt - * is nested context then the device is assigned to the parental context and - * necessary properties are copied to the @cxt. The change is propagated in - * child->parent direction only. It's impossible to use a different device for - * primary and nested contexts. + * If the @cxt is nested context (necessary for example to edit BSD or PMBR) + * then the device is assigned to the parental context and necessary properties + * are copied to the @cxt. The change is propagated in child->parent direction + * only. It's impossible to use a different device for primary and nested + * contexts. * * Returns: 0 on success, < 0 on error. */ diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 2a11acad6..68f73f143 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -247,7 +247,8 @@ const struct fdisk_field *fdisk_label_get_field_by_name( * fdisk_write_disklabel: * @cxt: fdisk context * - * Write in-memory changes to disk. Be careful! + * This function wipes the device (if eanbled by fdisk_enable_wipe() and than + * it writes in-memory changes to disk. Be careful! * * Returns: 0 on success, otherwise, a corresponding error. */ -- cgit v1.2.3-55-g7522 From 73ec5e164c8e67bb2621c58fcccbdef54da8e1ca Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 10 Jun 2019 11:43:56 +0200 Subject: libfdisk: fix fdisk_script_get_table() Make sure we never return NULL and we reuse the table in code. Signed-off-by: Karel Zak --- libfdisk/src/script.c | 32 +++++++++++++++++++------------- libfdisk/src/table.c | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 0a165aad4..dbbd53eaf 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -162,8 +162,9 @@ static void fdisk_reset_script(struct fdisk_script *dp) assert(dp); DBG(SCRIPT, ul_debugobj(dp, "reset")); - fdisk_unref_table(dp->table); - dp->table = NULL; + + if (dp->table) + fdisk_reset_table(dp->table); while (!list_empty(&dp->headers)) { struct fdisk_scriptheader *fi = list_entry(dp->headers.next, @@ -333,14 +334,22 @@ int fdisk_script_set_header(struct fdisk_script *dp, * * The table represents partitions holded by the script. The table is possible to * fill by fdisk_script_read_context() or fdisk_script_read_file(). All the "read" - * functions reset the table. See also fdisk_script_set_table(). + * functions remove old partitions from the table. See also fdisk_script_set_table(). * * Returns: NULL or script table. */ struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp) { assert(dp); - return dp ? dp->table : NULL; + + if (!dp->table) + /* + * Make sure user has access to the same table as script. If + * there is no table than create a new and reuse it later. + */ + dp->table = fdisk_new_table(); + + return dp->table; } /** @@ -448,7 +457,7 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt if (!lb) return -EINVAL; - /* allocate and fill new table */ + /* allocate (if not yet) and fill table */ rc = fdisk_get_partitions(cxt, &dp->table); if (rc) return rc; @@ -590,7 +599,7 @@ static int write_file_json(struct fdisk_script *dp, FILE *f) } - if (!dp->table) { + if (!dp->table || fdisk_table_is_empty(dp->table)) { DBG(SCRIPT, ul_debugobj(dp, "script table empty")); goto done; } @@ -699,7 +708,7 @@ static int write_file_sfdisk(struct fdisk_script *dp, FILE *f) devname = fi->data; } - if (!dp->table) { + if (!dp->table || fdisk_table_is_empty(dp->table)) { DBG(SCRIPT, ul_debugobj(dp, "script table empty")); return 0; } @@ -1290,11 +1299,8 @@ static int fdisk_script_read_buffer(struct fdisk_script *dp, char *s) if (!s || !*s) return 0; /* nothing baby, ignore */ - if (!dp->table) { - dp->table = fdisk_new_table(); - if (!dp->table) - return -ENOMEM; - } + if (!dp->table && fdisk_script_get_table(dp) == NULL) + return -ENOMEM; /* parse header lines only if no partition specified yet */ if (fdisk_table_is_empty(dp->table) && is_header_line(s)) @@ -1619,7 +1625,7 @@ static int test_stdin(struct fdisk_test *ts, int argc, char *argv[]) printf(", , , \n"); do { struct fdisk_partition *pa; - size_t n = fdisk_table_get_nents(dp->table); + size_t n = dp->table ? fdisk_table_get_nents(dp->table) : 0; printf(" #%zu :\n", n + 1); rc = fdisk_script_read_line(dp, stdin, buf, sizeof(buf)); diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index 1f9d5a28a..8a3a935af 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -303,7 +303,7 @@ int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_partition * @tb: returns table * * This function adds partitions from disklabel to @table, it allocates a new - * table if if @table points to NULL. + * table if @table points to NULL. * * Returns: 0 on success, otherwise, a corresponding error. */ -- cgit v1.2.3-55-g7522 From 25b7045e5db032df5354c0749cb454a20b89c522 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 13 Jun 2019 13:22:32 +0200 Subject: misc: replaces atexit(close_stdout) with new close_stdout_atexit() Signed-off-by: Karel Zak --- sys-utils/fsfreeze.c | 2 +- sys-utils/ldattach.c | 2 +- sys-utils/losetup.c | 2 +- sys-utils/lscpu.c | 2 +- sys-utils/lsipc.c | 2 +- text-utils/colrm.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sys-utils/fsfreeze.c b/sys-utils/fsfreeze.c index 4da1a6fa3..6035a1010 100644 --- a/sys-utils/fsfreeze.c +++ b/sys-utils/fsfreeze.c @@ -77,7 +77,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "hfuV", longopts, NULL)) != -1) { diff --git a/sys-utils/ldattach.c b/sys-utils/ldattach.c index 3019e5a9f..c2d2f8397 100644 --- a/sys-utils/ldattach.c +++ b/sys-utils/ldattach.c @@ -314,7 +314,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* parse options */ if (argc == 0) diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index d862fd8e7..27884df73 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -642,7 +642,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (loopcxt_init(&lc, 0)) err(EXIT_FAILURE, _("failed to initialize loopcxt")); diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 7411994fa..4f1ab47e9 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -2296,7 +2296,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "aBbC::ce::hJp::s:xyV", longopts, NULL)) != -1) { diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index 5ba9cd7bf..5a1a3d7ac 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -1137,7 +1137,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); ctl->time_mode = 0; diff --git a/text-utils/colrm.c b/text-utils/colrm.c index d0ef2eb66..f9dfd5938 100644 --- a/text-utils/colrm.c +++ b/text-utils/colrm.c @@ -166,7 +166,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((opt = getopt_long(argc, argv, "bfhl:pxVH", longopts, -- cgit v1.2.3-55-g7522 From 52aa1a661110e235a9eff57bb4db88aa8412dac1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 13 Jun 2019 13:25:44 +0200 Subject: include/closestream: avoid close more than once Signed-off-by: Karel Zak --- include/closestream.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/closestream.h b/include/closestream.h index 6a62e48e8..83df1ee7d 100644 --- a/include/closestream.h +++ b/include/closestream.h @@ -39,7 +39,7 @@ close_stream(FILE * stream) static inline void close_stdout(void) { - if (close_stream(stdout) != 0 && !(errno == EPIPE)) { + if (stdout && close_stream(stdout) != 0 && !(errno == EPIPE)) { if (errno) warn(_("write error")); else @@ -47,8 +47,11 @@ close_stdout(void) _exit(CLOSE_EXIT_CODE); } - if (close_stream(stderr) != 0) + if (stderr && close_stream(stderr) != 0) _exit(CLOSE_EXIT_CODE); + + stdout = NULL; + stderr = NULL; } static inline void -- cgit v1.2.3-55-g7522 From e4d511d40c492928b36286b2d64927ffa9382680 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 31 May 2019 14:06:04 +0200 Subject: wdctl: rename watch dog info struct Signed-off-by: Karel Zak --- sys-utils/wdctl.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index 4574e10da..00f4bd774 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -108,8 +108,8 @@ static struct colinfo infos[] = { static int columns[ARRAY_SIZE(infos) * 2]; static int ncolumns; -struct wdinfo { - char *device; +struct wd_device { + char *devpath; int timeout; int timeleft; @@ -204,7 +204,7 @@ static void __attribute__((__noreturn__)) usage(void) exit(EXIT_SUCCESS); } -static void add_flag_line(struct libscols_table *table, struct wdinfo *wd, const struct wdflag *fl) +static void add_flag_line(struct libscols_table *table, struct wd_device *wd, const struct wdflag *fl) { int i; struct libscols_line *line; @@ -232,7 +232,7 @@ static void add_flag_line(struct libscols_table *table, struct wdinfo *wd, const str = wd->bstatus & fl->flag ? "1" : "0"; break; case COL_DEVICE: - str = wd->device; + str = wd->devpath; break; default: break; @@ -245,7 +245,7 @@ static void add_flag_line(struct libscols_table *table, struct wdinfo *wd, const } } -static int show_flags(struct wdinfo *wd, uint32_t wanted) +static int show_flags(struct wd_device *wd, uint32_t wanted) { size_t i; int rc = -1; @@ -287,7 +287,7 @@ static int show_flags(struct wdinfo *wd, uint32_t wanted) } if (flags) - warnx(_("%s: unknown flags 0x%x\n"), wd->device, flags); + warnx(_("%s: unknown flags 0x%x\n"), wd->devpath, flags); scols_print_table(table); rc = 0; @@ -301,25 +301,25 @@ done: * * Don't use err() or exit() here! */ -static int set_watchdog(struct wdinfo *wd, int timeout) +static int set_watchdog(struct wd_device *wd, int timeout) { int fd; sigset_t sigs, oldsigs; int rc = 0; - assert(wd->device); + assert(wd->devpath); sigemptyset(&oldsigs); sigfillset(&sigs); sigprocmask(SIG_BLOCK, &sigs, &oldsigs); - fd = open(wd->device, O_WRONLY|O_CLOEXEC); + fd = open(wd->devpath, O_WRONLY|O_CLOEXEC); if (fd < 0) { if (errno == EBUSY) warnx(_("%s: watchdog already in use, terminating."), - wd->device); - warn(_("cannot open %s"), wd->device); + wd->devpath); + warn(_("cannot open %s"), wd->devpath); return -1; } @@ -331,7 +331,7 @@ static int set_watchdog(struct wdinfo *wd, int timeout) if (write(fd, &v, 1) >= 0) break; if (errno != EINTR) { - warn(_("%s: failed to disarm watchdog"), wd->device); + warn(_("%s: failed to disarm watchdog"), wd->devpath); break; } /* Let's try hard, since if we don't get this right @@ -340,7 +340,7 @@ static int set_watchdog(struct wdinfo *wd, int timeout) if (ioctl(fd, WDIOC_SETTIMEOUT, &timeout) != 0) { rc = errno; - warn(_("cannot set timeout for %s"), wd->device); + warn(_("cannot set timeout for %s"), wd->devpath); } if (close(fd)) @@ -358,29 +358,29 @@ static int set_watchdog(struct wdinfo *wd, int timeout) * * Don't use err() or exit() here! */ -static int read_watchdog(struct wdinfo *wd) +static int read_watchdog(struct wd_device *wd) { int fd; sigset_t sigs, oldsigs; - assert(wd->device); + assert(wd->devpath); sigemptyset(&oldsigs); sigfillset(&sigs); sigprocmask(SIG_BLOCK, &sigs, &oldsigs); - fd = open(wd->device, O_WRONLY|O_CLOEXEC); + fd = open(wd->devpath, O_WRONLY|O_CLOEXEC); if (fd < 0) { if (errno == EBUSY) warnx(_("%s: watchdog already in use, terminating."), - wd->device); - warn(_("cannot open %s"), wd->device); + wd->devpath); + warn(_("cannot open %s"), wd->devpath); return -1; } if (ioctl(fd, WDIOC_GETSUPPORT, &wd->ident) < 0) - warn(_("%s: failed to get information about watchdog"), wd->device); + warn(_("%s: failed to get information about watchdog"), wd->devpath); else { ioctl(fd, WDIOC_GETSTATUS, &wd->status); ioctl(fd, WDIOC_GETBOOTSTATUS, &wd->bstatus); @@ -401,7 +401,7 @@ static int read_watchdog(struct wdinfo *wd) if (write(fd, &v, 1) >= 0) break; if (errno != EINTR) { - warn(_("%s: failed to disarm watchdog"), wd->device); + warn(_("%s: failed to disarm watchdog"), wd->devpath); break; } /* Let's try hard, since if we don't get this right @@ -415,10 +415,10 @@ static int read_watchdog(struct wdinfo *wd) return 0; } -static void print_oneline(struct wdinfo *wd, uint32_t wanted, +static void print_oneline(struct wd_device *wd, uint32_t wanted, int noident, int notimeouts, int noflags) { - printf("%s:", wd->device); + printf("%s:", wd->devpath); if (!noident) { printf(" VERSION=\"%x\"", wd->ident.firmware_version); @@ -459,7 +459,7 @@ static void print_oneline(struct wdinfo *wd, uint32_t wanted, fputc('\n', stdout); } -static void show_timeouts(struct wdinfo *wd) +static void show_timeouts(struct wd_device *wd) { if (wd->has_timeout) printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeout), @@ -474,7 +474,7 @@ static void show_timeouts(struct wdinfo *wd) int main(int argc, char *argv[]) { - struct wdinfo wd; + struct wd_device wd; int c, res = EXIT_SUCCESS, count = 0; char noflags = 0, noident = 0, notimeouts = 0, oneline = 0; uint32_t wanted = 0; @@ -573,9 +573,9 @@ int main(int argc, char *argv[]) memset(&wd, 0, sizeof(wd)); if (optind == argc) - wd.device = _PATH_WATCHDOG_DEV; + wd.devpath = _PATH_WATCHDOG_DEV; else - wd.device = argv[optind++]; + wd.devpath = argv[optind++]; if (count) fputc('\n', stdout); @@ -601,7 +601,7 @@ int main(int argc, char *argv[]) /* pretty output */ if (!noident) { - printf("%-15s%s\n", _("Device:"), wd.device); + printf("%-15s%s\n", _("Device:"), wd.devpath); printf("%-15s%s [%s %x]\n", _("Identity:"), wd.ident.identity, -- cgit v1.2.3-55-g7522 From a599d1375e80d061dcc6b5fad3f0ffaef55d831d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 31 May 2019 14:18:19 +0200 Subject: wdctl: add control struct * remove global variables * keep all together Signed-off-by: Karel Zak --- sys-utils/wdctl.c | 58 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index 00f4bd774..6b04acd8b 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -59,10 +59,6 @@ other external alarm not a reboot */ #endif -/* basic output flags */ -static int no_headings; -static int raw; - struct wdflag { uint32_t flag; const char *name; @@ -125,6 +121,15 @@ struct wd_device { has_pretimeout : 1; }; +struct wd_control { + unsigned int show_oneline : 1, + show_raw : 1, + hide_headings : 1, + hide_flags : 1, + hide_ident : 1, + hide_timeouts : 1; +}; + /* converts flag name to flag bit */ static long name2bit(const char *name, size_t namesz) { @@ -245,7 +250,7 @@ static void add_flag_line(struct libscols_table *table, struct wd_device *wd, co } } -static int show_flags(struct wd_device *wd, uint32_t wanted) +static int show_flags(struct wd_control *ctl, struct wd_device *wd, uint32_t wanted) { size_t i; int rc = -1; @@ -260,8 +265,8 @@ static int show_flags(struct wd_device *wd, uint32_t wanted) warn(_("failed to allocate output table")); return -1; } - scols_table_enable_raw(table, raw); - scols_table_enable_noheadings(table, no_headings); + scols_table_enable_raw(table, ctl->show_raw); + scols_table_enable_noheadings(table, ctl->hide_headings); /* define columns */ for (i = 0; i < (size_t) ncolumns; i++) { @@ -415,18 +420,17 @@ static int read_watchdog(struct wd_device *wd) return 0; } -static void print_oneline(struct wd_device *wd, uint32_t wanted, - int noident, int notimeouts, int noflags) +static void print_oneline(struct wd_control *ctl, struct wd_device *wd, uint32_t wanted) { printf("%s:", wd->devpath); - if (!noident) { + if (!ctl->hide_ident) { printf(" VERSION=\"%x\"", wd->ident.firmware_version); printf(" IDENTITY="); fputs_quoted((char *) wd->ident.identity, stdout); } - if (!notimeouts) { + if (!ctl->hide_timeouts) { if (wd->has_timeout) printf(" TIMEOUT=\"%i\"", wd->timeout); if (wd->has_pretimeout) @@ -435,7 +439,7 @@ static void print_oneline(struct wd_device *wd, uint32_t wanted, printf(" TIMELEFT=\"%i\"", wd->timeleft); } - if (!noflags) { + if (!ctl->hide_flags) { size_t i; uint32_t flags = wd->ident.options; @@ -475,8 +479,8 @@ static void show_timeouts(struct wd_device *wd) int main(int argc, char *argv[]) { struct wd_device wd; + struct wd_control ctl = { .hide_headings = 0 }; int c, res = EXIT_SUCCESS, count = 0; - char noflags = 0, noident = 0, notimeouts = 0, oneline = 0; uint32_t wanted = 0; int timeout = 0; @@ -528,26 +532,26 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; break; case 'F': - noflags = 1; + ctl.hide_flags = 1; break; case 'I': - noident = 1; + ctl.hide_ident = 1; break; case 'T': - notimeouts = 1; + ctl.hide_timeouts = 1; break; case 'n': - no_headings = 1; + ctl.hide_headings = 1; break; case 'r': - raw = 1; + ctl.show_raw = 1; break; case 'O': - oneline = 1; + ctl.show_oneline = 1; break; case 'x': - noident = 1; - notimeouts = 1; + ctl.hide_ident = 1; + ctl.hide_timeouts = 1; break; case 'h': @@ -594,13 +598,13 @@ int main(int argc, char *argv[]) continue; } - if (oneline) { - print_oneline(&wd, wanted, noident, notimeouts, noflags); + if (ctl.show_oneline) { + print_oneline(&ctl, &wd, wanted); continue; } /* pretty output */ - if (!noident) { + if (!ctl.hide_ident) { printf("%-15s%s\n", _("Device:"), wd.devpath); printf("%-15s%s [%s %x]\n", _("Identity:"), @@ -608,10 +612,10 @@ int main(int argc, char *argv[]) _("version"), wd.ident.firmware_version); } - if (!notimeouts) + if (!ctl.hide_timeouts) show_timeouts(&wd); - if (!noflags) - show_flags(&wd, wanted); + if (!ctl.hide_flags) + show_flags(&ctl, &wd, wanted); } while (optind < argc); return res; -- cgit v1.2.3-55-g7522 From 5d628f37b7423c0047136c81aa7ff3b812fcaed9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 31 May 2019 14:25:41 +0200 Subject: wdctl: remove printing from main() Signed-off-by: Karel Zak --- sys-utils/wdctl.c | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index 6b04acd8b..b4f2c6b56 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -420,6 +420,19 @@ static int read_watchdog(struct wd_device *wd) return 0; } +static void show_timeouts(struct wd_device *wd) +{ + if (wd->has_timeout) + printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeout), + _("Timeout:"), wd->timeout); + if (wd->has_pretimeout) + printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->pretimeout), + _("Pre-timeout:"), wd->pretimeout); + if (wd->has_timeleft) + printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeleft), + _("Timeleft:"), wd->timeleft); +} + static void print_oneline(struct wd_control *ctl, struct wd_device *wd, uint32_t wanted) { printf("%s:", wd->devpath); @@ -463,17 +476,28 @@ static void print_oneline(struct wd_control *ctl, struct wd_device *wd, uint32_t fputc('\n', stdout); } -static void show_timeouts(struct wd_device *wd) +static void print_device(struct wd_control *ctl, struct wd_device *wd, uint32_t wanted) { - if (wd->has_timeout) - printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeout), - _("Timeout:"), wd->timeout); - if (wd->has_pretimeout) - printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->pretimeout), - _("Pre-timeout:"), wd->pretimeout); - if (wd->has_timeleft) - printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeleft), - _("Timeleft:"), wd->timeleft); + /* NAME=value one line output */ + if (ctl->show_oneline) { + print_oneline(ctl, wd, wanted); + return; + } + + /* pretty output */ + if (!ctl->hide_ident) { + printf("%-15s%s\n", _("Device:"), wd->devpath); + printf("%-15s%s [%s %x]\n", + _("Identity:"), + wd->ident.identity, + _("version"), + wd->ident.firmware_version); + } + if (!ctl->hide_timeouts) + show_timeouts(wd); + + if (!ctl->hide_flags) + show_flags(ctl, wd, wanted); } int main(int argc, char *argv[]) @@ -598,24 +622,8 @@ int main(int argc, char *argv[]) continue; } - if (ctl.show_oneline) { - print_oneline(&ctl, &wd, wanted); - continue; - } + print_device(&ctl, &wd, wanted); - /* pretty output */ - if (!ctl.hide_ident) { - printf("%-15s%s\n", _("Device:"), wd.devpath); - printf("%-15s%s [%s %x]\n", - _("Identity:"), - wd.ident.identity, - _("version"), - wd.ident.firmware_version); - } - if (!ctl.hide_timeouts) - show_timeouts(&wd); - if (!ctl.hide_flags) - show_flags(&ctl, &wd, wanted); } while (optind < argc); return res; -- cgit v1.2.3-55-g7522 From 8c8df4214656794b82d4eac5dffe36d3cac389e3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 31 May 2019 14:49:23 +0200 Subject: wdctl: default to /dev/watchdog0 Let's use miscdev /dev/watchdog as fallback only. We need (if possible) cdev /dev/watchdog0 as this device has entry in /sys/class/watchdog. Signed-off-by: Karel Zak --- include/pathnames.h | 3 --- sys-utils/wdctl.c | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/pathnames.h b/include/pathnames.h index ee470ee4b..6f091d5f0 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -167,9 +167,6 @@ /* deprecated */ #define _PATH_RAWDEVCTL_OLD "/dev/rawctl" -/* wdctl path */ -#define _PATH_WATCHDOG_DEV "/dev/watchdog" - /* ipc paths */ #define _PATH_PROC_SYSV_MSG "/proc/sysvipc/msg" #define _PATH_PROC_SYSV_SEM "/proc/sysvipc/sem" diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index b4f2c6b56..772e6b968 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -105,7 +105,7 @@ static int columns[ARRAY_SIZE(infos) * 2]; static int ncolumns; struct wd_device { - char *devpath; + const char *devpath; int timeout; int timeleft; @@ -170,10 +170,32 @@ static struct colinfo *get_column_info(unsigned num) return &infos[ get_column_id(num) ]; } +/* We preffer cdev /dev/watchdog0 as this device has node in + * /sys/class/watchdog/. The old miscdev /dev/watchdog is fallback for old + * systemds only. + */ +static const char *get_default_device(void) +{ + const char **p; + static const char *devs[] = { + "/dev/watchdog0", + "/dev/watchdog", + NULL + }; + + for (p = devs; *p; p++) { + if (access(*p, F_OK) == 0) + return *p; + } + + return NULL; +} + static void __attribute__((__noreturn__)) usage(void) { FILE *out = stdout; size_t i; + const char *dflt = get_default_device(); fputs(USAGE_HEADER, out); fprintf(out, @@ -198,7 +220,10 @@ static void __attribute__((__noreturn__)) usage(void) printf(USAGE_HELP_OPTIONS(24)); fputs(USAGE_SEPARATOR, out); - fprintf(out, _("The default device is %s.\n"), _PATH_WATCHDOG_DEV); + if (dflt) + fprintf(out, _("The default device is %s.\n"), dflt); + else + fprintf(out, _("No default device is available.\n")); fputs(USAGE_COLUMNS, out); for (i = 0; i < ARRAY_SIZE(infos); i++) @@ -507,6 +532,7 @@ int main(int argc, char *argv[]) int c, res = EXIT_SUCCESS, count = 0; uint32_t wanted = 0; int timeout = 0; + const char *dflt_device = NULL; static const struct option long_opts[] = { { "flags", required_argument, NULL, 'f' }, @@ -595,15 +621,18 @@ int main(int argc, char *argv[]) columns[ncolumns++] = COL_BSTATUS; } + /* Device no specified, use default. */ + if (optind == argc) { + dflt_device = get_default_device(); + if (!dflt_device) + err(EXIT_FAILURE, _("No default device is available.")); + } + do { int rc; memset(&wd, 0, sizeof(wd)); - - if (optind == argc) - wd.devpath = _PATH_WATCHDOG_DEV; - else - wd.devpath = argv[optind++]; + wd.devpath = dflt_device ? dflt_device : argv[optind++]; if (count) fputc('\n', stdout); -- cgit v1.2.3-55-g7522 From e3188dd90a4cd51723fefdcea8c3b82a6e7afc29 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 6 Jun 2019 11:09:17 +0200 Subject: lib/path: make sure ul_path_read_buffer() derminate result Signed-off-by: Karel Zak --- lib/path.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/path.c b/lib/path.c index f7fd19592..8dce1da40 100644 --- a/lib/path.c +++ b/lib/path.c @@ -610,9 +610,10 @@ int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char /* Remove tailing newline (usual in sysfs) */ if (rc > 0 && *(buf + rc - 1) == '\n') - --rc; + buf[--rc] = '\0'; + else + buf[rc - 1] = '\0'; - buf[rc] = '\0'; return rc; } -- cgit v1.2.3-55-g7522 From b3dd29d1b878865102c5cb366dd3e814ce043cb9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 6 Jun 2019 11:17:13 +0200 Subject: wdctl; read from /sys if necessary The device can be inaccessible for non-root user or busy (already used by another process). In this case it seems better to read information from /sys. Note that /sys does not provide struct watchdog_info.options, so we cannot print list of supported watchdog features. Addresses: https://github.com/karelzak/util-linux/issues/804 Signed-off-by: Karel Zak --- include/pathnames.h | 1 + sys-utils/wdctl.8 | 4 +++ sys-utils/wdctl.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/include/pathnames.h b/include/pathnames.h index 6f091d5f0..2e1f19355 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -104,6 +104,7 @@ #define _PATH_SYS_BLOCK "/sys/block" #define _PATH_SYS_DEVBLOCK "/sys/dev/block" +#define _PATH_SYS_DEVCHAR "/sys/dev/char" #define _PATH_SYS_CLASS "/sys/class" #define _PATH_SYS_SCSI "/sys/bus/scsi" diff --git a/sys-utils/wdctl.8 b/sys-utils/wdctl.8 index 7edf80866..efd8b5917 100644 --- a/sys-utils/wdctl.8 +++ b/sys-utils/wdctl.8 @@ -14,6 +14,10 @@ Show hardware watchdog status. The default device is If more than one device is specified then the output is separated by one blank line. .PP +If the device is already used or user has no permissions to read from the device than +.B wdctl +reads data from sysfs. In this case information about supported features (flags) might be missing. +.PP Note that the number of supported watchdog features is hardware specific. .SH OPTIONS .TP diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index 772e6b968..0bb245bae 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include @@ -36,6 +39,7 @@ #include "pathnames.h" #include "strutils.h" #include "carefulputc.h" +#include "path.h" /* * since 2.6.18 @@ -113,12 +117,14 @@ struct wd_device { uint32_t status; uint32_t bstatus; + int nowayout; struct watchdog_info ident; unsigned int has_timeout : 1, has_timeleft : 1, - has_pretimeout : 1; + has_pretimeout : 1, + has_nowayout : 1; }; struct wd_control { @@ -282,6 +288,10 @@ static int show_flags(struct wd_control *ctl, struct wd_device *wd, uint32_t wan struct libscols_table *table; uint32_t flags; + /* information about supported bits is probably missing in /sys */ + if (!wd->ident.options) + return 0; + scols_init_debug(0); /* create output table */ @@ -388,7 +398,7 @@ static int set_watchdog(struct wd_device *wd, int timeout) * * Don't use err() or exit() here! */ -static int read_watchdog(struct wd_device *wd) +static int read_watchdog_from_device(struct wd_device *wd) { int fd; sigset_t sigs, oldsigs; @@ -401,13 +411,8 @@ static int read_watchdog(struct wd_device *wd) fd = open(wd->devpath, O_WRONLY|O_CLOEXEC); - if (fd < 0) { - if (errno == EBUSY) - warnx(_("%s: watchdog already in use, terminating."), - wd->devpath); - warn(_("cannot open %s"), wd->devpath); - return -1; - } + if (fd < 0) + return -errno; if (ioctl(fd, WDIOC_GETSUPPORT, &wd->ident) < 0) warn(_("%s: failed to get information about watchdog"), wd->devpath); @@ -445,6 +450,64 @@ static int read_watchdog(struct wd_device *wd) return 0; } +/* Returns: <0 error, 0 success, 1 unssuported */ +static int read_watchdog_from_sysfs(struct wd_device *wd) +{ + struct path_cxt *sys; + struct stat st; + int rc; + + rc = stat(wd->devpath, &st); + if (rc != 0) + return rc; + + sys = ul_new_path(_PATH_SYS_DEVCHAR "/%u:%u", + major(st.st_rdev), minor(st.st_rdev)); + if (!sys) + return -ENOMEM; + + if (ul_path_get_dirfd(sys) < 0) + goto nosysfs; /* device not in /sys */ + + if (ul_path_access(sys, F_OK, "identity") != 0) + goto nosysfs; /* no info in /sys (old miscdev?) */ + + ul_path_read_buffer(sys, (char *) wd->ident.identity, sizeof(wd->ident.identity), "identity"); + + ul_path_scanf(sys, "status", "%x", &wd->status); + ul_path_read_u32(sys, &wd->bstatus, "bootstatus"); + + if (ul_path_read_s32(sys, &wd->nowayout, "nowayout") == 0) + wd->has_nowayout = 1; + if (ul_path_read_s32(sys, &wd->timeout, "timeout") == 0) + wd->has_timeout = 1; + if (ul_path_read_s32(sys, &wd->pretimeout, "pretimeout") == 0) + wd->has_pretimeout = 1; + if (ul_path_read_s32(sys, &wd->timeleft, "timeleft") == 0) + wd->has_timeleft = 1; + + ul_unref_path(sys); + return 0; +nosysfs: + ul_unref_path(sys); + return 1; +} + +static int read_watchdog(struct wd_device *wd) +{ + int rc = read_watchdog_from_device(wd); + + if (rc == -EBUSY || rc == -EACCES || rc == -EPERM) + rc = read_watchdog_from_sysfs(wd); + + if (rc) { + warn(_("cannot read information about %s"), wd->devpath); + return -1; + } + + return 0; +} + static void show_timeouts(struct wd_device *wd) { if (wd->has_timeout) -- cgit v1.2.3-55-g7522 From 7571ec08a15d54ad05e4b619ccef5a6f10ce30bc Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 Jun 2019 13:30:42 +0200 Subject: libfdisk: add fdisk_assign_device_by_fd() It's possible that caller has the device already opened for some other task, so let's reuse the file descriptor. Requested-by: Lennart Poettering Signed-off-by: Karel Zak --- libfdisk/docs/libfdisk-sections.txt | 1 + libfdisk/src/context.c | 142 ++++++++++++++++++++++++------------ libfdisk/src/fdiskP.h | 1 + libfdisk/src/libfdisk.h.in | 2 + libfdisk/src/libfdisk.sym | 1 + 5 files changed, 99 insertions(+), 48 deletions(-) diff --git a/libfdisk/docs/libfdisk-sections.txt b/libfdisk/docs/libfdisk-sections.txt index d0d362f60..f148da527 100644 --- a/libfdisk/docs/libfdisk-sections.txt +++ b/libfdisk/docs/libfdisk-sections.txt @@ -291,6 +291,7 @@ fdisk_unref_table context fdisk_context fdisk_assign_device +fdisk_assign_device_by_fd fdisk_deassign_device fdisk_reassign_device fdisk_device_is_used diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 1171f28a8..b62d2b101 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -541,7 +541,7 @@ static void reset_context(struct fdisk_context *cxt) free(cxt->firstsector); } else { /* we close device only in primary context */ - if (cxt->dev_fd > -1) + if (cxt->dev_fd > -1 && cxt->private_fd) close(cxt->dev_fd); free(cxt->firstsector); } @@ -559,6 +559,7 @@ static void reset_context(struct fdisk_context *cxt) memset(&cxt->dev_st, 0, sizeof(cxt->dev_st)); cxt->dev_fd = -1; + cxt->private_fd = 0; cxt->firstsector = NULL; cxt->firstsector_bufsz = 0; @@ -572,39 +573,12 @@ static void reset_context(struct fdisk_context *cxt) fdisk_free_wipe_areas(cxt); } -/** - * fdisk_assign_device: - * @cxt: context - * @fname: path to the device to be handled - * @readonly: how to open the device - * - * Open the device, discovery topology, geometry, detect disklabel, check for - * collisions and switch the current label driver to reflect the probing - * result. - * - * If in standard mode (!= non-listonly mode) than also detects for collisions. - * The result is accessible by fdisk_get_collision() and - * fdisk_is_ptcollision(). The collision (e.g. old obsolete PT) may be removed - * by fdisk_enable_wipe(). Note that new PT and old PT may be on different - * locations. - * - * Note that this function resets all generic setting in context. - * - * If the @cxt is nested context (necessary for example to edit BSD or PMBR) - * then the device is assigned to the parental context and necessary properties - * are copied to the @cxt. The change is propagated in child->parent direction - * only. It's impossible to use a different device for primary and nested - * contexts. - * - * Returns: 0 on success, < 0 on error. - */ -int fdisk_assign_device(struct fdisk_context *cxt, - const char *fname, int readonly) +/* fdisk_assign_device() body */ +static int fdisk_assign_fd(struct fdisk_context *cxt, int fd, + const char *fname, int readonly, int privfd) { - int fd; - - DBG(CXT, ul_debugobj(cxt, "assigning device %s", fname)); assert(cxt); + assert(fd >= 0); /* redirect request to parent */ if (cxt->parent) { @@ -615,7 +589,7 @@ int fdisk_assign_device(struct fdisk_context *cxt, * unwanted extra warnings. */ fdisk_enable_listonly(cxt->parent, fdisk_is_listonly(cxt)); - rc = fdisk_assign_device(cxt->parent, fname, readonly); + rc = fdisk_assign_fd(cxt->parent, fd, fname, readonly, privfd); fdisk_enable_listonly(cxt->parent, org); if (!rc) @@ -627,16 +601,13 @@ int fdisk_assign_device(struct fdisk_context *cxt, reset_context(cxt); - fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC); - if (fd < 0) - goto fail; - if (fstat(fd, &cxt->dev_st) != 0) goto fail; cxt->readonly = readonly; cxt->dev_fd = fd; - cxt->dev_path = strdup(fname); + cxt->private_fd = privfd; + cxt->dev_path = fname ? strdup(fname) : NULL; if (!cxt->dev_path) goto fail; @@ -649,7 +620,6 @@ int fdisk_assign_device(struct fdisk_context *cxt, goto fail; fdisk_probe_labels(cxt); - fdisk_apply_label_device_properties(cxt); /* warn about obsolete stuff on the device if we aren't in @@ -664,13 +634,78 @@ int fdisk_assign_device(struct fdisk_context *cxt, fail: { int rc = -errno; - if (fd >= 0) - close(fd); DBG(CXT, ul_debugobj(cxt, "failed to assign device [rc=%d]", rc)); return rc; } } +/** + * fdisk_assign_device: + * @cxt: context + * @fname: path to the device to be handled + * @readonly: how to open the device + * + * Open the device, discovery topology, geometry, detect disklabel, check for + * collisions and switch the current label driver to reflect the probing + * result. + * + * If in standard mode (!= non-listonly mode) than also detects for collisions. + * The result is accessible by fdisk_get_collision() and + * fdisk_is_ptcollision(). The collision (e.g. old obsolete PT) may be removed + * by fdisk_enable_wipe(). Note that new PT and old PT may be on different + * locations. + * + * Note that this function resets all generic setting in context. + * + * If the @cxt is nested context (necessary for example to edit BSD or PMBR) + * then the device is assigned to the parental context and necessary properties + * are copied to the @cxt. The change is propagated in child->parent direction + * only. It's impossible to use a different device for primary and nested + * contexts. + * + * Returns: 0 on success, < 0 on error. + */ +int fdisk_assign_device(struct fdisk_context *cxt, + const char *fname, int readonly) +{ + int fd, rc; + + DBG(CXT, ul_debugobj(cxt, "assigning device %s", fname)); + assert(cxt); + + fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC); + if (fd < 0) { + int rc = -errno; + DBG(CXT, ul_debugobj(cxt, "failed to assign device [rc=%d]", rc)); + return rc; + } + + rc = fdisk_assign_fd(cxt, fd, fname, readonly, 1); + if (rc) + close(fd); + return rc; +} + +/** + * fdisk_assign_device_by_fd: + * @cxt: context + * @fd: device file descriptor + * @fname: path to the device (used for dialogs, debugging, partition names, ...) + * @readonly: how to use the device + * + * Like fdisk_assign_device(), but caller is responsible to open and close the + * device. The library only fsync() the device on fdisk_deassign_device(). + * + * The device has to be open O_RDWR on @readonly=0. + * + * Returns: 0 on success, < 0 on error. + */ +int fdisk_assign_device_by_fd(struct fdisk_context *cxt, int fd, + const char *fname, int readonly) +{ + return fdisk_assign_fd(cxt, fd, fname, readonly, 0); +} + /** * fdisk_deassign_device: * @cxt: context @@ -696,15 +731,19 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync) DBG(CXT, ul_debugobj(cxt, "de-assigning device %s", cxt->dev_path)); - if (cxt->readonly) + if (cxt->readonly && cxt->private_fd) close(cxt->dev_fd); else { - if (fsync(cxt->dev_fd) || close(cxt->dev_fd)) { + if (fsync(cxt->dev_fd)) { + fdisk_warn(cxt, _("%s: fsync device failed"), + cxt->dev_path); + return -errno; + } + if (cxt->private_fd && close(cxt->dev_fd)) { fdisk_warn(cxt, _("%s: close device failed"), cxt->dev_path); return -errno; } - if (!nosync) { fdisk_info(cxt, _("Syncing disks.")); sync(); @@ -713,7 +752,6 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync) free(cxt->dev_path); cxt->dev_path = NULL; - cxt->dev_fd = -1; return 0; @@ -733,7 +771,7 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync) int fdisk_reassign_device(struct fdisk_context *cxt) { char *devname; - int rdonly, rc; + int rdonly, rc, fd, privfd; assert(cxt); assert(cxt->dev_fd >= 0); @@ -745,11 +783,19 @@ int fdisk_reassign_device(struct fdisk_context *cxt) return -ENOMEM; rdonly = cxt->readonly; + fd = cxt->dev_fd; + privfd = cxt->private_fd; fdisk_deassign_device(cxt, 1); - rc = fdisk_assign_device(cxt, devname, rdonly); - free(devname); + if (privfd) + /* reopen and assign */ + rc = fdisk_assign_device(cxt, devname, rdonly); + else + /* assign only */ + rc = fdisk_assign_fd(cxt, fd, devname, rdonly, privfd); + + free(devname); return rc; } diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index 19c1c7953..fefebae2a 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -389,6 +389,7 @@ struct fdisk_context { pt_collision : 1, /* another PT detected by libblkid */ no_disalogs : 1, /* disable dialog-driven partititoning */ dev_model_probed : 1, /* tried to read from sys */ + private_fd : 1, /* open by libfdisk */ listonly : 1; /* list partition, nothing else */ char *collision; /* name of already existing FS/PT */ diff --git a/libfdisk/src/libfdisk.h.in b/libfdisk/src/libfdisk.h.in index 69c6fd820..0669c0a7c 100644 --- a/libfdisk/src/libfdisk.h.in +++ b/libfdisk/src/libfdisk.h.in @@ -195,6 +195,8 @@ int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype id); int fdisk_assign_device(struct fdisk_context *cxt, const char *fname, int readonly); +int fdisk_assign_device_by_fd(struct fdisk_context *cxt, int fd, + const char *fname, int readonly); int fdisk_deassign_device(struct fdisk_context *cxt, int nosync); int fdisk_reassign_device(struct fdisk_context *cxt); diff --git a/libfdisk/src/libfdisk.sym b/libfdisk/src/libfdisk.sym index 8ce943acc..96fcadd71 100644 --- a/libfdisk/src/libfdisk.sym +++ b/libfdisk/src/libfdisk.sym @@ -306,4 +306,5 @@ FDISK_2.33 { FDISK_2.35 { fdisk_script_set_table; + fdisk_assign_device_by_fd; } FDISK_2.33; -- cgit v1.2.3-55-g7522 From dab1303287b7ebe30b57ccc78591070dad0a85ea Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 18 Jun 2019 22:05:16 +0200 Subject: Revert "lib/loopdev.c: Inline loopcxt_has_device" ... no caller in that file, this change has no effect. This reverts commit 3bb960c7b5f1428f1bff885b2667787e8af5001b. --- lib/loopdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loopdev.c b/lib/loopdev.c index ede1b5cdc..99a093926 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -127,7 +127,7 @@ int loopcxt_set_device(struct loopdev_cxt *lc, const char *device) return 0; } -inline int loopcxt_has_device(struct loopdev_cxt *lc) +int loopcxt_has_device(struct loopdev_cxt *lc) { return lc && *lc->device; } -- cgit v1.2.3-55-g7522 From f1424a94239f9149939b45ed9f19e8f77fb1847d Mon Sep 17 00:00:00 2001 From: Marcos Mello Date: Thu, 20 Jun 2019 08:22:25 -0300 Subject: libfdisk: fix typos --- libfdisk/src/alignment.c | 2 +- libfdisk/src/context.c | 8 ++++---- libfdisk/src/label.c | 8 ++++---- libfdisk/src/script.c | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libfdisk/src/alignment.c b/libfdisk/src/alignment.c index 426fa938c..4ae5ff08f 100644 --- a/libfdisk/src/alignment.c +++ b/libfdisk/src/alignment.c @@ -324,7 +324,7 @@ int fdisk_save_user_sector_size(struct fdisk_context *cxt, * * The smallest possible granularity for partitioning is physical sector size * (or minimal I/O size; the bigger number win). If the user's @grain size is - * too small than the smallest possible granularity is used. It means + * too small then the smallest possible granularity is used. It means * fdisk_save_user_grain(cxt, 512) forces libfdisk to use grain as small as * possible. * diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index b62d2b101..3677648e9 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -17,7 +17,7 @@ * * The library distinguish between three types of partitioning objects. * - * on-disk lebel data + * on-disk label data * - disk label specific * - probed and read by disklabel drivers when assign device to the context * or when switch to another disk label type @@ -487,7 +487,7 @@ int fdisk_is_ptcollision(struct fdisk_context *cxt) * * * Note that the recommended way to list partitions is to use - * fdisk_get_partitions() and struct fdisk_table than ask disk driver for each + * fdisk_get_partitions() and struct fdisk_table then ask disk driver for each * individual partitions. * * Returns: maximal number of partitions for the current label. @@ -649,7 +649,7 @@ fail: * collisions and switch the current label driver to reflect the probing * result. * - * If in standard mode (!= non-listonly mode) than also detects for collisions. + * If in standard mode (!= non-listonly mode) then also detects for collisions. * The result is accessible by fdisk_get_collision() and * fdisk_is_ptcollision(). The collision (e.g. old obsolete PT) may be removed * by fdisk_enable_wipe(). Note that new PT and old PT may be on different @@ -711,7 +711,7 @@ int fdisk_assign_device_by_fd(struct fdisk_context *cxt, int fd, * @cxt: context * @nosync: disable fsync() * - * Close device and call fsync(). If the @cxt is nested context than the + * Close device and call fsync(). If the @cxt is nested context then the * request is redirected to the parent. * * Returns: 0 on success, < 0 on error. diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 68f73f143..a18cdeaff 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -247,7 +247,7 @@ const struct fdisk_field *fdisk_label_get_field_by_name( * fdisk_write_disklabel: * @cxt: fdisk context * - * This function wipes the device (if eanbled by fdisk_enable_wipe() and than + * This function wipes the device (if enabled by fdisk_enable_wipe()) and then * it writes in-memory changes to disk. Be careful! * * Returns: 0 on success, otherwise, a corresponding error. @@ -637,7 +637,7 @@ int fdisk_label_is_disabled(const struct fdisk_label *lb) * @ma: maximal number * * The function provides minimal and maximal geometry supported for the label, - * if no range defined by library than returns -ENOSYS. + * if no range defined by library then returns -ENOSYS. * * Since: 2.32 * @@ -662,7 +662,7 @@ int fdisk_label_get_geomrange_sectors(const struct fdisk_label *lb, * @ma: maximal number * * The function provides minimal and maximal geometry supported for the label, - * if no range defined by library than returns -ENOSYS. + * if no range defined by library then returns -ENOSYS. * * Since: 2.32 * @@ -687,7 +687,7 @@ int fdisk_label_get_geomrange_heads(const struct fdisk_label *lb, * @ma: maximal number * * The function provides minimal and maximal geometry supported for the label, - * if no range defined by library than returns -ENOSYS. + * if no range defined by library then returns -ENOSYS. * * Since: 2.32 * diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index dbbd53eaf..3db76c87b 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -30,7 +30,7 @@ * The read functions fdisk_script_read_context() and fdisk_script_read_file() * creates always a new script partition table. The table (see * fdisk_script_get_table()) is possible to modify by standard - * fdisk_table_...() functions and than apply by fdisk_apply_script(). + * fdisk_table_...() functions and then apply by fdisk_apply_script(). * * Note that script API is fully non-interactive and forces libfdisk to not use * standard dialog driven partitioning as we have in fdisk(8). @@ -345,7 +345,7 @@ struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp) if (!dp->table) /* * Make sure user has access to the same table as script. If - * there is no table than create a new and reuse it later. + * there is no table then create a new one and reuse it later. */ dp->table = fdisk_new_table(); @@ -363,10 +363,10 @@ struct fdisk_table *fdisk_script_get_table(struct fdisk_script *dp) * * This is useful for example to create partition table with the same basic * settings (e.g. label-id, ...) but with different partitions -- just call - * fdisk_script_read_context() to get current settings and than + * fdisk_script_read_context() to get current settings and then * fdisk_script_set_table() to set a different layout. * - * If @tb is NULL than the current script table is unreferenced. + * If @tb is NULL then the current script table is unreferenced. * * Note that script read_ functions (e.g. fdisk_script_read_context()) create * always a new script table. @@ -434,7 +434,7 @@ int fdisk_script_has_force_label(struct fdisk_script *dp) * @cxt: context * * Reads data from the @cxt context (on disk partition table) into the script. - * If the context is no specified than defaults to context used for fdisk_new_script(). + * If the context is not specified then defaults to context used for fdisk_new_script(). * * Return: 0 on success, <0 on error. */ -- cgit v1.2.3-55-g7522 From b0853a08dba1163613069ba24cb09cc2f0282d98 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec Date: Thu, 20 Jun 2019 22:16:42 +0200 Subject: agetty: Remove superfluous fflush() eval_issue_file() contains fflush(stdout). It comes from an old code that used fputs() to write to the console. In the new code, we write to a temporary memstream, and fclose(ie->output) fully replaces possible fflush(ie->output) in this implementation. The new print_issue_file() does not need it as well, as it uses unbuffered write_all(). Signed-off-by: Stanislav Brabec --- term-utils/agetty.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 43dbd6dea..96bf41b36 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -1903,8 +1903,6 @@ static void eval_issue_file(struct issue *ie, f = NULL; } while (dirname); - fflush(stdout); - if ((op->flags & F_VCONSOLE) == 0) ie->do_tcrestore = 1; } -- cgit v1.2.3-55-g7522 From ec06412c90f789864a99361f46740fe640a01679 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec Date: Thu, 20 Jun 2019 23:41:30 +0200 Subject: losetup: Typo fix Fix a typo in usage introduced in a1a41597bf. Signed-off-by: Stanislav Brabec --- sys-utils/losetup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 27884df73..379b95f17 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -419,7 +419,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(USAGE_SEPARATOR, out); fputs(_(" -o, --offset start at offset into file\n"), out); fputs(_(" --sizelimit device is limited to bytes of the file\n"), out); - fputs(_(" -b --sector-size set the logical sector size to \n"), out); + fputs(_(" -b, --sector-size set the logical sector size to \n"), out); fputs(_(" -P, --partscan create a partitioned loop device\n"), out); fputs(_(" -r, --read-only set up a read-only loop device\n"), out); fputs(_(" --direct-io[=] open backing file with O_DIRECT\n"), out); -- cgit v1.2.3-55-g7522 From d670a3f30bfc4794b42ba9d564656d419c946572 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec Date: Thu, 20 Jun 2019 23:42:40 +0200 Subject: Fix translations for losetup typo fix Signed-off-by: Stanislav Brabec --- po/cs.po | 2 +- po/da.po | 2 +- po/de.po | 4 ++-- po/es.po | 2 +- po/fr.po | 2 +- po/hr.po | 4 ++-- po/pl.po | 2 +- po/pt_BR.po | 4 ++-- po/sv.po | 2 +- po/uk.po | 4 ++-- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/po/cs.po b/po/cs.po index 35f6f97c9..9c5f0059c 100644 --- a/po/cs.po +++ b/po/cs.po @@ -14802,7 +14802,7 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit omezí zařízení na bajtů souboru\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" +msgid " -b, --sector-size set the logical sector size to \n" msgstr " -b, --sector-size <číslo> nastaví velikost logického sektoru na <číslo>\n" #: sys-utils/losetup.c:423 diff --git a/po/da.po b/po/da.po index baf6b4577..24c6ec5ed 100644 --- a/po/da.po +++ b/po/da.po @@ -14702,7 +14702,7 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit enhed er begrænset til byte af filen\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" +msgid " -b, --sector-size set the logical sector size to \n" msgstr " -b, --sector-size angiv den logiske sektorstørrelse til \n" #: sys-utils/losetup.c:423 diff --git a/po/de.po b/po/de.po index c135ce828..ef24a1da4 100644 --- a/po/de.po +++ b/po/de.po @@ -14835,8 +14835,8 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit das Gerät ist auf Bytes der Datei beschränkt\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" -msgstr " -b --sector-size die logische Sekttorgröße auf setzen\n" +msgid " -b, --sector-size set the logical sector size to \n" +msgstr " -b, --sector-size die logische Sekttorgröße auf setzen\n" #: sys-utils/losetup.c:423 msgid " -P, --partscan create a partitioned loop device\n" diff --git a/po/es.po b/po/es.po index 05e565bbb..7f1e115c0 100644 --- a/po/es.po +++ b/po/es.po @@ -14577,7 +14577,7 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit el dispositivo está limitado a bytes del fichero\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" +msgid " -b, --sector-size set the logical sector size to \n" msgstr " -b, --sector-size establece el tamaño de sector lógico en \n" #: sys-utils/losetup.c:423 diff --git a/po/fr.po b/po/fr.po index b9fc060b8..f6b696d87 100644 --- a/po/fr.po +++ b/po/fr.po @@ -14630,7 +14630,7 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit périphérique limité à  octets du fichier\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" +msgid " -b, --sector-size set the logical sector size to \n" msgstr " -b, --sector-size définir la taille de secteur logique à \n" #: sys-utils/losetup.c:423 diff --git a/po/hr.po b/po/hr.po index 74ad956be..3e1db42b6 100644 --- a/po/hr.po +++ b/po/hr.po @@ -14752,8 +14752,8 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit koristi samo taj broj bajtova datoteke\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" -msgstr " -b --sector-size veličinu logičkog sektora postavi na taj broj\n" +msgid " -b, --sector-size set the logical sector size to \n" +msgstr " -b, --sector-size veličinu logičkog sektora postavi na taj broj\n" #: sys-utils/losetup.c:423 msgid " -P, --partscan create a partitioned loop device\n" diff --git a/po/pl.po b/po/pl.po index 11c53922b..2b8f631b5 100644 --- a/po/pl.po +++ b/po/pl.po @@ -14576,7 +14576,7 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit ograniczenie do podanej liczby bajtów pliku\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" +msgid " -b, --sector-size set the logical sector size to \n" msgstr " -b, --sector-size ustawienie rozmiaru sektora logicznego\n" #: sys-utils/losetup.c:423 diff --git a/po/pt_BR.po b/po/pt_BR.po index 17120cbc3..503cd8c2a 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -14721,8 +14721,8 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit dispositivo limitado a bytes do arquivo\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" -msgstr " -b --sector-size define o tamanho de setor lógico para \n" +msgid " -b, --sector-size set the logical sector size to \n" +msgstr " -b, --sector-size define o tamanho de setor lógico para \n" #: sys-utils/losetup.c:423 msgid " -P, --partscan create a partitioned loop device\n" diff --git a/po/sv.po b/po/sv.po index b7de28cdc..31c8c06cc 100644 --- a/po/sv.po +++ b/po/sv.po @@ -14550,7 +14550,7 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit enhet är begränsad till byte i filen\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" +msgid " -b, --sector-size set the logical sector size to \n" msgstr " -b, --sector-size ställ in logisk sektorstorlek\n" #: sys-utils/losetup.c:423 diff --git a/po/uk.po b/po/uk.po index b13910ba9..c814a5f44 100644 --- a/po/uk.po +++ b/po/uk.po @@ -14591,8 +14591,8 @@ msgid " --sizelimit device is limited to bytes of the fi msgstr " --sizelimit пристрій обмежено байтами файла\n" #: sys-utils/losetup.c:422 -msgid " -b --sector-size set the logical sector size to \n" -msgstr " -b --sector-size <число> встановити для логічного сектора розмір <число>\n" +msgid " -b, --sector-size set the logical sector size to \n" +msgstr " -b, --sector-size <число> встановити для логічного сектора розмір <число>\n" #: sys-utils/losetup.c:423 msgid " -P, --partscan create a partitioned loop device\n" -- cgit v1.2.3-55-g7522 From cfb9934d5fb6a8fb3499d9c6cdac6640ce57275a Mon Sep 17 00:00:00 2001 From: Sanchit Saini Date: Fri, 21 Jun 2019 23:21:46 +0530 Subject: TODO: fix typo --- Documentation/TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/TODO b/Documentation/TODO index a4a8d7890..6d4c1b278 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -51,7 +51,7 @@ nsenter(1) - read the default UID and GID from the target process. http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/9553/focus=9585 -hwlock +hwclock ------ - use /var/lib/hwclock/drift to store hw-clock drift numbers. - use /etc/adjtime as read-only for UTC/LOCAL information only -- cgit v1.2.3-55-g7522 From e3bb9bfb76c17b1d05814436ced62c05c4011f48 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 27 Jun 2019 09:22:18 +0200 Subject: lsblk: force to print PKNAME for partition PKNAME (parent kernel device name) is based on printed tree according to parent -> child relationship. The tree is optional and not printed if partition specified (.e.g "lsblk -o+PKNAME /dev/sda1"), but old versions print the PKNAME also in this case. Addresses: https://github.com/karelzak/util-linux/issues/813 Signed-off-by: Karel Zak --- misc-utils/lsblk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index e95af7af0..3ce6da730 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -1019,6 +1019,9 @@ static void device_to_scols( DBG(DEV, ul_debugobj(dev, "add '%s' to scols", dev->name)); ON_DBG(DEV, if (ul_path_isopen_dirfd(dev->sysfs)) ul_debugobj(dev, " %s ---> is open!", dev->name)); + if (!parent && dev->wholedisk) + parent = dev->wholedisk; + /* Do not print device more than one in --list mode */ if (!(lsblk->flags & LSBLK_TREE) && dev->is_printed) return; -- cgit v1.2.3-55-g7522 From 5119ef0a8335a7a9e3fde2b6990ed66e2c0b5974 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Mon, 1 Jul 2019 22:02:06 +0100 Subject: lib/ttyutils: avoid checking same thing twice Check cols and lines are not NULL only once. Signed-off-by: Sami Kerola --- lib/ttyutils.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ttyutils.c b/lib/ttyutils.c index 166e49e11..8649f435a 100644 --- a/lib/ttyutils.c +++ b/lib/ttyutils.c @@ -47,16 +47,16 @@ int get_terminal_dimension(int *cols, int *lines) l = t_win.ts_lines; } #endif - - if (cols && c <= 0) - c = get_env_int("COLUMNS"); - if (lines && l <= 0) - l = get_env_int("LINES"); - - if (cols) + if (cols) { + if (c <= 0) + c = get_env_int("COLUMNS"); *cols = c; - if (lines) + } + if (lines) { + if (l <= 0) + l = get_env_int("LINES"); *lines = l; + } return 0; } -- cgit v1.2.3-55-g7522 From 34813bdd29cd2012bec61156286018ed9e13817a Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2019 21:45:50 +0100 Subject: libfdisk: fix variable shadowing libfdisk/src/context.c:678:7: warning: declaration of ‘rc’ shadows a previous local [-Wshadow] Signed-off-by: Sami Kerola --- libfdisk/src/context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 3677648e9..770aa4d52 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -675,7 +675,7 @@ int fdisk_assign_device(struct fdisk_context *cxt, fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC); if (fd < 0) { - int rc = -errno; + rc = -errno; DBG(CXT, ul_debugobj(cxt, "failed to assign device [rc=%d]", rc)); return rc; } -- cgit v1.2.3-55-g7522 From 371be858d74fe5562a403af75e596d7bd0042905 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2019 21:56:52 +0100 Subject: libmount: fix potential null pointer dereference This is false positive warning, but lets silence it so that if and when warnings crop up they are easy to notice and take seriously. libmount/src/optstr.c:354:29: warning: potential null pointer dereference [-Wnull-dereference] Signed-off-by: Sami Kerola --- libmount/src/optstr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index c0f438fe2..49fc9cc40 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -351,7 +351,9 @@ int mnt_optstr_deduplicate_option(char **optstr, const char *name) end = ol.end; opt = end && *end ? end + 1 : NULL; } - } while (rc == 0 && opt && *opt); + if (opt == NULL) + break; + } while (rc == 0 && *opt); return rc < 0 ? rc : begin ? 0 : 1; } -- cgit v1.2.3-55-g7522 From f3aded3fdb1e19818b05f205b74cd4bff7532811 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 12 Jul 2019 22:28:10 +0100 Subject: include/xalloc: ensure xstrdup() and xstrndup() returns nonnull attribute Turned out lsblk is passing null as argument to xstrdup(), so fix that and add assert() to make sure promise of not returning null is kept in future. Signed-off-by: Sami Kerola --- include/xalloc.h | 6 ++---- misc-utils/lsblk.c | 8 +++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/xalloc.h b/include/xalloc.h index 0129a85e2..48712a452 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -62,8 +62,7 @@ static inline char __attribute__((warn_unused_result)) __ul_returns_nonnull { char *ret; - if (!str) - return NULL; + assert(str); ret = strdup(str); @@ -77,8 +76,7 @@ xstrndup(const char *str, size_t size) { char *ret; - if (!str) - return NULL; + assert(str); ret = strndup(str, size); diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 3ce6da730..7ab9dc23c 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -774,8 +774,14 @@ static char *device_get_data( str = get_vfs_attribute(dev, id); break; case COL_TARGET: - str = xstrdup(lsblk_device_get_mountpoint(dev)); + { + char *s = lsblk_device_get_mountpoint(dev); + if (s) + str = xstrdup(s); + else + str = NULL; break; + } case COL_LABEL: prop = lsblk_device_get_properties(dev); if (prop && prop->label) -- cgit v1.2.3-55-g7522 From 9175f39075b130bce00ed4b0d23be90a1defa915 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 13 Jul 2019 09:31:06 +0100 Subject: libblkid: check number of test_blkid_save arguments correctly Without this running test_blkid_save without arguments will cause a crash when strdup() refers to none-exiting file name. Signed-off-by: Sami Kerola --- libblkid/src/save.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libblkid/src/save.c b/libblkid/src/save.c index 21308a9cf..bceaa1139 100644 --- a/libblkid/src/save.c +++ b/libblkid/src/save.c @@ -213,7 +213,7 @@ int main(int argc, char **argv) int ret; blkid_init_debug(BLKID_DEBUG_ALL); - if (argc > 2) { + if (argc != 2) { fprintf(stderr, "Usage: %s [filename]\n" "Test loading/saving a cache (filename)\n", argv[0]); exit(1); -- cgit v1.2.3-55-g7522 From f55dd4cc2dadfa74e5a207a4058489fa4d10387a Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 14 Jul 2019 10:17:32 +0100 Subject: libblkid: fix address sanitizer issues With aligned attribute many blkid tests fail with following error. So instead of aligning to 4K add padding that makes the struct same size without causing asan trip over. libblkid/src/superblocks/drbd.c:179:6: runtime error: member access within misaligned address 0x55913d7e6958 for type 'struct meta_data_on_disk_9', which requires 4096 byte alignment In zfs structure it seems compiler is adding padding, that does not mix well with be32_to_cpu() and other bit operations. libblkid/src/superblocks/zfs.c:109:23: runtime error: load of misaligned address 0x7ff6406540e4 for type 'uint32_t' (aka 'unsigned int'), which requires 8 byte alignment Signed-off-by: Sami Kerola --- libblkid/src/superblocks/drbd.c | 2 +- libblkid/src/superblocks/zfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c index 4ebaf1739..c27a8b384 100644 --- a/libblkid/src/superblocks/drbd.c +++ b/libblkid/src/superblocks/drbd.c @@ -109,7 +109,7 @@ struct meta_data_on_disk_9 { struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX]; uint64_t history_uuids[HISTORY_UUIDS]; - char padding[0] __attribute__((aligned(4096))); + uint8_t padding[2704]; } __attribute__((packed)); diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c index 4d4b46d55..0af14fb65 100644 --- a/libblkid/src/superblocks/zfs.c +++ b/libblkid/src/superblocks/zfs.c @@ -58,7 +58,7 @@ struct nvuint64 { uint32_t nvu_type; uint32_t nvu_elem; uint64_t nvu_value; -}; +} __attribute__((packed)); struct nvlist { uint32_t nvl_unknown[3]; -- cgit v1.2.3-55-g7522 From 1632856ef19efb50c57c939b82a9ff712b3c0b09 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 5 Jul 2019 17:20:27 +0200 Subject: build-sys: Include in ./configure wchar_t test Without #include , this configure check fails for strict C99/C11 compilers which do not support implicit function declarations (which are a C90 feature removed from C99). Signed-off-by: Karel Zak --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index a840e20ee..997b6388c 100644 --- a/configure.ac +++ b/configure.ac @@ -756,6 +756,7 @@ UL_REQUIRES_COMPILE([widechar], [[ #include #include #include + #include ]], [[ wchar_t wc; wint_t w; -- cgit v1.2.3-55-g7522 From 5c8a88356d436f6a87e2c40347dd19d6f5b50198 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 15 Jul 2019 12:07:42 +0200 Subject: libblkid: (drbd) simplify padding We do not need all the metadata and it seems the extra padding is problematic in some cases. Let's keep is simple and use fixed offset for the metadata rather than sizeof(). References: https://github.com/karelzak/util-linux/pull/820 Signed-off-by: Karel Zak --- libblkid/src/superblocks/drbd.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c index c27a8b384..000a34879 100644 --- a/libblkid/src/superblocks/drbd.c +++ b/libblkid/src/superblocks/drbd.c @@ -45,6 +45,13 @@ enum drbd_uuid_index { UI_EXTENDED_SIZE /* Everything. */ }; + +/* + * Used by libblkid to avoid unnecessary padding at the end of the structs and + * too large unused structs in memory. + */ +#define DRBD_MD_OFFSET 4096 + /* * user/shared/drbdmeta.c * Minor modifications wrt. types @@ -63,7 +70,8 @@ struct md_on_disk_08 { uint32_t bm_bytes_per_bit; uint32_t reserved_u32[4]; - char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)]; + /** Unnecessary for libblkid ** + * char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)]; */ }; /* @@ -109,7 +117,9 @@ struct meta_data_on_disk_9 { struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX]; uint64_t history_uuids[HISTORY_UUIDS]; - uint8_t padding[2704]; + /** Unnecessary for libblkid ** + * char padding[0] __attribute__((aligned(4096))); + */ } __attribute__((packed)); @@ -118,7 +128,7 @@ static int probe_drbd_84(blkid_probe pr) struct md_on_disk_08 *md; off_t off; - off = pr->size - sizeof(*md); + off = pr->size - DRBD_MD_OFFSET; /* Small devices cannot be drbd (?) */ if (pr->size < 0x10000) @@ -159,7 +169,7 @@ static int probe_drbd_90(blkid_probe pr) struct meta_data_on_disk_9 *md; off_t off; - off = pr->size - sizeof(*md); + off = pr->size - DRBD_MD_OFFSET; /* * Smaller ones are certainly not DRBD9 devices. -- cgit v1.2.3-55-g7522 From 9e677de1ecbb5c724f679e66d773494e370db97f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 15 Jul 2019 12:28:26 +0200 Subject: lsblk: fix -E segfault We need to check if referenced wholedisk defines the de-duplication key... Addresses: https://github.com/karelzak/util-linux/issues/819 Signed-off-by: Karel Zak --- misc-utils/lsblk-devtree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc-utils/lsblk-devtree.c b/misc-utils/lsblk-devtree.c index a2aa26aed..4d15f70c1 100644 --- a/misc-utils/lsblk-devtree.c +++ b/misc-utils/lsblk-devtree.c @@ -384,6 +384,7 @@ static int device_dedupkey_is_equal( return 0; if (strcmp(dev->dedupkey, pattern->dedupkey) == 0) { if (!device_is_partition(dev) || + !dev->wholedisk->dedupkey || strcmp(dev->dedupkey, dev->wholedisk->dedupkey) != 0) { DBG(DEV, ul_debugobj(dev, "%s: match deduplication pattern", dev->name)); return 1; @@ -458,6 +459,7 @@ int lsblk_devtree_deduplicate_devices(struct lsblk_devtree *tr) if (!pattern->dedupkey) continue; if (device_is_partition(pattern) && + pattern->wholedisk->dedupkey && strcmp(pattern->dedupkey, pattern->wholedisk->dedupkey) == 0) continue; if (last && strcmp(pattern->dedupkey, last) == 0) -- cgit v1.2.3-55-g7522 From 8ebecc18e859474986cdb2fbe9fa3419e3417e28 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 15 Jul 2019 12:46:11 +0200 Subject: tests: (libmount) make X-* and x-* more robust Addresses: https://github.com/karelzak/util-linux/issues/818 Signed-off-by: Karel Zak --- tests/expected/libmount/context-X-comment | 1 + tests/expected/libmount/context-X-mount.mkdir | 1 - tests/expected/libmount/context-x-mount.mkdir | 1 - tests/expected/libmount/context-x-permanent | 1 + tests/ts/libmount/context | 7 ++++--- 5 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 tests/expected/libmount/context-X-comment delete mode 100644 tests/expected/libmount/context-X-mount.mkdir delete mode 100644 tests/expected/libmount/context-x-mount.mkdir create mode 100644 tests/expected/libmount/context-x-permanent diff --git a/tests/expected/libmount/context-X-comment b/tests/expected/libmount/context-X-comment new file mode 100644 index 000000000..7504a7e83 --- /dev/null +++ b/tests/expected/libmount/context-X-comment @@ -0,0 +1 @@ +successfully mounted diff --git a/tests/expected/libmount/context-X-mount.mkdir b/tests/expected/libmount/context-X-mount.mkdir deleted file mode 100644 index 7504a7e83..000000000 --- a/tests/expected/libmount/context-X-mount.mkdir +++ /dev/null @@ -1 +0,0 @@ -successfully mounted diff --git a/tests/expected/libmount/context-x-mount.mkdir b/tests/expected/libmount/context-x-mount.mkdir deleted file mode 100644 index 7504a7e83..000000000 --- a/tests/expected/libmount/context-x-mount.mkdir +++ /dev/null @@ -1 +0,0 @@ -successfully mounted diff --git a/tests/expected/libmount/context-x-permanent b/tests/expected/libmount/context-x-permanent new file mode 100644 index 000000000..7504a7e83 --- /dev/null +++ b/tests/expected/libmount/context-x-permanent @@ -0,0 +1 @@ +successfully mounted diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context index 3750c701f..6dd35b193 100755 --- a/tests/ts/libmount/context +++ b/tests/ts/libmount/context @@ -146,8 +146,8 @@ is_mounted $MOUNTPOINT && echo "$MOUNTPOINT still mounted" >> $TS_OUTPUT 2>&1 ts_finalize_subtest -# deprecated -ts_init_subtest "x-mount.mkdir" +# deprecated (x-* mount option maintained in userspace (e.g. utab) +ts_init_subtest "x-permanent" TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex" [ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST @@ -159,7 +159,8 @@ $TS_CMD_UMOUNT $TS_NOEXIST rmdir $TS_NOEXIST -ts_init_subtest "X-mount.mkdir" +# X-* comment +ts_init_subtest "X-comment" TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex" [ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST -- cgit v1.2.3-55-g7522 From 88bc304ba815e21b09373cfec4e2f1f087482214 Mon Sep 17 00:00:00 2001 From: Carlos Santos Date: Wed, 3 Jul 2019 13:31:34 -0300 Subject: hwclock: use CMOS clock only if available - Add --disable-hwclock-cmos configuration argument - Add USE_HWCLOCK_CMOS (enabled by default for i386/x86_64) - Add define(USE_HWCLOCK_CMOS) - Compile hwclock-cmos.c only if USE_HWCLOCK_CMOS is true - Remove all unnecessary #ifdefs from hwclock-cmos.c - Add #ifdef USE_HWCLOCK_CMOS around the determine_clock_access_method() call in hwclock.c Signed-off-by: Carlos Santos --- configure.ac | 13 +++++++++++++ sys-utils/Makemodule.am | 7 +++++-- sys-utils/hwclock-cmos.c | 47 ++++++----------------------------------------- sys-utils/hwclock.c | 2 ++ 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/configure.ac b/configure.ac index 997b6388c..8aa2fed38 100644 --- a/configure.ac +++ b/configure.ac @@ -1517,6 +1517,19 @@ UL_REQUIRES_HAVE([hwclock], [io, linuxdummy], [ioperm iopl function or Linux]) AM_CONDITIONAL([BUILD_HWCLOCK], [test "x$build_hwclock" = xyes]) +AC_ARG_ENABLE([hwclock-cmos], + AS_HELP_STRING([--disable-hwclock-cmos], [do not use CMOS clock]), + [], [use_hwclock_cmos="$build_hwclock"] +) + +AS_IF([test "x$use_hwclock_cmos" = xyes], [ + AM_CONDITIONAL([USE_HWCLOCK_CMOS], [true]) + AC_DEFINE([USE_HWCLOCK_CMOS], [1], [Define to 1 if want to use CMOS clock.]) +],[ + AM_CONDITIONAL([USE_HWCLOCK_CMOS], [false]) +]) + + UL_BUILD_INIT([mkfs], [yes]) AM_CONDITIONAL([BUILD_MKFS], [test "x$build_mkfs" = xyes]) diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 7c118a6de..98e2cc29b 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -451,9 +451,12 @@ dist_man_MANS += \ PATHFILES += sys-utils/hwclock.8 hwclock_SOURCES = \ sys-utils/hwclock.c \ - sys-utils/hwclock.h \ - sys-utils/hwclock-cmos.c + sys-utils/hwclock.h hwclock_LDADD = $(LDADD) libcommon.la -lm +if USE_HWCLOCK_CMOS +hwclock_SOURCES += \ + sys-utils/hwclock-cmos.c +endif if LINUX hwclock_SOURCES += \ sys-utils/hwclock-rtc.c \ diff --git a/sys-utils/hwclock-cmos.c b/sys-utils/hwclock-cmos.c index a11f676b8..4d3e023d9 100644 --- a/sys-utils/hwclock-cmos.c +++ b/sys-utils/hwclock-cmos.c @@ -56,37 +56,13 @@ #include "pathnames.h" /* for inb, outb */ -#if defined(__i386__) || defined(__x86_64__) -# ifdef HAVE_SYS_IO_H -# include -# elif defined(HAVE_ASM_IO_H) -# include -# else -# undef __i386__ -# undef __x86_64__ -# warning "disable cmos access - no sys/io.h or asm/io.h" -static void outb(int a __attribute__((__unused__)), - int b __attribute__((__unused__))) -{ -} - -static int inb(int c __attribute__((__unused__))) -{ - return 0; -} -# endif /* __i386__ __x86_64__ */ +#ifdef HAVE_SYS_IO_H +# include +#elif defined(HAVE_ASM_IO_H) +# include #else -# warning "disable cmos access - not i386 or x86_64" -static void outb(int a __attribute__((__unused__)), - int b __attribute__((__unused__))) -{ -} - -static int inb(int c __attribute__((__unused__))) -{ - return 0; -} -#endif /* for inb, outb */ +# error "no sys/io.h or asm/io.h" +#endif /* HAVE_SYS_IO_H, HAVE_ASM_IO_H */ #include "hwclock.h" @@ -360,7 +336,6 @@ static int set_hardware_clock_cmos(const struct hwclock_control *ctl return 0; } -#if defined(__i386__) || defined(__x86_64__) # if defined(HAVE_IOPL) static int i386_iopl(const int level) { @@ -373,12 +348,6 @@ static int i386_iopl(const int level __attribute__ ((__unused__))) return ioperm(clock_ctl_addr, 2, 1); } # endif -#else -static int i386_iopl(const int level __attribute__ ((__unused__))) -{ - return IOPL_NOT_IMPLEMENTED; -} -#endif static int get_permissions_cmos(void) { @@ -412,9 +381,5 @@ static struct clock_ops cmos_interface = { */ struct clock_ops *probe_for_cmos_clock(void) { -#if defined(__i386__) || defined(__x86_64__) return &cmos_interface; -#else - return NULL; -#endif } diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index a2c5cc2a4..c01a86826 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -925,8 +925,10 @@ static void determine_clock_access_method(const struct hwclock_control *ctl) { ur = NULL; +#ifdef USE_HWCLOCK_CMOS if (ctl->directisa) ur = probe_for_cmos_clock(); +#endif #ifdef __linux__ if (!ur) ur = probe_for_rtc_clock(ctl); -- cgit v1.2.3-55-g7522 From c7eca69d6d89262c71b6d412f6b3a469fad07d7d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 15 Jul 2019 15:31:40 +0200 Subject: build-sys: add UL_REQUIRES_ARCH() Signed-off-by: Karel Zak --- m4/ul.m4 | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/m4/ul.m4 b/m4/ul.m4 index 9b3e73d22..e32af44a3 100644 --- a/m4/ul.m4 +++ b/m4/ul.m4 @@ -208,6 +208,46 @@ AC_DEFUN([UL_EXCLUDE_ARCH], [ fi ]) + + +dnl UL_REQUIRES_ARCH(NAME, ARCH, [VARSUFFIX = $1]) +dnl +dnl Modifies $build_ variable according to $enable_ and $host. The +dnl $enable_ could be "yes", "no" and "check". If build_ is "no" then +dnl all checks are skiped. +dnl +dnl The maybe a list, then at least one of the patterns in the list +dnl have to match. +dnl +dnl The default for $build_ and $enable_ could be overwrited by option $3. +dnl +AC_DEFUN([UL_REQUIRES_ARCH], [ + m4_define([suffix], m4_default([$3],$1)) + if test "x$[build_]suffix" != xno; then + AC_REQUIRE([AC_CANONICAL_HOST]) + [ul_archone_]suffix=no + m4_foreach([onearch], [$2], [ + case "$host" in #( + onearch) + [ul_archone_]suffix=yes ;; + esac + ])dnl + case $[enable_]suffix:$[ul_archone_]suffix in #( + no:*) + [build_]suffix=no ;; + yes:no) + AC_MSG_ERROR([$1 selected for unsupported architecture]);; + yes:*) + [build_]suffix=yes ;; + check:no) + AC_MSG_WARN([excluded for $host architecture; not building $1]) + [build_]suffix=no ;; + check:*) + [build_]suffix=yes ;; + esac + fi +]) + dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC, [VARSUFFIX=$1]) dnl dnl Modifies $build_ variable according to $enable_ and @@ -248,7 +288,7 @@ AC_DEFUN([UL_REQUIRES_HAVE], [ fi ]) -dnl UL_REQUIRES_HAVE(NAME, PROGRAM_PROLOGUE, PROGRAM_BODY, DESC, [VARSUFFIX=$1]) +dnl UL_REQUIRES_COMPILE(NAME, PROGRAM_PROLOGUE, PROGRAM_BODY, DESC, [VARSUFFIX=$1]) dnl dnl Modifies $build_ variable according to $enable_ and dnl ability compile AC_LANG_PROGRAM(, ). -- cgit v1.2.3-55-g7522 From b1062292066e0568adbbdbb104b7afdcc5dac25f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 15 Jul 2019 15:32:49 +0200 Subject: build-sys: improve hwclock CMOS dependences Let's use standard UL_* macros to check for dependencies (architectures and hwclock). Signed-off-by: Karel Zak --- configure.ac | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 8aa2fed38..3bec9769b 100644 --- a/configure.ac +++ b/configure.ac @@ -1516,17 +1516,16 @@ UL_BUILD_INIT([hwclock]) UL_REQUIRES_HAVE([hwclock], [io, linuxdummy], [ioperm iopl function or Linux]) AM_CONDITIONAL([BUILD_HWCLOCK], [test "x$build_hwclock" = xyes]) - -AC_ARG_ENABLE([hwclock-cmos], +AC_ARG_ENABLE([hwclock_cmos], AS_HELP_STRING([--disable-hwclock-cmos], [do not use CMOS clock]), - [], [use_hwclock_cmos="$build_hwclock"] -) - -AS_IF([test "x$use_hwclock_cmos" = xyes], [ - AM_CONDITIONAL([USE_HWCLOCK_CMOS], [true]) - AC_DEFINE([USE_HWCLOCK_CMOS], [1], [Define to 1 if want to use CMOS clock.]) -],[ - AM_CONDITIONAL([USE_HWCLOCK_CMOS], [false]) + [], [enable_hwclock_cmos=check] +) +UL_BUILD_INIT([hwclock_cmos]) +UL_REQUIRES_BUILD([hwclock_cmos], [hwclock]) +UL_REQUIRES_ARCH([hwclock_cmos], [i?86-*,x86_64*]) +AM_CONDITIONAL([USE_HWCLOCK_CMOS], [test "x$build_hwclock_cmos" = xyes]) +AS_IF([test "x$build_hwclock_cmos" = xyes ], [ + AC_DEFINE([USE_HWCLOCK_CMOS], [1], [Define to 1 if want to use CMOS clock.]) ]) -- cgit v1.2.3-55-g7522 From 7c643ed2855058657798d9e8e80701023de14a08 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 17 Jul 2019 12:11:38 +0200 Subject: libfdisk: don't use FAT as MBR The current libfdisk MBR detection is too weak, the result is that it reuses MBR from FAT. The correct behavior is to create a new MBR, wipe first sector (on write) and warn about obsolete FAT superblock. Reported-by: Mike Fleetwood Signed-off-by: Karel Zak --- libfdisk/src/context.c | 16 +++++++++++----- libfdisk/src/dos.c | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 770aa4d52..bc284f34e 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -619,14 +619,20 @@ static int fdisk_assign_fd(struct fdisk_context *cxt, int fd, if (fdisk_read_firstsector(cxt) < 0) goto fail; + /* warn about obsolete stuff on the device if we aren't in list-only */ + if (!fdisk_is_listonly(cxt) && fdisk_check_collisions(cxt) < 0) + goto fail; + fdisk_probe_labels(cxt); fdisk_apply_label_device_properties(cxt); - /* warn about obsolete stuff on the device if we aren't in - * list-only mode and there is not PT yet */ - if (!fdisk_is_listonly(cxt) && !fdisk_has_label(cxt) - && fdisk_check_collisions(cxt) < 0) - goto fail; + /* Don't report collision if there is already a valid partition table. + * The bootbits are wiped when we create a *new* partition table only. */ + if (fdisk_is_ptcollision(cxt) && fdisk_has_label(cxt)) { + cxt->pt_collision = 0; + free(cxt->collision); + cxt->collision = NULL; + } DBG(CXT, ul_debugobj(cxt, "initialized for %s [%s]", fname, readonly ? "READ-ONLY" : "READ-WRITE")); diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 6dc276e8a..bd964db15 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -814,6 +814,10 @@ static int dos_probe_label(struct fdisk_context *cxt) if (!mbr_is_valid_magic(cxt->firstsector)) return 0; + /* ignore disks with FAT */ + if (cxt->collision && strcmp(cxt->collision, "vfat") == 0) + return 0; + dos_init(cxt); get_partition_table_geometry(cxt, &h, &s); -- cgit v1.2.3-55-g7522 From cdb91409674cfb5d94a374b1e3b2bf1869ecfec7 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 17 Jul 2019 12:35:45 +0200 Subject: libblkid: do not interpret NTFS as MBR # mkntfs -Q -F /dev/sdc old version: # ./blkid -p /dev/sdc /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem" PTTYPE="dos" new version:  # ./blkid -p /dev/sdc /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem" Reported-by: Mike Fleetwood Signed-off-by: Karel Zak --- libblkid/src/partitions/dos.c | 7 +++++++ libblkid/src/superblocks/ntfs.c | 24 +++++++++++++++++++++++- libblkid/src/superblocks/superblocks.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c index 6c1b519f7..f8b0ee50d 100644 --- a/libblkid/src/partitions/dos.c +++ b/libblkid/src/partitions/dos.c @@ -14,6 +14,7 @@ #include #include "partitions.h" +#include "superblocks/superblocks.h" #include "aix.h" /* see superblocks/vfat.c */ @@ -222,6 +223,12 @@ static int probe_dos_pt(blkid_probe pr, goto nothing; } + /* Another false possitive is NTFS */ + if (blkid_probe_is_ntfs(pr) == 1) { + DBG(LOWPROBE, ul_debug("probably NTFS -- ignore")); + goto nothing; + } + /* * Ugly exception, if the device contains a valid LVM physical volume * and empty MBR (=no partition defined) then it's LVM and MBR should diff --git a/libblkid/src/superblocks/ntfs.c b/libblkid/src/superblocks/ntfs.c index 5ea2a454a..90a102f89 100644 --- a/libblkid/src/superblocks/ntfs.c +++ b/libblkid/src/superblocks/ntfs.c @@ -78,7 +78,7 @@ struct file_attribute { #define MFT_RECORD_ATTR_VOLUME_NAME 0x60 #define MFT_RECORD_ATTR_END 0xffffffff -static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag) +static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_info) { struct ntfs_super_block *ns; struct master_file_table_record *mft; @@ -174,6 +174,10 @@ static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag) if (memcmp(buf_mft, "FILE", 4)) return 1; + /* return if caller does not care about UUID and LABEL */ + if (!save_info) + return 0; + mft = (struct master_file_table_record *) buf_mft; attr_off = le16_to_cpu(mft->attrs_offset); @@ -211,6 +215,24 @@ static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag) return 0; } +static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag) +{ + return __probe_ntfs(pr, mag, 1); +} + +int blkid_probe_is_ntfs(blkid_probe pr) +{ + const struct blkid_idmag *mag = NULL; + int rc; + + rc = blkid_probe_get_idmag(pr, &ntfs_idinfo, NULL, &mag); + if (rc < 0) + return rc; /* error */ + if (rc != BLKID_PROBE_OK || !mag) + return 0; + + return __probe_ntfs(pr, mag, 0) == 0 ? 1 : 0; +} const struct blkid_idinfo ntfs_idinfo = { diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h index 3313d0245..59682c86d 100644 --- a/libblkid/src/superblocks/superblocks.h +++ b/libblkid/src/superblocks/superblocks.h @@ -109,5 +109,6 @@ extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name, const unsigned char *data, size_t len, int enc); extern int blkid_probe_is_bitlocker(blkid_probe pr); +extern int blkid_probe_is_ntfs(blkid_probe pr); #endif /* _BLKID_SUPERBLOCKS_H */ -- cgit v1.2.3-55-g7522 From 1ace839781b73517790f714fbd9c9c48e2297148 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 17 Jul 2019 12:42:39 +0200 Subject: libfdisk: don't use NTFS as MBR Same as 7c643ed2855058657798d9e8e80701023de14a08. Signed-off-by: Karel Zak --- libfdisk/src/dos.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index bd964db15..fc5bcc651 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -815,7 +815,9 @@ static int dos_probe_label(struct fdisk_context *cxt) return 0; /* ignore disks with FAT */ - if (cxt->collision && strcmp(cxt->collision, "vfat") == 0) + if (cxt->collision && + (strcmp(cxt->collision, "vfat") == 0 || + strcmp(cxt->collision, "ntfs") == 0)) return 0; dos_init(cxt); -- cgit v1.2.3-55-g7522 From 79f37ec4e1ab65664a2930793f497b288563e907 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 19 Jul 2019 13:35:11 +0200 Subject: libfdisk: Fix double free of *_chs strings in fdisk_partition __copy_partition doesn't duplicate these strings which leads to occasional double free. Signed-off-by: Vojtech Trefny --- libfdisk/src/partition.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 05474a041..55ce1ca5c 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -100,6 +100,10 @@ static struct fdisk_partition *__copy_partition(struct fdisk_partition *o) n->fsuuid = strdup(o->fsuuid); if (o->fslabel) n->fslabel = strdup(o->fslabel); + if (o->start_chs) + n->start_chs = strdup(o->start_chs); + if (o->end_chs) + n->end_chs = strdup(o->end_chs); return n; } -- cgit v1.2.3-55-g7522 From c64d452b3eb85fe55e238144082247b05cc143ea Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Jul 2019 11:10:30 +0200 Subject: fstrim: fix systemd service protection ProtectHome=yes makes /home inaccessible, but we need to open the directories (mountpoints) read-only. Addresses: https://github.com/karelzak/util-linux/issues/824 Signed-off-by: Karel Zak --- sys-utils/fstrim.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-utils/fstrim.service.in b/sys-utils/fstrim.service.in index 516023ed8..2a8dc1d3a 100644 --- a/sys-utils/fstrim.service.in +++ b/sys-utils/fstrim.service.in @@ -6,7 +6,7 @@ Documentation=man:fstrim(8) Type=oneshot ExecStart=@sbindir@/fstrim --fstab --verbose --quiet ProtectSystem=strict -ProtectHome=yes +ProtectHome=read-only PrivateDevices=no PrivateNetwork=yes PrivateUsers=no -- cgit v1.2.3-55-g7522 From 1768d77c18a4c892adb985870438325496d57f83 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Jul 2019 11:49:45 +0200 Subject: libblkid: (drbd) fix comment formatting ... to avoid misinterpretation by gtk-docs. Signed-off-by: Karel Zak --- libblkid/src/superblocks/drbd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c index 000a34879..f3601864e 100644 --- a/libblkid/src/superblocks/drbd.c +++ b/libblkid/src/superblocks/drbd.c @@ -70,8 +70,9 @@ struct md_on_disk_08 { uint32_t bm_bytes_per_bit; uint32_t reserved_u32[4]; - /** Unnecessary for libblkid ** - * char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)]; */ + /* Unnecessary for libblkid ** + * char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)]; + */ }; /* @@ -117,7 +118,7 @@ struct meta_data_on_disk_9 { struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX]; uint64_t history_uuids[HISTORY_UUIDS]; - /** Unnecessary for libblkid ** + /* Unnecessary for libblkid ** * char padding[0] __attribute__((aligned(4096))); */ } __attribute__((packed)); -- cgit v1.2.3-55-g7522 From 10c39f03a1e70cf2a4b8e0301784174ac5730251 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Jul 2019 12:09:38 +0200 Subject: libfdisk: improve partition copy on resize It seems pretty fragile to copy also reference counting and reference to table list. Addresses: https://github.com/karelzak/util-linux/pull/822 Signed-off-by: Karel Zak --- libfdisk/src/partition.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 55ce1ca5c..80a43ffde 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -85,7 +85,13 @@ static struct fdisk_partition *__copy_partition(struct fdisk_partition *o) if (!n) return NULL; + memcpy(n, o, sizeof(*n)); + + /* do not copy reference to lists, etc.*/ + n->refcount = 1; + INIT_LIST_HEAD(&n->parts); + if (n->type) fdisk_ref_parttype(n->type); if (o->name) -- cgit v1.2.3-55-g7522 From 94dbb322737524027a55e6ed5646dc69c5ed9e5b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Jul 2019 16:04:51 +0200 Subject: libsmartcols: cleanup and extend padding functionality LIBSMARTCOLS_DEBUG_PADDING=on in the next examples forces libsmartcols print '.' as a padding char. See line "ffff" in the exmaples. * default output is to fill all except last cell $ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null NAME.. ......NUM STRINGS STRINGS aaaa.. ........0 aaaa... aaaa bbb... ......100 bbb.... bbb ccccc. .......21 ccccc.. ccccc dddddd ........3 dddddd. dddddd ee.... ......411 ee..... ee ffff.. .....5111 ....... gggggg 678993321 gggggg. gggggg hhh... ..7666666 hhh.... hhh * scols_table_enable_minout() minimizes output for tailing empty cells, example: $ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --minout --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null NAME.. ......NUM STRINGS STRINGS aaaa.. ........0 aaaa... aaaa bbb... ......100 bbb.... bbb ccccc. .......21 ccccc.. ccccc dddddd ........3 dddddd. dddddd ee.... ......411 ee..... ee ffff.. .....5111 gggggg 678993321 gggggg. gggggg hhh... ..7666666 hhh.... hhh * cleanup up scols_table_enable_maxout() use, example: $ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --maxout --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null NAME.............. ..................NUM STRINGS............ STRINGS............ aaaa.............. ....................0 aaaa............... aaaa............... bbb............... ..................100 bbb................ bbb................ ccccc............. ...................21 ccccc.............. ccccc.............. dddddd............ ....................3 dddddd............. dddddd............. ee................ ..................411 ee................. ee................. ffff.............. .................5111 ................... ................... gggggg............ ............678993321 gggggg............. gggggg............. hhh............... ..............7666666 hhh................ hhh................ Note that we cannot make scols_table_enable_minout() default because for example "column --table" is pretty commonly used with non-blank columns separator and in this case all cells has to be filled. $ echo -e "aa,b,ccc\na,,\naaa,bbb,ccc" | column --table --separator ',' --output-separator '|' aa |b |ccc a | | aaa|bbb|ccc Addresses: https://github.com/karelzak/util-linux/issues/826 Signed-off-by: Karel Zak --- libsmartcols/docs/libsmartcols-sections.txt | 3 + libsmartcols/samples/fromfile.c | 11 +++- libsmartcols/src/libsmartcols.h.in | 3 + libsmartcols/src/libsmartcols.sym | 6 ++ libsmartcols/src/print.c | 81 +++++++++++++++++++++++---- libsmartcols/src/smartcolsP.h | 1 + libsmartcols/src/table.c | 68 +++++++++++++++++++++- tests/expected/lsblk/lsblk-simple-lvm-vendor | 38 ++++++------- tests/expected/lsblk/lsblk-simple-nvme-vendor | 22 ++++---- 9 files changed, 188 insertions(+), 45 deletions(-) diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt index 72c4ab866..4f3178b3a 100644 --- a/libsmartcols/docs/libsmartcols-sections.txt +++ b/libsmartcols/docs/libsmartcols-sections.txt @@ -132,6 +132,7 @@ scols_table_enable_export scols_table_enable_header_repeat scols_table_enable_json scols_table_enable_maxout +scols_table_enable_minout scols_table_enable_noheadings scols_table_enable_nolinesep scols_table_enable_nowrap @@ -155,6 +156,7 @@ scols_table_is_export scols_table_is_header_repeat scols_table_is_json scols_table_is_maxout +scols_table_is_minout scols_table_is_noheadings scols_table_is_noencoding scols_table_is_nolinesep @@ -165,6 +167,7 @@ scols_table_move_column scols_table_new_column scols_table_new_line scols_table_next_column +scols_table_set_columns_iter scols_table_next_line scols_table_reduce_termwidth scols_table_remove_column diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c index c1ab728fd..35d85489b 100644 --- a/libsmartcols/samples/fromfile.c +++ b/libsmartcols/samples/fromfile.c @@ -151,7 +151,8 @@ static int parse_column_data(FILE *f, struct libscols_table *tb, int col) if (!ln) break; - scols_line_set_data(ln, col, str); + if (str && *str) + scols_line_set_data(ln, col, str); } free(str); @@ -204,6 +205,7 @@ static void __attribute__((__noreturn__)) usage(void) "\n %s [options] ...\n\n", program_invocation_short_name); fputs(" -m, --maxout fill all terminal width\n", out); + fputs(" -M, --minout minimize tailing padding\n", out); fputs(" -c, --column column definition\n", out); fputs(" -n, --nlines number of lines\n", out); fputs(" -J, --json JSON output format\n", out); @@ -227,6 +229,7 @@ int main(int argc, char *argv[]) static const struct option longopts[] = { { "maxout", 0, NULL, 'm' }, + { "minout", 0, NULL, 'M' }, { "column", 1, NULL, 'c' }, { "nlines", 1, NULL, 'n' }, { "width", 1, NULL, 'w' }, @@ -242,6 +245,7 @@ int main(int argc, char *argv[]) static const ul_excl_t excl[] = { /* rows and cols in ASCII order */ { 'E', 'J', 'r' }, + { 'M', 'm' }, { 0 } }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; @@ -253,7 +257,7 @@ int main(int argc, char *argv[]) if (!tb) err(EXIT_FAILURE, "failed to create output table"); - while((c = getopt_long(argc, argv, "hCc:Ei:Jmn:p:rw:", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "hCc:Ei:JMmn:p:rw:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -285,6 +289,9 @@ int main(int argc, char *argv[]) case 'm': scols_table_enable_maxout(tb, TRUE); break; + case 'M': + scols_table_enable_minout(tb, TRUE); + break; case 'r': scols_table_enable_raw(tb, TRUE); break; diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index bd47f7898..d4be9969a 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -243,6 +243,7 @@ extern int scols_table_is_header_repeat(const struct libscols_table *tb); extern int scols_table_is_empty(const struct libscols_table *tb); extern int scols_table_is_export(const struct libscols_table *tb); extern int scols_table_is_maxout(const struct libscols_table *tb); +extern int scols_table_is_minout(const struct libscols_table *tb); extern int scols_table_is_nowrap(const struct libscols_table *tb); extern int scols_table_is_nolinesep(const struct libscols_table *tb); extern int scols_table_is_tree(const struct libscols_table *tb); @@ -256,6 +257,7 @@ extern int scols_table_enable_noheadings(struct libscols_table *tb, int enable); extern int scols_table_enable_header_repeat(struct libscols_table *tb, int enable); extern int scols_table_enable_export(struct libscols_table *tb, int enable); extern int scols_table_enable_maxout(struct libscols_table *tb, int enable); +extern int scols_table_enable_minout(struct libscols_table *tb, int enable); extern int scols_table_enable_nowrap(struct libscols_table *tb, int enable); extern int scols_table_enable_nolinesep(struct libscols_table *tb, int enable); extern int scols_table_enable_noencoding(struct libscols_table *tb, int enable); @@ -272,6 +274,7 @@ extern int scols_table_remove_columns(struct libscols_table *tb); extern int scols_table_move_column(struct libscols_table *tb, struct libscols_column *pre, struct libscols_column *cl); extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags); extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl); +extern int scols_table_set_columns_iter(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column *cl); extern const char *scols_table_get_column_separator(const struct libscols_table *tb); extern const char *scols_table_get_line_separator(const struct libscols_table *tb); extern size_t scols_table_get_ncols(const struct libscols_table *tb); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index e318c9054..99353be80 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -194,3 +194,9 @@ SMARTCOLS_2.34 { scols_symbols_set_group_last_child; scols_symbols_set_group_middle_child; } SMARTCOLS_2.33; + +SMARTCOLS_2.35 { + scols_table_enable_minout; + scols_table_is_minout; + scols_table_set_columns_iter; +} SMARTCOLS_2.34; diff --git a/libsmartcols/src/print.c b/libsmartcols/src/print.c index 986af153c..c92154219 100644 --- a/libsmartcols/src/print.c +++ b/libsmartcols/src/print.c @@ -50,6 +50,43 @@ #define want_repeat_header(tb) (!(tb)->header_repeat || (tb)->header_next <= (tb)->termlines_used) +static int is_next_columns_empty( + struct libscols_table *tb, + struct libscols_column *cl, + struct libscols_line *ln) +{ + struct libscols_iter itr; + + if (!tb || !cl) + return 0; + if (is_last_column(cl)) + return 1; + if (!ln) + return 0; + + scols_reset_iter(&itr, SCOLS_ITER_FORWARD); + scols_table_set_columns_iter(tb, &itr, cl); + + /* skip current column */ + scols_table_next_column(tb, &itr, &cl); + + while (scols_table_next_column(tb, &itr, &cl) == 0) { + struct libscols_cell *ce; + const char *data = NULL; + + if (scols_column_is_hidden(cl)) + continue; + if (scols_column_is_tree(cl)) + return 0; + + ce = scols_line_get_cell(ln, cl->seqnum); + if (ce) + data = scols_cell_get_data(ce); + if (data && *data) + return 0; + } + return 1; +} /* returns pointer to the end of used data */ static int tree_ascii_art_to_buffer(struct libscols_table *tb, @@ -216,14 +253,20 @@ static void print_empty_cell(struct libscols_table *tb, } } - if (is_last_column(cl)) + /* minout -- don't fill */ + if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) + return; + + /* default -- fill except last column */ + if (!scols_table_is_maxout(tb) && is_last_column(cl)) return; /* fill rest of cell with space */ for(; len_pad < cl->width; ++len_pad) fputs(cellpadding_symbol(tb), tb->out); - fputs(colsep(tb), tb->out); + if (!is_last_column(cl)) + fputs(colsep(tb), tb->out); } @@ -367,13 +410,21 @@ static int print_pending_data( fputs(UL_COLOR_RESET, tb->out); free(data); - if (is_last_column(cl)) + /* minout -- don't fill */ + if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) return 0; - for (i = len; i < width; i++) - fputs(cellpadding_symbol(tb), tb->out); /* padding */ + /* default -- fill except last column */ + if (!scols_table_is_maxout(tb) && is_last_column(cl)) + return 0; + + /* fill rest of cell with space */ + for(i = len; i < width; i++) + fputs(cellpadding_symbol(tb), tb->out); + + if (!is_last_column(cl)) + fputs(colsep(tb), tb->out); - fputs(colsep(tb), tb->out); /* columns separator */ return 0; err: free(data); @@ -491,7 +542,7 @@ static int print_data(struct libscols_table *tb, data = NULL; } - if (data) { + if (data && *data) { if (scols_column_is_right(cl)) { if (color) fputs(color, tb->out); @@ -518,16 +569,24 @@ static int print_data(struct libscols_table *tb, } else fputs(data, tb->out); } - for (i = len; i < width; i++) - fputs(cellpadding_symbol(tb), tb->out); /* padding */ - if (is_last) + /* minout -- don't fill */ + if (scols_table_is_minout(tb) && is_next_columns_empty(tb, cl, ln)) return 0; + /* default -- fill except last column */ + if (!scols_table_is_maxout(tb) && is_last) + return 0; + + /* fill rest of cell with space */ + for(i = len; i < width; i++) + fputs(cellpadding_symbol(tb), tb->out); + if (len > width && !scols_column_is_trunc(cl)) { DBG(COL, ul_debugobj(cl, "*** data len=%zu > column width=%zu", len, width)); print_newline_padding(tb, cl, ln, buffer_get_size(buf)); /* next column starts on next line */ - } else + + } else if (!is_last) fputs(colsep(tb), tb->out); /* columns separator */ return 0; diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index 3653eda07..e745a05a4 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -238,6 +238,7 @@ struct libscols_table { padding_debug :1, /* output visible padding chars */ is_dummy_print :1, /* printing used for width calcualion only */ maxout :1, /* maximize output */ + minout :1, /* minimize output (mutually exclusive to maxout) */ header_repeat :1, /* print header after libscols_table->termheight */ header_printed :1, /* header already printed */ priv_symbols :1, /* default private symbols */ diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 944c1e593..e14c82b1b 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -474,6 +474,33 @@ int scols_table_next_column(struct libscols_table *tb, return rc; } +/** + * scols_table_set_columns_iter: + * @tb: tab pointer + * @itr: iterator + * @cl: tab entry + * + * Sets @iter to the position of @cl in the file @tb. + * + * Returns: 0 on success, negative number in case of error. + */ +int scols_table_set_columns_iter( + struct libscols_table *tb, + struct libscols_iter *itr, + struct libscols_column *cl) +{ + if (!tb || !itr || !cl) + return -EINVAL; + + if (cl->table != tb) + return -EINVAL; + + SCOLS_ITER_INIT(itr, &tb->tb_columns); + itr->p = &cl->cl_columns; + + return 0; +} + /** * scols_table_get_ncols: * @tb: table @@ -1133,19 +1160,45 @@ int scols_table_enable_header_repeat(struct libscols_table *tb, int enable) * @enable: 1 or 0 * * The extra space after last column is ignored by default. The output - * maximization use the extra space for all columns. + * maximization add padding for all columns. + * + * This setting is mutually exclusive to cols_table_enable_minout(). * * Returns: 0 on success, negative number in case of an error. */ int scols_table_enable_maxout(struct libscols_table *tb, int enable) { - if (!tb) + if (!tb || tb->minout) return -EINVAL; + DBG(TAB, ul_debugobj(tb, "maxout: %s", enable ? "ENABLE" : "DISABLE")); tb->maxout = enable ? 1 : 0; return 0; } +/** + * scols_table_enable_minout: + * @tb: table + * @enable: 1 or 0 + * + * Force library to terminate line after last column with data. The extra + * padding is not added to the empty cells at the end of the line. The default is fill + * tailing empty cells except the last line cell. + * + * This setting is mutually exclusive to cols_table_enable_maxout(). + * + * Returns: 0 on success, negative number in case of an error. + */ +int scols_table_enable_minout(struct libscols_table *tb, int enable) +{ + if (!tb || tb->maxout) + return -EINVAL; + + DBG(TAB, ul_debugobj(tb, "minout: %s", enable ? "ENABLE" : "DISABLE")); + tb->minout = enable ? 1 : 0; + return 0; +} + /** * scols_table_enable_nowrap: * @tb: table @@ -1315,6 +1368,17 @@ int scols_table_is_maxout(const struct libscols_table *tb) return tb->maxout; } +/** + * scols_table_is_minout + * @tb: table + * + * Returns: 1 if output minimization is enabled or 0 + */ +int scols_table_is_minout(const struct libscols_table *tb) +{ + return tb->minout; +} + /** * scols_table_is_tree: * @tb: table diff --git a/tests/expected/lsblk/lsblk-simple-lvm-vendor b/tests/expected/lsblk/lsblk-simple-lvm-vendor index 591c703af..24ee97dd4 100644 --- a/tests/expected/lsblk/lsblk-simple-lvm-vendor +++ b/tests/expected/lsblk/lsblk-simple-lvm-vendor @@ -1,22 +1,22 @@ NAME MODEL VENDOR REV -loop0 -`-vg_foo.4059-lv_foo.4059 -loop1 -`-vg_foo.4059-lv_foo.4059 -loop2 -`-vg_foo.4059-lv_foo.4059 -loop3 -`-vg_foo.4059-lv_foo.4059 +loop0 +`-vg_foo.4059-lv_foo.4059 +loop1 +`-vg_foo.4059-lv_foo.4059 +loop2 +`-vg_foo.4059-lv_foo.4059 +loop3 +`-vg_foo.4059-lv_foo.4059 sda KINGSTON SH103S3 ATA BBF0 -|-sda1 -|-sda2 -|-sda3 -|-sda4 -|-sda5 -`-sda6 +|-sda1 +|-sda2 +|-sda3 +|-sda4 +|-sda5 +`-sda6 sdb WDC WD800JD-00MS ATA 1E01 -`-sdb1 -nvme0n1 KINGSTON SKC1000240G -|-nvme0n1p1 -|-nvme0n1p2 -`-nvme0n1p3 +`-sdb1 +nvme0n1 KINGSTON SKC1000240G +|-nvme0n1p1 +|-nvme0n1p2 +`-nvme0n1p3 diff --git a/tests/expected/lsblk/lsblk-simple-nvme-vendor b/tests/expected/lsblk/lsblk-simple-nvme-vendor index 69e972a31..2a0a90514 100644 --- a/tests/expected/lsblk/lsblk-simple-nvme-vendor +++ b/tests/expected/lsblk/lsblk-simple-nvme-vendor @@ -1,14 +1,14 @@ NAME MODEL VENDOR REV sda KINGSTON SH103S3 ATA BBF0 -|-sda1 -|-sda2 -|-sda3 -|-sda4 -|-sda5 -`-sda6 +|-sda1 +|-sda2 +|-sda3 +|-sda4 +|-sda5 +`-sda6 sdb WDC WD800JD-00MS ATA 1E01 -`-sdb1 -nvme0n1 KINGSTON SKC1000240G -|-nvme0n1p1 -|-nvme0n1p2 -`-nvme0n1p3 +`-sdb1 +nvme0n1 KINGSTON SKC1000240G +|-nvme0n1p1 +|-nvme0n1p2 +`-nvme0n1p3 -- cgit v1.2.3-55-g7522 From fc970a0947469b2a7fe80af704e9fca307116c0f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Jul 2019 16:26:48 +0200 Subject: tests: (libsmartcols) add padding tests Signed-off-by: Karel Zak --- .../expected/libsmartcols/fromfile-padding-default | 11 ++++++ .../expected/libsmartcols/fromfile-padding-maxout | 11 ++++++ .../expected/libsmartcols/fromfile-padding-minout | 11 ++++++ tests/ts/libsmartcols/files/data-string-empty | 10 +++++ tests/ts/libsmartcols/fromfile | 46 ++++++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 tests/expected/libsmartcols/fromfile-padding-default create mode 100644 tests/expected/libsmartcols/fromfile-padding-maxout create mode 100644 tests/expected/libsmartcols/fromfile-padding-minout create mode 100644 tests/ts/libsmartcols/files/data-string-empty diff --git a/tests/expected/libsmartcols/fromfile-padding-default b/tests/expected/libsmartcols/fromfile-padding-default new file mode 100644 index 000000000..f935be267 --- /dev/null +++ b/tests/expected/libsmartcols/fromfile-padding-default @@ -0,0 +1,11 @@ +NAME.. ......NUM STRINGS STRINGS +aaaa.. ........0 aaaa... aaaa +bbb... ......100 bbb.... bbb +ccccc. .......21 ccccc.. ccccc +dddddd ........3 dddddd. dddddd +ee.... ......411 ee..... ee +ffff.. .....5111 ....... +gggggg 678993321 gggggg. gggggg +hhh... ..7666666 hhh.... hhh +iiiiii .....8765 iiiiii. iiiiii +jj.... ...987456 jj..... jj diff --git a/tests/expected/libsmartcols/fromfile-padding-maxout b/tests/expected/libsmartcols/fromfile-padding-maxout new file mode 100644 index 000000000..3f73ce38b --- /dev/null +++ b/tests/expected/libsmartcols/fromfile-padding-maxout @@ -0,0 +1,11 @@ +NAME.............. ..................NUM STRINGS............ STRINGS............ +aaaa.............. ....................0 aaaa............... aaaa............... +bbb............... ..................100 bbb................ bbb................ +ccccc............. ...................21 ccccc.............. ccccc.............. +dddddd............ ....................3 dddddd............. dddddd............. +ee................ ..................411 ee................. ee................. +ffff.............. .................5111 ................... ................... +gggggg............ ............678993321 gggggg............. gggggg............. +hhh............... ..............7666666 hhh................ hhh................ +iiiiii............ .................8765 iiiiii............. iiiiii............. +jj................ ...............987456 jj................. jj................. diff --git a/tests/expected/libsmartcols/fromfile-padding-minout b/tests/expected/libsmartcols/fromfile-padding-minout new file mode 100644 index 000000000..ac8eabc93 --- /dev/null +++ b/tests/expected/libsmartcols/fromfile-padding-minout @@ -0,0 +1,11 @@ +NAME.. ......NUM STRINGS STRINGS +aaaa.. ........0 aaaa... aaaa +bbb... ......100 bbb.... bbb +ccccc. .......21 ccccc.. ccccc +dddddd ........3 dddddd. dddddd +ee.... ......411 ee..... ee +ffff.. .....5111 +gggggg 678993321 gggggg. gggggg +hhh... ..7666666 hhh.... hhh +iiiiii .....8765 iiiiii. iiiiii +jj.... ...987456 jj..... jj diff --git a/tests/ts/libsmartcols/files/data-string-empty b/tests/ts/libsmartcols/files/data-string-empty new file mode 100644 index 000000000..1f8ad34e5 --- /dev/null +++ b/tests/ts/libsmartcols/files/data-string-empty @@ -0,0 +1,10 @@ +aaaa +bbb +ccccc +dddddd +ee + +gggggg +hhh +iiiiii +jj diff --git a/tests/ts/libsmartcols/fromfile b/tests/ts/libsmartcols/fromfile index 274081ea0..20994d661 100755 --- a/tests/ts/libsmartcols/fromfile +++ b/tests/ts/libsmartcols/fromfile @@ -114,6 +114,52 @@ ts_run $TESTPROG --nlines 10 --maxout --width 80\ >> $TS_OUTPUT 2>&1 ts_finalize_subtest +ts_init_subtest "padding-default" +export LIBSMARTCOLS_DEBUG_PADDING=on +ts_run $TESTPROG --nlines 10 --width 80 \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-number \ + --column $TS_SELF/files/col-string \ + --column $TS_SELF/files/col-string \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-number \ + $TS_SELF/files/data-string-empty \ + $TS_SELF/files/data-string-empty \ + >> $TS_OUTPUT 2> /dev/null +ts_finalize_subtest + +ts_init_subtest "padding-maxout" +export LIBSMARTCOLS_DEBUG_PADDING=on +ts_run $TESTPROG --nlines 10 --width 80 \ + --maxout \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-number \ + --column $TS_SELF/files/col-string \ + --column $TS_SELF/files/col-string \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-number \ + $TS_SELF/files/data-string-empty \ + $TS_SELF/files/data-string-empty \ + >> $TS_OUTPUT 2> /dev/null +ts_finalize_subtest + +ts_init_subtest "padding-minout" +export LIBSMARTCOLS_DEBUG_PADDING=on +ts_run $TESTPROG --nlines 10 --width 80 \ + --minout \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-number \ + --column $TS_SELF/files/col-string \ + --column $TS_SELF/files/col-string \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-number \ + $TS_SELF/files/data-string-empty \ + $TS_SELF/files/data-string-empty \ + >> $TS_OUTPUT 2> /dev/null +ts_finalize_subtest + +unset LIBSMARTCOLS_DEBUG_PADDING + ts_init_subtest "strictwidth" ts_run $TESTPROG --nlines 10 \ --column $TS_SELF/files/col-name \ -- cgit v1.2.3-55-g7522 From 7ea0907364e626eaed4441355f00fc6d79fcd3db Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Jul 2019 16:35:20 +0200 Subject: tests: (fdisk) update padding in output Signed-off-by: Karel Zak --- tests/expected/fdisk/sunlabel | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/expected/fdisk/sunlabel b/tests/expected/fdisk/sunlabel index 47b5e756b..5ada4fab1 100644 --- a/tests/expected/fdisk/sunlabel +++ b/tests/expected/fdisk/sunlabel @@ -18,7 +18,7 @@ I/O size (minimum/optimal): 512 bytes / bytes Disklabel type: sun Device Start End Cylinders Size Id Type Flags -1 1 128 129 4M 83 Linux native +1 1 128 129 4M 83 Linux native Set partition sysid df75defdb97fbd56222aed18631a22d0 sunlabel.img Disk : 10 MiB, 10485760 bytes, 20480 sectors @@ -29,7 +29,7 @@ I/O size (minimum/optimal): 512 bytes / bytes Disklabel type: sun Device Start End Cylinders Size Id Type Flags -1 1 128 129 4M 4 SunOS usr +1 1 128 129 4M 4 SunOS usr Set first partition readonly da23f66698d9a553162887621d4c7490 sunlabel.img Disk : 10 MiB, 10485760 bytes, 20480 sectors @@ -75,6 +75,6 @@ Disklabel type: sun Device Start End Cylinders Size Id Type Flags 1 1 128 129 4M 4 SunOS usr ur -2 129 325 198 6.1M 83 Linux native +2 129 325 198 6.1M 83 Linux native Delete all partitions 502ba7a0cfdce2849c3a99881f0590c3 sunlabel.img -- cgit v1.2.3-55-g7522 From 0675f52ab5014b8c0ef5c1a2763b8526e8b03eaa Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 20 Jul 2019 11:11:01 +0100 Subject: last: replace strncat() with more robust mem2strcpy() Signed-off-by: Sami Kerola --- login-utils/last.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/login-utils/last.c b/login-utils/last.c index 2f7d9d48f..1b1a74191 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -394,8 +394,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t /* * uucp and ftp have special-type entries */ - utline[0] = 0; - strncat(utline, p->ut_line, sizeof(utline) - 1); + mem2strcpy(utline, p->ut_line, sizeof(p->ut_line), sizeof(utline)); if (strncmp(utline, "ftp", 3) == 0 && isdigit(utline[3])) utline[3] = 0; if (strncmp(utline, "uucp", 4) == 0 && isdigit(utline[4])) -- cgit v1.2.3-55-g7522 From 1aaee548e3cbe00a084103792b03605182eefd04 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 21 Jul 2019 19:12:03 +0100 Subject: login: simplify string handling Signed-off-by: Sami Kerola --- login-utils/login.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index ce112b54e..6b9d27e3e 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -1355,10 +1355,7 @@ int main(int argc, char **argv) /* if the shell field has a space: treat it like a shell script */ if (strchr(pwd->pw_shell, ' ')) { - buff = xmalloc(strlen(pwd->pw_shell) + 6); - - strcpy(buff, "exec "); - strcat(buff, pwd->pw_shell); + xasprintf(&buff, "exec %s", pwd->pw_shell); childArgv[childArgc++] = "/bin/sh"; childArgv[childArgc++] = "-sh"; childArgv[childArgc++] = "-c"; -- cgit v1.2.3-55-g7522 From 2a952555d2b56ffaf461465139255c94bf6a49a5 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 21 Jul 2019 21:36:28 +0100 Subject: agetty: simplify code in dolog() preprocessor blocks Aim is to make dolog() a lot more readable and understandable, with downside of when (rarely?) USE_SYSLOG it not defined the function will use a bit more space from stack. I think that is price well worth paying. Signed-off-by: Sami Kerola --- term-utils/agetty.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 96bf41b36..703fb9fd7 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -2391,46 +2391,40 @@ static void list_speeds(void) * Will be used by log_err() and log_warn() therefore * it takes a format as well as va_list. */ -#define str2cpy(b,s1,s2) strcat(strcpy(b,s1),s2) - -static void dolog(int priority, const char *fmt, va_list ap) -{ -#ifndef USE_SYSLOG - int fd; +static void dolog(int priority +#ifndef USE_SYSLOG + __attribute__((__unused__)) #endif - char buf[BUFSIZ]; - char *bp; - + , const char *fmt, va_list ap) +{ +#ifdef USE_SYSLOG /* * If the diagnostic is reported via syslog(3), the process name is * automatically prepended to the message. If we write directly to * /dev/console, we must prepend the process name ourselves. */ -#ifdef USE_SYSLOG - buf[0] = '\0'; - bp = buf; -#else - str2cpy(buf, program_invocation_short_name, ": "); - bp = buf + strlen(buf); -#endif /* USE_SYSLOG */ - vsnprintf(bp, sizeof(buf)-strlen(buf), fmt, ap); - - /* - * Write the diagnostic directly to /dev/console if we do not use the - * syslog(3) facility. - */ -#ifdef USE_SYSLOG openlog(program_invocation_short_name, LOG_PID, LOG_AUTHPRIV); - syslog(priority, "%s", buf); + vsyslog(priority, fmt, ap); closelog(); #else + /* + * Write the diagnostic directly to /dev/console if we do not use + * the syslog(3) facility. + */ + char buf[BUFSIZ]; + char new_fmt[BUFSIZ]; + int fd; + + snprintf(new_fmt, sizeof(new_fmt), "%s: %s\r\n", + program_invocation_short_name, fmt); /* Terminate with CR-LF since the console mode is unknown. */ - strcat(bp, "\r\n"); + vsnprintf(buf, sizeof(buf), new_fmt, ap); + if ((fd = open("/dev/console", 1)) >= 0) { write_all(fd, buf, strlen(buf)); close(fd); } -#endif /* USE_SYSLOG */ +#endif /* USE_SYSLOG */ } static void exit_slowly(int code) -- cgit v1.2.3-55-g7522 From 8bad603ae0a87f58cc79eb590a9fd7c68514009a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 25 Jul 2019 12:23:59 +0200 Subject: lscpu: (man) add note about cache sizes Addresses: https://github.com/karelzak/util-linux/issues/827 Signed-off-by: Karel Zak --- sys-utils/lscpu.1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys-utils/lscpu.1 b/sys-utils/lscpu.1 index e82fa4320..cd509f72b 100644 --- a/sys-utils/lscpu.1 +++ b/sys-utils/lscpu.1 @@ -33,6 +33,11 @@ specified, \fBlscpu\fP prints the column but does not provide any data for it. The default output formatting on terminal maybe optimized for better readability. The output for non-terminals (e.g. pipes) is never affected by this optimization and it is always in "Field: data\\n" format. +.sp +The cache sizes are reported as summary from all CPUs. The versions before +v2.34 reported per-core sizes, but this output was confusing due to complicated +CPUs topology and the way how caches are shared between CPUs. For more details +about caches see \fB\-\-cache\fP. .SS COLUMNS Note that topology elements (core, socket, etc.) use a sequential unique ID starting from zero, but CPU logical numbers follow the kernel where there is -- cgit v1.2.3-55-g7522 From b5f376d11d9f9e25be32920705bd5ee54684ca36 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 27 Jul 2019 18:55:01 +0100 Subject: lscpu: prefer memcpy() to manual pointer arithmetic With pointer arithmetic clang address sanitizer gives following error this change addresses. Notice the following happens only when running as root. sys-utils/lscpu-dmi.c:83:14: runtime error: load of misaligned address 0x55a1d62f3d1d for type 'const uint16_t' (aka 'const unsigned short'), which requires 2 byte alignment Signed-off-by: Sami Kerola --- sys-utils/lscpu-dmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c index 29bd2e4fc..82d8ed443 100644 --- a/sys-utils/lscpu-dmi.c +++ b/sys-utils/lscpu-dmi.c @@ -80,7 +80,7 @@ static void to_dmi_header(struct dmi_header *h, uint8_t *data) { h->type = data[0]; h->length = data[1]; - h->handle = WORD(data + 2); + memcpy(&h->handle, data + 2, sizeof(h->handle)); h->data = data; } -- cgit v1.2.3-55-g7522 From 325bfd53e889fd52f240e4bcbd690b03dddc7570 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Mon, 29 Jul 2019 01:24:29 +0000 Subject: column: fix outputing empty column at the end of line The following commands manifests the problem. In old versions before commit 4762ae9d60 ("column: use libsmartcols for --table"), both of them should output with 2 "|" echo '||' | column -o '|' -s '|' -t echo '|| ' | column -o '|' -s '|' -t Fixes: 4762ae9d60 ("column: use libsmartcols for --table") Signed-off-by: Yousong Zhou Reviewed-by: Sami Kerola --- tests/expected/column/table-empty-column-at-eol | 1 + tests/expected/column/table-empty-column-at-eol2 | 1 + tests/ts/column/table | 8 ++++++++ text-utils/column.c | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/expected/column/table-empty-column-at-eol create mode 100644 tests/expected/column/table-empty-column-at-eol2 diff --git a/tests/expected/column/table-empty-column-at-eol b/tests/expected/column/table-empty-column-at-eol new file mode 100644 index 000000000..948cf947f --- /dev/null +++ b/tests/expected/column/table-empty-column-at-eol @@ -0,0 +1 @@ +| diff --git a/tests/expected/column/table-empty-column-at-eol2 b/tests/expected/column/table-empty-column-at-eol2 new file mode 100644 index 000000000..7c4378506 --- /dev/null +++ b/tests/expected/column/table-empty-column-at-eol2 @@ -0,0 +1 @@ +|| diff --git a/tests/ts/column/table b/tests/ts/column/table index bd1f16f3f..e64dee746 100755 --- a/tests/ts/column/table +++ b/tests/ts/column/table @@ -116,4 +116,12 @@ ts_init_subtest "empty-column" printf ':a:b\n' | $TS_CMD_COLUMN --table --separator ':' --output-separator ':' >> $TS_OUTPUT 2>&1 ts_finalize_subtest +ts_init_subtest "empty-column-at-eol" +printf '|' | $TS_CMD_COLUMN --separator '|' --output-separator '|' --table >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + +ts_init_subtest "empty-column-at-eol2" +printf '||' | $TS_CMD_COLUMN --separator '|' --output-separator '|' --table >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + ts_finalize diff --git a/text-utils/column.c b/text-utils/column.c index 13b39537e..9d56e514c 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -169,7 +169,7 @@ static wchar_t *local_wcstok(wchar_t *p, const wchar_t *separator, int greedy, w return strtok_r(p, separator, state); #endif if (!p) { - if (!*state || !**state) + if (!*state) return NULL; p = *state; } -- cgit v1.2.3-55-g7522 From c4d6d1c54dcd0eff701236d396d88b1fc6251768 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 31 Jul 2019 16:18:27 +0200 Subject: libblkid: fix file descriptor leak in blkid_verify() The function blkid_verify() uses private device file descriptor and uses blkid_probe_set_device() to assign the descriptor to low-level probing code. Unfortunately, close() in this case is not enough as the prober can internally open whole-disk device too. The library API has been extended so blkid_probe_set_device() deallocates and close previously used prober for whole-disk. This new functionality is used in blkid_verify() now. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1734545 Signed-off-by: Karel Zak --- libblkid/src/probe.c | 19 ++++++++++++++++--- libblkid/src/verify.c | 4 +++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 1ace06a68..ae1fc06d6 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -846,10 +846,15 @@ failed: * @off: begin of probing area * @size: size of probing area (zero means whole device/file) * - * Assigns the device to probe control struct, resets internal buffers and - * resets the current probing. + * Assigns the device to probe control struct, resets internal buffers, resets + * the current probing, and close previously associated device (if open by + * libblkid). * - * Returns: -1 in case of failure, or 0 on success. + * If @fd is < 0 than only resets the prober and returns 1. Note that + * blkid_reset_probe() keeps the device associated with the prober, but + * blkid_probe_set_device() does complete reset. + * + * Returns: -1 in case of failure, 0 on success and 1 on reset. */ int blkid_probe_set_device(blkid_probe pr, int fd, blkid_loff_t off, blkid_loff_t size) @@ -864,6 +869,11 @@ int blkid_probe_set_device(blkid_probe pr, int fd, if ((pr->flags & BLKID_FL_PRIVATE_FD) && pr->fd >= 0) close(pr->fd); + if (pr->disk_probe) { + blkid_free_probe(pr->disk_probe); + pr->disk_probe = NULL; + } + pr->flags &= ~BLKID_FL_PRIVATE_FD; pr->flags &= ~BLKID_FL_TINY_DEV; pr->flags &= ~BLKID_FL_CDROM_DEV; @@ -879,6 +889,9 @@ int blkid_probe_set_device(blkid_probe pr, int fd, pr->wipe_size = 0; pr->wipe_chain = NULL; + if (fd < 0) + return 1; + #if defined(POSIX_FADV_RANDOM) && defined(HAVE_POSIX_FADVISE) /* Disable read-ahead */ posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM); diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c index dbc10f254..a78c9f8f2 100644 --- a/libblkid/src/verify.c +++ b/libblkid/src/verify.c @@ -184,9 +184,11 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev) dev->bid_name, (long long)st.st_rdev, dev->bid_type)); } - blkid_reset_probe(cache->probe); + /* reset prober */ blkid_probe_reset_superblocks_filter(cache->probe); + blkid_probe_set_device(cache->probe, -1, 0, 0); close(fd); + return dev; } -- cgit v1.2.3-55-g7522 From 0c493067dddfed8989ee143873e1cda5d2fe3cb9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 1 Aug 2019 11:06:06 +0200 Subject: choom: improve docs It's not obvious from the current docs that you have to explicitly split command line options and wanted commands. Addresses: https://github.com/karelzak/util-linux/issues/833 Signed-off-by: Karel Zak --- sys-utils/choom.1 | 1 + sys-utils/choom.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sys-utils/choom.1 b/sys-utils/choom.1 index 2b844cbe2..def31d5f0 100644 --- a/sys-utils/choom.1 +++ b/sys-utils/choom.1 @@ -15,6 +15,7 @@ choom \- display and adjust OOM-killer score. .B choom .B \-n .I number +.B [\-\-] .IR command\ [ argument ...] .SH DESCRIPTION diff --git a/sys-utils/choom.c b/sys-utils/choom.c index 1096ab186..b3d3e4d91 100644 --- a/sys-utils/choom.c +++ b/sys-utils/choom.c @@ -37,7 +37,7 @@ static void __attribute__((__noreturn__)) usage(void) fprintf(out, _(" %1$s [options] -p pid\n" " %1$s [options] -n number -p pid\n" - " %1$s [options] -n number command [args...]]\n"), + " %1$s [options] -n number [--] command [args...]]\n"), program_invocation_short_name); fputs(USAGE_SEPARATOR, out); -- cgit v1.2.3-55-g7522 From 3661aab4cf7509b03f749477082553f4eee7dc0e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 1 Aug 2019 11:43:58 +0200 Subject: dmesg: fix output hex encoding The current code ignores single-byte non-printable characters. Reported-by: Marc Deslauriers Signed-off-by: Karel Zak --- sys-utils/dmesg.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index f0b9b7137..9f2e5b804 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -637,25 +637,29 @@ static void safe_fwrite(const char *buf, size_t size, int indent, FILE *out) if (len == (size_t)-1 || len == (size_t)-2) { /* invalid sequence */ memset(&s, 0, sizeof (s)); len = hex = 1; - } else if (len > 1 && !iswprint(wc)) { /* non-printable multibyte */ - hex = 1; - } - i += len - 1; -#else - len = 1; - if (!isprint((unsigned char) *p) && - !isspace((unsigned char) *p)) /* non-printable */ - hex = 1; + i += len - 1; + } else if (len > 1) { + if (!iswprint(wc) && !iswspace(wc)) /* non-printable multibyte */ + hex = 1; + i += len - 1; + } else #endif + { + len = 1; + if (!isprint((unsigned char) *p) && + !isspace((unsigned char) *p)) /* non-printable */ + hex = 1; + } + if (hex) rc = fwrite_hex(p, len, out); else if (*p == '\n' && *(p + 1) && indent) { rc = fwrite(p, 1, len, out) != len; if (fprintf(out, "%*s", indent, "") != indent) rc |= 1; - } - else + } else rc = fwrite(p, 1, len, out) != len; + if (rc != 0) { if (errno != EPIPE) err(EXIT_FAILURE, _("write failed")); -- cgit v1.2.3-55-g7522 From 6d56251220954f4937c9fafbcdb427d4aa50d330 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 2 Aug 2019 19:39:05 +0100 Subject: mountpoint: add --nofollow option The no follow option will allow user to distinct mount points from symbolic links pointing to them. Arguably this is pretty pedantic option, mounting a device or bind mount to a directory via symlink does not have or cause any issues. Addresses: https://github.com/karelzak/util-linux/issues/832 Signed-off-by: Sami Kerola --- bash-completion/mountpoint | 2 +- sys-utils/mountpoint.1 | 7 ++++++- sys-utils/mountpoint.c | 19 ++++++++++++++++--- tests/expected/misc/mountpoint | 9 +++++++++ tests/ts/misc/mountpoint | 27 +++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/expected/misc/mountpoint create mode 100755 tests/ts/misc/mountpoint diff --git a/bash-completion/mountpoint b/bash-completion/mountpoint index f14327ce2..15c6d2314 100644 --- a/bash-completion/mountpoint +++ b/bash-completion/mountpoint @@ -11,7 +11,7 @@ _mountpoint_module() esac case $cur in -*) - OPTS="--quiet --fs-devno --devno --help --version" + OPTS="--quiet --nofollow --fs-devno --devno --help --version" COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) return 0 ;; diff --git a/sys-utils/mountpoint.1 b/sys-utils/mountpoint.1 index afc469ebc..6669b13eb 100644 --- a/sys-utils/mountpoint.1 +++ b/sys-utils/mountpoint.1 @@ -1,4 +1,4 @@ -.TH MOUNTPOINT 1 "July 2014" "util-linux" "User Commands" +.TH MOUNTPOINT 1 "August 2019" "util-linux" "User Commands" .SH NAME mountpoint \- see if a directory or file is a mountpoint .SH SYNOPSIS @@ -28,6 +28,11 @@ directory. .BR \-q , " \-\-quiet" Be quiet - don't print anything. .TP +.B "\-\-nofollow" +Do not follow symbolic link if it the last elemnt of the +.I directory +path. +.TP .BR \-x , " \-\-devno" Show the major/minor numbers of the given blockdevice on standard output. .TP diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c index 985130cba..052440bd4 100644 --- a/sys-utils/mountpoint.c +++ b/sys-utils/mountpoint.c @@ -47,6 +47,7 @@ struct mountpoint_control { unsigned int dev_devno:1, fs_devno:1, + nofollow:1, quiet:1; }; @@ -123,6 +124,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(USAGE_OPTIONS, out); fputs(_(" -q, --quiet quiet mode - don't print anything\n" + " --nofollow do not follow symlink\n" " -d, --fs-devno print maj:min device number of the filesystem\n" " -x, --devno print maj:min device number of the block device\n"), out); fputs(USAGE_SEPARATOR, out); @@ -137,8 +139,13 @@ int main(int argc, char **argv) int c; struct mountpoint_control ctl = { NULL }; + enum { + OPT_NOFOLLOW = CHAR_MAX + 1 + }; + static const struct option longopts[] = { { "quiet", no_argument, NULL, 'q' }, + { "nofollow", no_argument, NULL, OPT_NOFOLLOW }, { "fs-devno", no_argument, NULL, 'd' }, { "devno", no_argument, NULL, 'x' }, { "help", no_argument, NULL, 'h' }, @@ -159,6 +166,9 @@ int main(int argc, char **argv) case 'q': ctl.quiet = 1; break; + case OPT_NOFOLLOW: + ctl.nofollow = 1; + break; case 'd': ctl.fs_devno = 1; break; @@ -179,17 +189,20 @@ int main(int argc, char **argv) warnx(_("bad usage")); errtryhelp(EXIT_FAILURE); } + if (ctl.nofollow && ctl.dev_devno) + errx(EXIT_FAILURE, _("%s and %s are mutually exclusive"), + "--devno", "--nofollow"); ctl.path = argv[optind]; - - if (stat(ctl.path, &ctl.st)) { + c = ctl.nofollow ? lstat(ctl.path, &ctl.st) : stat(ctl.path, &ctl.st); + if (c) { if (!ctl.quiet) err(EXIT_FAILURE, "%s", ctl.path); return EXIT_FAILURE; } if (ctl.dev_devno) return print_devno(&ctl) ? EXIT_FAILURE : EXIT_SUCCESS; - if (dir_to_device(&ctl)) { + if ((ctl.nofollow && S_ISLNK(ctl.st.st_mode)) || dir_to_device(&ctl)) { if (!ctl.quiet) printf(_("%s is not a mountpoint\n"), ctl.path); return EXIT_FAILURE; diff --git a/tests/expected/misc/mountpoint b/tests/expected/misc/mountpoint new file mode 100644 index 000000000..e7c20cd25 --- /dev/null +++ b/tests/expected/misc/mountpoint @@ -0,0 +1,9 @@ +default +./symlink-to-root is a mountpoint +0 +try --nofollow +./symlink-to-root is not a mountpoint +1 +mutually exclusive +mountpoint: --devno and --nofollow are mutually exclusive +1 diff --git a/tests/ts/misc/mountpoint b/tests/ts/misc/mountpoint new file mode 100755 index 000000000..0b93a9c36 --- /dev/null +++ b/tests/ts/misc/mountpoint @@ -0,0 +1,27 @@ +#!/bin/bash + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="mountpoint" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_MOUNTPOINT" + +ln -s / ./symlink-to-root + +echo "default" >> $TS_OUTPUT 2>&1 +$TS_CMD_MOUNTPOINT ./symlink-to-root >> $TS_OUTPUT 2>&1 +echo $? >> $TS_OUTPUT 2>&1 + +echo "try --nofollow" >> $TS_OUTPUT 2>&1 +$TS_CMD_MOUNTPOINT --nofollow ./symlink-to-root >> $TS_OUTPUT 2>&1 +echo $? >> $TS_OUTPUT 2>&1 + +echo "mutually exclusive" >> $TS_OUTPUT 2>&1 +$TS_CMD_MOUNTPOINT --devno --nofollow / >> $TS_OUTPUT 2>&1 +echo $? >> $TS_OUTPUT 2>&1 + +rm -f ./symlink-to-root + +ts_finalize -- cgit v1.2.3-55-g7522 From e9d2e0c8197ffcb1b5e92be3002656c644e588d3 Mon Sep 17 00:00:00 2001 From: Chistyj Arkadij Date: Sun, 4 Aug 2019 17:06:38 +0300 Subject: fixed mount man page typo, "bythe" -> "by the" --- sys-utils/mount.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-utils/mount.8 b/sys-utils/mount.8 index b79b4ef5f..8d4b8f164 100644 --- a/sys-utils/mount.8 +++ b/sys-utils/mount.8 @@ -116,7 +116,7 @@ options to avoid ambivalent interpretation of the given argument. For example: The same filesystem may be mounted more than once, and in some cases (e.g. network filesystems) the same filesystem may be mounted on the same mountpoint more times. The mount command does not implement any policy to -control this behavior. All behavior is controlled bythe kernel and it is usually +control this behavior. All behavior is controlled by the kernel and it is usually specific to the filesystem driver. The exception is \fB\-\-all\fR, in this case already mounted filesystems are ignored (see \fB\-\-all\fR below for more details). -- cgit v1.2.3-55-g7522 From 0797511930ff90d8f97c05e15e37a3cce10197ad Mon Sep 17 00:00:00 2001 From: Chistyj Arkadij Date: Sun, 4 Aug 2019 21:21:55 +0300 Subject: removed double space --- sys-utils/mount.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-utils/mount.8 b/sys-utils/mount.8 index 8d4b8f164..56d3520be 100644 --- a/sys-utils/mount.8 +++ b/sys-utils/mount.8 @@ -116,7 +116,7 @@ options to avoid ambivalent interpretation of the given argument. For example: The same filesystem may be mounted more than once, and in some cases (e.g. network filesystems) the same filesystem may be mounted on the same mountpoint more times. The mount command does not implement any policy to -control this behavior. All behavior is controlled by the kernel and it is usually +control this behavior. All behavior is controlled by the kernel and it is usually specific to the filesystem driver. The exception is \fB\-\-all\fR, in this case already mounted filesystems are ignored (see \fB\-\-all\fR below for more details). -- cgit v1.2.3-55-g7522 From cb74ebad253c6aaaf81b8f5fcdee8be71c956dbf Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 6 Aug 2019 12:24:33 +0200 Subject: libfdisk: refer to partx(8) rather than to kpartx(8) Reported-by: Petr Pisar Signed-off-by: Karel Zak --- libfdisk/src/context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index bc284f34e..f97f0a612 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -839,7 +839,7 @@ int fdisk_reread_partition_table(struct fdisk_context *cxt) fdisk_info(cxt, _( "The kernel still uses the old table. The " "new table will be used at the next reboot " - "or after you run partprobe(8) or kpartx(8).")); + "or after you run partprobe(8) or partx(8).")); return -errno; } -- cgit v1.2.3-55-g7522 From 11aaedf5742771b1989add0c3801bbaede6bf3b4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 7 Aug 2019 11:45:57 +0200 Subject: tests: use subtests for mountpoint(1) Signed-off-by: Karel Zak --- tests/expected/misc/mountpoint | 9 --------- tests/expected/misc/mountpoint-default | 2 ++ tests/expected/misc/mountpoint-mutually-exclusive | 2 ++ tests/expected/misc/mountpoint-nofollow | 2 ++ tests/ts/misc/mountpoint | 10 ++++++---- 5 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 tests/expected/misc/mountpoint-default create mode 100644 tests/expected/misc/mountpoint-mutually-exclusive create mode 100644 tests/expected/misc/mountpoint-nofollow diff --git a/tests/expected/misc/mountpoint b/tests/expected/misc/mountpoint index e7c20cd25..e69de29bb 100644 --- a/tests/expected/misc/mountpoint +++ b/tests/expected/misc/mountpoint @@ -1,9 +0,0 @@ -default -./symlink-to-root is a mountpoint -0 -try --nofollow -./symlink-to-root is not a mountpoint -1 -mutually exclusive -mountpoint: --devno and --nofollow are mutually exclusive -1 diff --git a/tests/expected/misc/mountpoint-default b/tests/expected/misc/mountpoint-default new file mode 100644 index 000000000..9a7ac6ab3 --- /dev/null +++ b/tests/expected/misc/mountpoint-default @@ -0,0 +1,2 @@ +./symlink-to-root is a mountpoint +0 diff --git a/tests/expected/misc/mountpoint-mutually-exclusive b/tests/expected/misc/mountpoint-mutually-exclusive new file mode 100644 index 000000000..38c36f13b --- /dev/null +++ b/tests/expected/misc/mountpoint-mutually-exclusive @@ -0,0 +1,2 @@ +mountpoint: --devno and --nofollow are mutually exclusive +1 diff --git a/tests/expected/misc/mountpoint-nofollow b/tests/expected/misc/mountpoint-nofollow new file mode 100644 index 000000000..1ba174959 --- /dev/null +++ b/tests/expected/misc/mountpoint-nofollow @@ -0,0 +1,2 @@ +./symlink-to-root is not a mountpoint +1 diff --git a/tests/ts/misc/mountpoint b/tests/ts/misc/mountpoint index 0b93a9c36..03c1ccc3e 100755 --- a/tests/ts/misc/mountpoint +++ b/tests/ts/misc/mountpoint @@ -10,18 +10,20 @@ ts_check_test_command "$TS_CMD_MOUNTPOINT" ln -s / ./symlink-to-root -echo "default" >> $TS_OUTPUT 2>&1 +ts_init_subtest "default" $TS_CMD_MOUNTPOINT ./symlink-to-root >> $TS_OUTPUT 2>&1 echo $? >> $TS_OUTPUT 2>&1 +ts_finalize_subtest -echo "try --nofollow" >> $TS_OUTPUT 2>&1 +ts_init_subtest "nofollow" $TS_CMD_MOUNTPOINT --nofollow ./symlink-to-root >> $TS_OUTPUT 2>&1 echo $? >> $TS_OUTPUT 2>&1 +ts_finalize_subtest -echo "mutually exclusive" >> $TS_OUTPUT 2>&1 +ts_init_subtest "mutually-exclusive" $TS_CMD_MOUNTPOINT --devno --nofollow / >> $TS_OUTPUT 2>&1 echo $? >> $TS_OUTPUT 2>&1 +ts_finalize_subtest rm -f ./symlink-to-root - ts_finalize -- cgit v1.2.3-55-g7522 From 08474fde6669d89f5b77653ba9d378fc16e19903 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 8 Aug 2019 10:34:27 +0200 Subject: libfdisk: (script) support shortcuts in the type= field The unnamed-field format supports partition type shortcuts: ",1MiB,L' but for named-field format it requires full type: (mbr) "size=1MiB,type=83" (gpt) "size=1MiB,type=0FC63DAF-8483-4772-8E79-3D69D8477DE4" This patch implements type shortcuts also for named-field format: "size=1MiB,type=L" to make it more user-friendly and unified. Addresses: https://github.com/karelzak/util-linux/issues/837 Signed-off-by: Karel Zak --- disk-utils/sfdisk.8 | 3 ++- libfdisk/src/script.c | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index ff54760ca..c7630bb37 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -462,7 +462,8 @@ GPT partition UUID. GPT partition name. .TP .BI type= code -A hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition. +A hexadecimal number (without 0x) for an MBR partition, a GUID for a GPT partition, +or a shortcut as for unnamed-fields format. For backward compatibility the \fBId=\fR field has the same meaning. .RE .RE diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 3db76c87b..a28983dba 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -61,6 +61,8 @@ struct fdisk_script { force_label : 1; /* label: specified */ }; +static struct fdisk_parttype *translate_type_shortcuts(struct fdisk_script *dp, char *str); + static void fdisk_script_free_header(struct fdisk_scriptheader *fi) { @@ -1054,8 +1056,11 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) rc = next_string(&p, &type); if (rc) break; - pa->type = fdisk_label_parse_parttype( - script_get_label(dp), type); + + pa->type = translate_type_shortcuts(dp, type); + if (!pa->type) + pa->type = fdisk_label_parse_parttype( + script_get_label(dp), type); free(type); if (!pa->type) { -- cgit v1.2.3-55-g7522 From c60231a7447692c42602c77cf96f1291740f4637 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 8 Aug 2019 14:20:05 +0200 Subject: tests: update fdisk output Signed-off-by: Karel Zak --- tests/expected/fdisk/gpt-resize | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/expected/fdisk/gpt-resize b/tests/expected/fdisk/gpt-resize index 0b3c25a27..2871f1a14 100644 --- a/tests/expected/fdisk/gpt-resize +++ b/tests/expected/fdisk/gpt-resize @@ -35,7 +35,7 @@ Command (m for help): The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: Invalid argument -The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8). +The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or partx(8). -- cgit v1.2.3-55-g7522 From 76b680b1a9deeb83c310115fd96fd6f51d37cd53 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 8 Aug 2019 12:12:55 -0700 Subject: Remove isascii usage There is a c_isascii function that can be used. isascii is deprecated and not available with some libcs like uClibc-ng where it can be compile time disabled. --- include/carefulputc.h | 4 +++- term-utils/agetty.c | 3 ++- term-utils/wall.c | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/carefulputc.h b/include/carefulputc.h index 54a02bfef..f1c03566d 100644 --- a/include/carefulputc.h +++ b/include/carefulputc.h @@ -10,13 +10,15 @@ #include #include +#include "cctype.h" + static inline int fputc_careful(int c, FILE *fp, const char fail) { int ret; if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') ret = putc(c, fp); - else if (!isascii(c)) + else if (!c_isascii(c)) ret = fprintf(fp, "\\%3o", (unsigned char)c); else { ret = putc(fail, fp); diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 703fb9fd7..038152d56 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -42,6 +42,7 @@ #include "nls.h" #include "pathnames.h" #include "c.h" +#include "cctype.h" #include "widechar.h" #include "ttyutils.h" #include "color-names.h" @@ -1432,7 +1433,7 @@ static void auto_baud(struct termios *tp) if ((nread = read(STDIN_FILENO, buf, sizeof(buf) - 1)) > 0) { buf[nread] = '\0'; for (bp = buf; bp < buf + nread; bp++) - if (isascii(*bp) && isdigit(*bp)) { + if (c_isascii(*bp) && isdigit(*bp)) { if ((speed = bcode(bp))) { cfsetispeed(tp, speed); cfsetospeed(tp, speed); diff --git a/term-utils/wall.c b/term-utils/wall.c index c3e89bab9..bf92fe1b7 100644 --- a/term-utils/wall.c +++ b/term-utils/wall.c @@ -68,6 +68,7 @@ #include "pathnames.h" #include "carefulputc.h" #include "c.h" +#include "cctype.h" #include "fileutils.h" #include "closestream.h" @@ -324,7 +325,7 @@ static void buf_putc_careful(struct buffer *bs, int c) if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') { buf_enlarge(bs, 1); bs->data[bs->used++] = c; - } else if (!isascii(c)) + } else if (!c_isascii(c)) buf_printf(bs, "\\%3o", (unsigned char)c); else { char tmp[] = { '^', c ^ 0x40, '\0' }; -- cgit v1.2.3-55-g7522 From 050def0f3511f743d948458ecd3fda637168a7c7 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 8 Aug 2019 12:14:39 -0700 Subject: Remove unused utime.h header It is sometimes unavailable and errors on inclusion. For example, when disabled in uClibc-ng. --- disk-utils/fsck.cramfs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c index e1b964b64..a81995180 100644 --- a/disk-utils/fsck.cramfs.c +++ b/disk-utils/fsck.cramfs.c @@ -416,7 +416,6 @@ static void do_uncompress(char *path, int outfd, unsigned long offset, curr = next; } while (size); } -#include static void change_file_status(char *path, struct cramfs_inode *i) { const struct timeval epoch[] = { {0,0}, {0,0} }; -- cgit v1.2.3-55-g7522 From 9210c0d225fd808da451d86055bf243a8b47a525 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 19 Aug 2019 14:03:07 +0200 Subject: chfn: don't append extra tailing commas # grep kzak /etc/passwd kzak:x:1000:1000::/home/kzak:/bin/bash # chfn kzak ... grep kzak /etc/passwd old version: kzak:x:1000:1000:Karel Zak,,,,:/home/kzak:/bin/bash fixed version: kzak:x:1000:1000:Karel Zak:/home/kzak:/bin/bash Reported-by: Filip Dvorak References: f723cbf544a7eac2927634f2cb6d802437a2d519 Signed-off-by: Karel Zak --- login-utils/chfn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/login-utils/chfn.c b/login-utils/chfn.c index a2e6e099e..b7395552b 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -376,7 +376,7 @@ static int save_new_data(struct chfn_control *ctl) ctl->newf.other); /* remove trailing empty fields (but not subfields of ctl->newf.other) */ - if (!ctl->newf.other) { + if (!ctl->newf.other || !*ctl->newf.other) { while (len > 0 && gecos[len - 1] == ',') len--; gecos[len] = 0; -- cgit v1.2.3-55-g7522 From 424b66c514501f3a6311b73a69db5ec5729fca49 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 19 Aug 2019 14:28:50 +0200 Subject: tests: Skip fdisk/mbr-nondos-mode on Sparc as unsupported The test has been originally designed as usable on sparc, but now we use it for many features which are MBR specific. Reported-by: John Paul Adrian Glaubitz Co-Author: Anatoly Pugachev Signed-off-by: Karel Zak --- tests/expected/fdisk/mbr-nondos-mode.sparc | 189 ----------------------------- tests/ts/fdisk/mbr-nondos-mode | 7 +- 2 files changed, 2 insertions(+), 194 deletions(-) delete mode 100644 tests/expected/fdisk/mbr-nondos-mode.sparc diff --git a/tests/expected/fdisk/mbr-nondos-mode.sparc b/tests/expected/fdisk/mbr-nondos-mode.sparc deleted file mode 100644 index ffbbd8024..000000000 --- a/tests/expected/fdisk/mbr-nondos-mode.sparc +++ /dev/null @@ -1,189 +0,0 @@ -Initialize empty image -8f4e33f3dc3e414ff94e5fb6905cba8c mbr-nondos-mode.img -Create new DOS partition table -8f4e33f3dc3e414ff94e5fb6905cba8c mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -------------------- - -Create 1st primary partition -d5ad6d4e743430c2a61e558bb3319175 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Set primary partition active -d59bb4ba5914242f9a63a2d13fb68752 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Re-create 1st primary partition -d8ba04bdd46cec690fa672ac8fcaf387 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -------------------- - -Create 2nd primary partition -d8ba04bdd46cec690fa672ac8fcaf387 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -------------------- - -Create extended partition -d59bb4ba5914242f9a63a2d13fb68752 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Create logical partitions -d59bb4ba5914242f9a63a2d13fb68752 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Delete logical partitions -d59bb4ba5914242f9a63a2d13fb68752 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Create another logical partition -d59bb4ba5914242f9a63a2d13fb68752 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -1 0 16064 16065 7.9M 83 Linux native r -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Delete primary partition -0bd87175c4c5c3ef9a46595027b6369c mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -2 16065 32129 16065 7.9M 82 Linux swap u -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Delete primary partition -33f6e541ddcafed65d231ce3f2b76a59 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun - -Device Start End Sectors Size Id Type Flags -3 0 32129 32130 15.7M 5 Whole disk -------------------- - -Delete extended partition -e923755cbc0054eb85341fe119be07f9 mbr-nondos-mode.img - ----layout---------- -Disk : 20 MiB, 20971520 bytes, 40960 sectors -Geometry: 255 heads, 63 sectors/track, 2 cylinders -Units: sectors of 1 * 512 = 512 bytes -Sector size (logical/physical): 512 bytes / 512 bytes -I/O size (minimum/optimal): 512 bytes / bytes -Disklabel type: sun -------------------- - diff --git a/tests/ts/fdisk/mbr-nondos-mode b/tests/ts/fdisk/mbr-nondos-mode index d3b35fa39..8fb09f1ce 100755 --- a/tests/ts/fdisk/mbr-nondos-mode +++ b/tests/ts/fdisk/mbr-nondos-mode @@ -37,19 +37,16 @@ FDISK_CMD_DELETE_1PRIMARY="d\n1\n" # delete first primary FDISK_CMD_DELETE_2PRIMARY="d\n2\n" # delete first primary FDISK_CMD_DELETE_EXTENDED="d\n3\n" # delete second primary -# Sparc uses SUN disk labels by default and thus has a different output +# ignore architectures where MBR is not a default ARCH=$(uname -m) case $ARCH in *sparc* ) - ARCH_EXT=".sparc" + ts_skip "unsupported" ;; *) - ARCH_EXT="" ;; esac -TS_EXPECTED+="${ARCH_EXT}" - function print_layout { echo -ne "\n---layout----------\n" >> $TS_OUTPUT $TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT -- cgit v1.2.3-55-g7522 From 042057d8029dde27cc465d573731579f50c89eee Mon Sep 17 00:00:00 2001 From: Kevin Hao Date: Mon, 19 Aug 2019 16:30:22 +0800 Subject: libmount: Keep the mnt_tab info for the existent dest in mnt_copy_fs() The "umount -f -a -r" get stuck in a endless loop when run with a mountinfo like below: 15 0 179:2 / / ro,relatime - ext4 /dev/root ro 16 15 0:6 / /dev rw,relatime - devtmpfs devtmpfs rw,size=242896k,nr_inodes=60724,mode=755 17 15 0:4 / /proc rw,relatime - proc proc rw 18 15 0:15 / /mnt/.psplash rw,relatime - tmpfs tmpfs rw,size=40k 19 15 0:16 / /sys rw,relatime - sysfs sysfs rw 20 19 0:7 / /sys/kernel/debug rw,relatime - debugfs debugfs rw 21 15 0:17 / /run rw,nosuid,nodev - tmpfs tmpfs rw,mode=755 22 15 0:18 / /var/volatile rw,relatime - tmpfs tmpfs rw 23 15 179:1 / /boot rw,relatime - vfat /dev/mmcblk0p1 rw,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 24 16 0:19 / /dev/pts rw,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=000 25 18 0:20 / /mnt/.psplash rw,relatime - tmpfs tmpfs rw,size=40k The reason is that the two same mnt entry "/mnt/.psplash" will cause the dst->tab set to NULL when umount this mnt entry the second time. This will trigger an endless loop in mnt_reset_table() because that mnt entry is linked on the libmnt_table but its .tab is set to NULL. Signed-off-by: Kevin Hao --- libmount/src/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmount/src/fs.c b/libmount/src/fs.c index eb89bb8a3..4126ee9dc 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -188,9 +188,10 @@ struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest, dest = mnt_new_fs(); if (!dest) return NULL; + + dest->tab = NULL; } - dest->tab = NULL; dest->id = src->id; dest->parent = src->parent; dest->devno = src->devno; -- cgit v1.2.3-55-g7522 From cdd2d60e56ad2ef103ba6fa46bc6276d52c65f10 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 15 Aug 2019 14:03:23 +0200 Subject: wdctl: remove duplicate include of The header is included twice in "wdctl.c". Remove one of these includes to keep "make checkincludes" happy. Signed-off-by: Patrick Steinhardt --- sys-utils/wdctl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index 0bb245bae..8de5d5a2d 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3-55-g7522 From ad167a9023aa1fd04653c6aed0256132514827aa Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 15 Aug 2019 12:50:05 +0200 Subject: libmount: fix comment referring to passno field There's an obvious copy-paste error in `mnt_parse_table_line` when referring to the 6th field of the fstab format, where it says "freq" instead of "passno". This has probably been copied from the 5th field, which is in fact correctly labelled as "freq". Fix the mistake by changing the comment to say "passno" instead. Signed-off-by: Patrick Steinhardt --- libmount/src/tab_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 8e94715d2..2dfa6cbb4 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -154,7 +154,7 @@ static int mnt_parse_table_line(struct libmnt_fs *fs, const char *s) if (!s || !*s) goto done; - /* (6) freq (optional) */ + /* (6) passno (optional) */ s = next_s32(s, &fs->passno, &rc); if (s && *s && rc) { DBG(TAB, ul_debug("tab parse error: [passno]")); -- cgit v1.2.3-55-g7522 From 53ae7d60cfeacd4e87bfe6fcc015b58b78ef4555 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 21 Aug 2019 10:51:18 +0200 Subject: partx: don't report ENXIO as error on -d The errno ENXIO should be ignored, unfortunately the current code uses variable 'rc' for ioctl return code as well as for final del_parts() return value. So, failed ioctl (which should be ignored) affects all del_parts() status. # modprobe scsi_debug dev_size_mb=100 # partx -d --nr 1-1024 /dev/sdc; echo $? 1 The device dos not contains any partitions, so 0 return code is expected in this case. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1739179 Signed-off-by: Karel Zak --- disk-utils/partx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/disk-utils/partx.c b/disk-utils/partx.c index 949278eb7..e1f6b8f9e 100644 --- a/disk-utils/partx.c +++ b/disk-utils/partx.c @@ -328,8 +328,7 @@ static int del_parts(int fd, const char *device, dev_t devno, } for (i = lower; i <= upper; i++) { - rc = partx_del_partition(fd, i); - if (rc == 0) { + if (partx_del_partition(fd, i) == 0) { if (verbose) printf(_("%s: partition #%d removed\n"), device, i); continue; -- cgit v1.2.3-55-g7522 From 5200aa99d27e084b514e8b035db32f39b49562a3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 21 Aug 2019 13:42:22 +0200 Subject: partx: document -d vs. --nr and fix test The commit ab025087f91b66ee8e23a16bc49eb0d9bd421d65 has disabled error message, but unfortunately it keeps wrong return code. This has been fixed by commit 53ae7d60cfeacd4e87bfe6fcc015b58b78ef4555. This commit add hit about it to docs and fix regression test too. Signed-off-by: Karel Zak --- disk-utils/partx.8 | 5 ++++- tests/ts/partx/partx | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/disk-utils/partx.8 b/disk-utils/partx.8 index 223f20918..d6ff52f08 100644 --- a/disk-utils/partx.8 +++ b/disk-utils/partx.8 @@ -53,7 +53,10 @@ Add the specified partitions, or read the disk and add all partitions. Print the SIZE column in bytes rather than in human-readable format. .TP .BR \-d , " \-\-delete" -Delete the specified partitions or all partitions. +Delete the specified partitions or all partitions. It is not error to +remove non-existing partitions, so this option is possible to use together with +large \fB\-\-nr\fR ranges without care about the current partitions set on +the device. .TP .BR \-g , " \-\-noheadings" Do not print a header line with \fB\-\-show\fR or \fB\-\-raw\fR. diff --git a/tests/ts/partx/partx b/tests/ts/partx/partx index b21dc44ef..84c286a94 100755 --- a/tests/ts/partx/partx +++ b/tests/ts/partx/partx @@ -137,9 +137,14 @@ udevadm settle ts_init_subtest "delete-non-existent" #attempt to remove it again { + # remove non-existing partitions (ENXIO) is not error + # + # see ab025087f91b66ee8e23a16bc49eb0d9bd421d65 and + # 53ae7d60cfeacd4e87bfe6fcc015b58b78ef4555 + # $TS_CMD_PARTX -d --nr $PARTS $TS_DEVICE && - echo "partx failed: removed non-existing partition" || - echo "partx: OK" + echo "partx: OK" || + echo "partx failed: removed non-existing partition" } >$TS_OUTPUT 2>&1 ts_finalize_subtest -- cgit v1.2.3-55-g7522