* [PATCH] whereis: search in path variable
From: Davidlohr Bueso @ 2011-07-20 4:46 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Wed, 20 Jul 2011 00:39:10 -0400
Currently this tool only uses the hardcoded paths for looking up strings for binaries, man pages and source code,
adding those directories found in $PATH makes a nice little enhancement.
dave@offbook:~/projects/util-linux/misc-utils$ export PATH=$PATH:/home/dave/whereis-test
dave@offbook:~/projects/util-linux/misc-utils$ ./whereis stdlib
stdlib: /home/dave/whereis-test/stdlib.h /usr/include/stdlib.h
dave@offbook:~/projects/util-linux/misc-utils$ whereis-old stdlib
stdlib: /usr/include/stdlib.h
This feature was also discussed previously here (http://www.spinics.net/lists/util-linux-ng/msg03429.html)
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
misc-utils/whereis.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 4f841f9..ec75057 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -45,6 +45,8 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+
+#include "xalloc.h"
#include "nls.h"
#include "c.h"
@@ -58,6 +60,7 @@ void findv(char **, int, char *);
void find(char **, char *);
void findin(char *, char *);
int itsit(char *, char *);
+void fillpath(void);
static char *bindirs[] = {
"/bin",
@@ -144,6 +147,7 @@ int Bcnt;
char **Mflag;
int Mcnt;
char uflag;
+char **dirp, **pathdir = NULL;
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -172,6 +176,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int
main(int argc, char **argv)
{
+ int i;
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -179,6 +185,9 @@ main(int argc, char **argv)
argc--, argv++;
if (argc == 0)
usage(stderr);
+
+ fillpath();
+ dirp = pathdir;
do
if (argv[0][0] == '-') {
@@ -232,9 +241,51 @@ main(int argc, char **argv)
} else
lookup(*argv++);
while (--argc > 0);
+
+ free(pathdir);
+
return EXIT_SUCCESS;
}
+int inpath(const char *str)
+{
+ int i;
+
+ for (i = 0; i < sizeof(bindirs)/sizeof(char *) - 1 ; i++)
+ if (!strcmp(bindirs[i], str))
+ return 1;
+
+ for (i = 0; i < sizeof(mandirs)/sizeof(char *) - 1; i++)
+ if (!strcmp(mandirs[i], str))
+ return 1;
+
+ for (i = 0; i < sizeof(srcdirs)/sizeof(char *) - 1; i++)
+ if (!strcmp(srcdirs[i], str))
+ return 1;
+
+ return 0;
+}
+
+void fillpath(void)
+{
+ char *key=NULL, *tmp=NULL, *tok=NULL, *path = getenv("PATH");
+ int i = 0;
+
+ if (!path)
+ return;
+
+ for (tmp = path; ;tmp = NULL) {
+ tok = strtok_r(tmp, ":", &key);
+ if (!tok)
+ break;
+ if (inpath(tok)) /* make sure we don't repeat the search path */
+ continue;
+
+ pathdir = xrealloc(pathdir, (i + 1) * sizeof(char *));
+ pathdir[i++] = tok;
+ }
+}
+
void
getlist(int *argcp, char ***argvp, char ***flagp, int *cntp)
{
@@ -356,6 +407,8 @@ find(char **dirs, char *cp)
{
while (*dirs)
findin(*dirs++, cp);
+ while(*dirp)
+ findin(*dirp++, cp);
}
void
--
1.7.4.1
^ permalink raw reply related
* [PATCH] swapon: use xalloc lib
From: Davidlohr Bueso @ 2011-07-19 23:17 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Mon, 18 Jul 2011 00:33:20 -0400
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
mount/swapon.c | 15 +++++----------
1 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/mount/swapon.c b/mount/swapon.c
index 49771f5..6dfe4b1 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -24,6 +24,7 @@
#include "swapheader.h"
#include "mangle.h"
#include "canonicalize.h"
+#include "xalloc.h"
#include "c.h"
#define PATH_MKSWAP "/sbin/mkswap"
@@ -341,10 +342,8 @@ swap_get_header(int fd, int *sig, unsigned int *pagesize)
*pagesize = 0;
*sig = 0;
- buf = malloc(MAX_PAGESIZE);
- if (!buf)
- return NULL;
-
+ buf = xmalloc(MAX_PAGESIZE);
+
datasz = read(fd, buf, MAX_PAGESIZE);
if (datasz == (ssize_t) -1)
goto err;
@@ -658,16 +657,12 @@ static const char **ulist = NULL;
static int ulct = 0;
static void addl(const char *label) {
- llist = (const char **) realloc(llist, (++llct) * sizeof(char *));
- if (!llist)
- exit(EXIT_FAILURE);
+ llist = (const char **) xrealloc(llist, (++llct) * sizeof(char *));
llist[llct-1] = label;
}
static void addu(const char *uuid) {
- ulist = (const char **) realloc(ulist, (++ulct) * sizeof(char *));
- if (!ulist)
- exit(EXIT_FAILURE);
+ ulist = (const char **) xrealloc(ulist, (++ulct) * sizeof(char *));
ulist[ulct-1] = uuid;
}
--
1.7.4.1
^ permalink raw reply related
* [PATCH] partx: get partition number with sysfs lib
From: Davidlohr Bueso @ 2011-07-19 23:17 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 17 Jul 2011 12:47:30 -0400
Now that we have this feature, there's no need to manually parse sysfs in partx.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
partx/Makefile.am | 1 +
partx/partx.c | 22 +++++-----------------
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/partx/Makefile.am b/partx/Makefile.am
index 46fc641..6a72942 100644
--- a/partx/Makefile.am
+++ b/partx/Makefile.am
@@ -6,6 +6,7 @@ dist_man_MANS = addpart.8 delpart.8
usrsbin_exec_PROGRAMS += partx
partx_SOURCES = partx.c partx.h \
$(top_srcdir)/lib/blkdev.c \
+ $(top_srcdir)/lib/sysfs.c \
$(top_srcdir)/lib/tt.c \
$(top_srcdir)/lib/at.c \
$(top_srcdir)/lib/mbsalign.c \
diff --git a/partx/partx.c b/partx/partx.c
index d8a4119..e29e50d 100644
--- a/partx/partx.c
+++ b/partx/partx.c
@@ -30,6 +30,7 @@
#include "strutils.h"
#include "xalloc.h"
#include "partx.h"
+#include "sysfs.h"
#include "at.h"
/* this is the default upper limit, could be modified by --nr */
@@ -123,8 +124,6 @@ static int column_name_to_id(const char *name, size_t namesz)
*
* Note that this function tries to use sysfs, otherwise it assumes that the
* last characters are always numeric (sda1, sdc20, etc).
- *
- * Returns -1 on error.
*/
static int get_partno_from_device(char *partition, dev_t devno)
{
@@ -135,21 +134,10 @@ static int get_partno_from_device(char *partition, dev_t devno)
assert(partition);
if (devno) {
- /* the device exists, read the partition number from /sys
- * TODO: move this to stuff to lib/sysfs.c */
- char path[PATH_MAX];
- FILE *f;
-
- snprintf(path, sizeof(path),
- _PATH_SYS_DEVBLOCK "/%d:%d/partition",
- major(devno), minor(devno));
- f = fopen(path, "r");
- if (f) {
- if (fscanf(f, "%d", &partno) != 1)
- partno = 0;
- fclose(f);
- }
- if (partno)
+ struct sysfs_cxt cxt;
+
+ sysfs_init(&cxt, devno, NULL);
+ if (sysfs_read_int(&cxt, "partition", &partno) >= 0)
return partno;
}
--
1.7.4.1
^ permalink raw reply related
* Re: dmesg(1) changes
From: Karel Zak @ 2011-07-18 22:28 UTC (permalink / raw)
To: Thomas Bächler; +Cc: util-linux
In-Reply-To: <4E242E69.6090409@archlinux.org>
On Mon, Jul 18, 2011 at 03:00:25PM +0200, Thomas Bächler wrote:
> Am 14.07.2011 13:52, schrieb Karel Zak:
> >
> > Hi,
> >
> > I did some changes to dmesg(1) in last days:
>
> Thanks for these advances.
>
> While we're making a wishlist, I always wanted a 'follow' option
> (similar to tail -f/-F) for dmesg.
It's not so simple:
http://www.spinics.net/lists/util-linux-ng/msg04453.html
I'll try to play with that a little more later. Now I'd like to
release 2.20 ASAP.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] lscpu: add support for books
From: Karel Zak @ 2011-07-18 22:21 UTC (permalink / raw)
To: Jon Stanley; +Cc: Heiko Carstens, util-linux
In-Reply-To: <CALY6xnjDxrUWO5su4wqHhwR0=SmZ+bqPVZD1mEqrfRoqSQiV5g@mail.gmail.com>
On Mon, Jul 18, 2011 at 11:17:24AM -0400, Jon Stanley wrote:
> On Mon, Jul 18, 2011 at 5:10 AM, Karel Zak <kzak@redhat.com> wrote:
>
> > I'm not sure if the currently used extra separators (,,) for the
> > caches is a good idea. Maybe it would be better to force people to
> > parse the last comment line where is the header for the columns.
>
> Speaking as a user of lscpu, I think that forcing people to parse the
> last comment line is not a particularly good idea - no one is used to
> doing it, and I'm not sure of any other utility that forces you to
> parse it's "machine-readable" output. Stability of this format is key.
Yes, -p sucks ;-)
> > The ideal solution is to extend the "-p" functionality and allow to
> > specify expected columns at command line, something like:
> >
> > lscpu -p -o cpu,core,book,socket
>
> I think that this is the only long-term supportable way to do this.
> CPU architectures (even in the x86 world that I'm interested in) ARE
> going to change and evolve. Heck, it's even possible that concepts
> like the hypervisor scheduling parameters that you mentioned on s390
> could eventually make their way down to x86 virtualization, and
> exposing stuff like that in lscpu would be nice.
I'll try to add this functionality in next days.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] minix: v3 super-block does not have s_state field
From: Karel Zak @ 2011-07-18 22:19 UTC (permalink / raw)
To: kerolasa; +Cc: Davidlohr Bueso, util-linux
In-Reply-To: <CAG27Bk0DYx+jCD-iqQvt1n=VdHszceTEAQQRvCKLvPXqpagTXA@mail.gmail.com>
Sami, thanks for the patches, few notes:
On Thu, Jul 14, 2011 at 05:47:39PM +0200, Sami Kerola wrote:
> +++ b/include/minix.h
> @@ -1,69 +1,65 @@
> #ifndef __MINIX_H__
> #define __MINIX_H__
we usually use UTIL_LINUX prefix, so #ifndef UTIL_LINUX_MINIX_H.
> #define BLOCK_SIZE_BITS 10
> #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
This is too generic. Please, use MINIX_ prefix.
> #define Inode (((struct minix_inode *) inode_buffer)-1)
> #define Inode2 (((struct minix2_inode *) inode_buffer)-1)
>
> #define INODE_SIZE (sizeof(struct minix_inode))
> #define INODE2_SIZE (sizeof(struct minix2_inode))
>
> -int fs_version = 1; /* this default value needs to change in a near future */
> -char *super_block_buffer, *inode_buffer = NULL;
> +static int fs_version = 1; /* this default value needs to change in a
> near future */
> +static char *super_block_buffer, *inode_buffer = NULL;
>
> static char *inode_map;
> static char *zone_map;
The global variables don't belong to this generic header file. The
stuff around inode_buffer, fs_version and the inline functions are
specific to the disk-utils/ utils. Please, add
disk-utils/minix_programs.h and use it in {mkfs,fsck}.minix.
> /* sanity checks to be sure that the FS is really minix */
> - if (sb->s_imap_blocks * MINIX_BLOCK_SIZE * 8 < sb->s_ninodes + 1)
> + if (sb->s_imap_blocks * BLOCK_SIZE * 8 < sb->s_ninodes + 1)
> return -1;
> - if (sb->s_zmap_blocks * MINIX_BLOCK_SIZE * 8 < zones -
> sb->s_firstdatazone + 1)
> + if (sb->s_zmap_blocks * BLOCK_SIZE * 8 < zones - sb->s_firstdatazone + 1)
> return -1;
No, please...
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] schedutils
From: Karel Zak @ 2011-07-18 22:17 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk0XXawQERH19+iUguDame2Pts_+bvrt8Of0+ib9KSW3NA@mail.gmail.com>
On Sun, Jul 17, 2011 at 08:37:58PM +0200, Sami Kerola wrote:
> default:
> - printf(_("unknown\n"));
> + printf(_("unknown scheduling policy\n"));
what about warnx() ?
> + printf(_("policy : min/max priority\n"
> + "----------------+-----------------\n"));
oh...
> for (i = 0; i < ARRAY_SIZE(policies); i++) {
> int max = sched_get_priority_max(policies[i]);
> int min = sched_get_priority_min(policies[i]);
>
> if (max >= 0 && min >= 0)
> - printf(_("SCHED_%s min/max priority\t: %d/%d\n"),
> + printf(_("SCHED_%-10s: %d/%d\n"),
> names[i], min, max);
...this is not backwardly compatible.
If you really want to have nice output then use include/tt.c (see for
example partx, findmnt or lsblk) and add a new option for such
functionality.
> .SH SYNOPSIS
> .B ionice
> -.RB [[ \-c
> -.IR class ]
> -.RB [ \-n
> -.IR classdata ]
> -.RB [ \-t ]]
> -.BI \-p \ PID
> -.RI [ PID ]...
> +[OPTION] \fB\-p\fR PID [PID...]
> .br
> .B ionice
> -.RB [ \-c
> -.IR class ]
> -.RB [ \-n
> -.IR classdata ]
> -.RB [ \-t ]
> -.IR COMMAND\ [ ARG ]...
> +[OPTION] COMMAND
hmm.. don't forget that people love examples, IMHO the old version
seems more readable.
> textdomain(PACKAGE);
>
> - while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
> + while ((c = getopt_long(argc, argv, "+n:c:p:tVh", longopts, NULL)) != EOF)
> switch (c) {
> case 'n':
> - ioprio = strtol_or_err(optarg, _("failed to parse class data"));
> + ioprio = strtol_or_err(optarg, _("failed to parse priority"));
well, the original kernel Documentation/block/ioprio.txt is talking
about "class data" and I think it would be better to follow kernel
here. Maybe one day the mask for the syscall will used for a different
things than only for priority...
> + case 'V':
> + printf(_("%s (%s)\n"),
"%s from %s" ;-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] fdformat fixes
From: Karel Zak @ 2011-07-18 21:49 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk2uumAs8nhh1EdHHR+v92vOKqK19WSEaNSjnjwHSCjstw@mail.gmail.com>
On Mon, Jul 11, 2011 at 07:05:36PM +0200, Sami Kerola wrote:
> The following changes since commit 365acc97654d33a01698ada9bf18fbbdce7d88cc:
>
> fdisk: use a single variable for the current disklabel (2011-07-11
> 12:01:42 +0200)
>
> are available in the git repository at:
> https://github.com/kerolasa/lelux-utiliteetit fdformat
>
> Sami Kerola (7):
> fdformat: use libc error printing facilities
> fdformat: use long options
> fdformat: integer comparisons & unused parameter
> fdformat: use xalloc.h
> fdformat: include-what-you-use header check
> fdformat: coding style
> docs: add long options to fdformat.8
>
> disk-utils/fdformat.8 | 18 ++--
> disk-utils/fdformat.c | 253 ++++++++++++++++++++++++++-----------------------
> 2 files changed, 147 insertions(+), 124 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] isosize fixes
From: Karel Zak @ 2011-07-18 21:49 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk0MvKRCW1d_fQ3-k2s4HXTdy-S1NyVC4UFM2Boxig9usA@mail.gmail.com>
On Mon, Jul 11, 2011 at 02:54:04PM +0200, Sami Kerola wrote:
> The following changes since commit 37b94458bd0f4a178233ad0366a727bf5bde879f:
>
> sfdisk: fix coding style. (2011-06-29 12:47:38 +0200)
>
> are available in the git repository at:
> https://github.com/kerolasa/lelux-utiliteetit isosize
>
> Sami Kerola (6):
> isosize: remove global variables
> isosize: use long options
> isosize: check user input to be numeric
> isosize: include-what-you-use header check
> isosize: fix coding style
> docs: isosize.8 add long options
>
> disk-utils/Makefile.am | 1 +
> disk-utils/isosize.8 | 16 ++--
> disk-utils/isosize.c | 221 +++++++++++++++++++++++++-----------------------
> 3 files changed, 122 insertions(+), 116 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH v2] dmesg: fix segfault
From: Karel Zak @ 2011-07-18 21:47 UTC (permalink / raw)
To: Marc-Antoine Perennou; +Cc: util-linux
In-Reply-To: <CACpTwpHENHMCSxkh4a-Z5SHVifa=M7ai2XNtfY1An2TiUPc84A@mail.gmail.com>
On Mon, Jul 18, 2011 at 07:37:22PM +0200, Marc-Antoine Perennou wrote:
> An element declared as size_t cannot be detected as negative (len < 0)
> is always false.
> This can lead to an infinite loop causing a segmentation fault.
> Check if len is equal to -1 or -2 instead
>
> Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
> ---
> sys-utils/dmesg.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: dmesg: fix segfqult
From: Mike Frysinger @ 2011-07-18 18:12 UTC (permalink / raw)
To: Marc-Antoine Perennou; +Cc: util-linux
In-Reply-To: <CAJaTeTp2Aj4yN3iZkH2S0s=NtUXcvD=hURz9DK8edsZz7xSKKg@mail.gmail.com>
and you can ignore me as i simply didnt finish going through my inbox
and you've already posted a v2 doing it right ;x
-mike
^ permalink raw reply
* Re: dmesg: fix segfqult
From: Mike Frysinger @ 2011-07-18 18:12 UTC (permalink / raw)
To: Marc-Antoine Perennou; +Cc: util-linux
In-Reply-To: <CAJaTeTrdvGBpMf8quzORSjkcnVt=ZWeJ2DvPZDChZ+hO_W60Vw@mail.gmail.com>
On Mon, Jul 18, 2011 at 14:11, Mike Frysinger wrote:
> On Mon, Jul 18, 2011 at 12:45, Marc-Antoine Perennou wrote:
>> - size_t len = mbrtowc(&wc, p, size - i, &s);
>> + int len = mbrtowc(&wc, p, size - i, &s);
>
> this is wrong for systems where sizeof(size_t) != sizeof(int). i
> think you want to fix the code like the man page indicates ... do "if
> (len < (size_t)-1) ....."
err, something like "if (len == (size_t)-1) { /* handle error */ }"
-mike
^ permalink raw reply
* Re: dmesg: fix segfqult
From: Mike Frysinger @ 2011-07-18 18:11 UTC (permalink / raw)
To: Marc-Antoine Perennou; +Cc: util-linux
In-Reply-To: <CACpTwpGZHf4dY72T6-nNLWCEU9CM2h58OQvCVgDZiKxsOorxVw@mail.gmail.com>
On Mon, Jul 18, 2011 at 12:45, Marc-Antoine Perennou wrote:
> - size_t len = mbrtowc(&wc, p, size - i, &s);
> + int len = mbrtowc(&wc, p, size - i, &s);
this is wrong for systems where sizeof(size_t) != sizeof(int). i
think you want to fix the code like the man page indicates ... do "if
(len < (size_t)-1) ....."
-mike
^ permalink raw reply
* [PATCH v2] dmesg: fix segfault
From: Marc-Antoine Perennou @ 2011-07-18 17:37 UTC (permalink / raw)
To: util-linux
An element declared as size_t cannot be detected as negative (len < 0)
is always false.
This can lead to an infinite loop causing a segmentation fault.
Check if len is equal to -1 or -2 instead
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
---
sys-utils/dmesg.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 867581d..d7cf95b 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -367,7 +367,7 @@ static void safe_fwrite(const char *buf, size_t
size, FILE *out)
if (len == 0) /* L'\0' */
return;
- if (len < 0) { /* invalid sequence */
+ if (len == (size_t)-1 || len == (size_t)-2) { /* invalid sequence */
memset(&s, 0, sizeof (s));
len = hex = 1;
--
1.7.6.134.gcf13f6.dirty
^ permalink raw reply related
* RE: dmesg: fix segfqult
From: Voelker, Bernhard @ 2011-07-18 17:12 UTC (permalink / raw)
To: Marc-Antoine Perennou, util-linux@vger.kernel.org
In-Reply-To: <CACpTwpGZHf4dY72T6-nNLWCEU9CM2h58OQvCVgDZiKxsOorxVw@mail.gmail.com>
Marc-Antoine Perennou wrote:
> An element declared as size_t cannot be detected as negative (len < 0
> is always false).
> This can lead to an infinite loop causing a segmentation fault.
> Use an int to solve this issue
>
> Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
> ---
> sys-utils/dmesg.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
> index 867581d..91855a1 100644
> --- a/sys-utils/dmesg.c
> +++ b/sys-utils/dmesg.c
> @@ -362,7 +362,7 @@ static void safe_fwrite(const char *buf, size_t
> size, FILE *out)
>
> #ifdef HAVE_WIDECHAR
> wchar_t wc;
> - size_t len = mbrtowc(&wc, p, size - i, &s);
> + int len = mbrtowc(&wc, p, size - i, &s);
>
> if (len == 0) /* L'\0' */
> return;
> --
> 1.7.6.134.gcf13f6.dirty
> --
Interestingly, there are other projects which fell into the same trap:
* mc: https://bugzilla.redhat.com/show_bug.cgi?id=150569
Have a nice day,
Berny
^ permalink raw reply
* dmesg: fix segfqult
From: Marc-Antoine Perennou @ 2011-07-18 16:45 UTC (permalink / raw)
To: util-linux
An element declared as size_t cannot be detected as negative (len < 0
is always false).
This can lead to an infinite loop causing a segmentation fault.
Use an int to solve this issue
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
---
sys-utils/dmesg.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 867581d..91855a1 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -362,7 +362,7 @@ static void safe_fwrite(const char *buf, size_t
size, FILE *out)
#ifdef HAVE_WIDECHAR
wchar_t wc;
- size_t len = mbrtowc(&wc, p, size - i, &s);
+ int len = mbrtowc(&wc, p, size - i, &s);
if (len == 0) /* L'\0' */
return;
--
1.7.6.134.gcf13f6.dirty
^ permalink raw reply related
* Re: [PATCH] lscpu: add support for books
From: Jon Stanley @ 2011-07-18 15:17 UTC (permalink / raw)
To: Karel Zak; +Cc: Heiko Carstens, util-linux
In-Reply-To: <20110718091017.GI3486@nb.net.home>
On Mon, Jul 18, 2011 at 5:10 AM, Karel Zak <kzak@redhat.com> wrote:
> =A0I'm not sure if the currently used extra separators (,,) for the
> =A0caches is a good idea. Maybe it would be better to force people to
> =A0parse the last comment line where is the header for the columns.
Speaking as a user of lscpu, I think that forcing people to parse the
last comment line is not a particularly good idea - no one is used to
doing it, and I'm not sure of any other utility that forces you to
parse it's "machine-readable" output. Stability of this format is key.
> =A0The ideal solution is to extend the "-p" functionality and allow to
> =A0specify expected columns at command line, something like:
>
> =A0 =A0lscpu -p -o cpu,core,book,socket
I think that this is the only long-term supportable way to do this.
CPU architectures (even in the x86 world that I'm interested in) ARE
going to change and evolve. Heck, it's even possible that concepts
like the hypervisor scheduling parameters that you mentioned on s390
could eventually make their way down to x86 virtualization, and
exposing stuff like that in lscpu would be nice.
^ permalink raw reply
* Re: [PATCH] dmesg.c: print human readable timestamp
From: corentin.labbe @ 2011-07-18 14:56 UTC (permalink / raw)
To: util-linux
In-Reply-To: <20110629145957.GM6418@nb.net.home>
Le 29/06/2011 16:59, Karel Zak a écrit :
> On Fri, May 20, 2011 at 02:06:21PM +0200, corentin.labbe wrote:
>>
>> This patch add the -H option to dmesg which allow to print human
>> readable time instead of the number of seconds since boot.
>
> Nice idea, but it's not so simple :-(
>
> The time stamp used for printk() is not based on normal system time
> (as you know from gettimeofday()). It uses cpu_clock() (IMHO to
> keep printk() robust and without xtime_lock).
>
> The problem is that the cpu_clock is not updated after system resume,
> so if you suspend (e.g. pm-suspend(8)) and resume than the dmesg -H
> command prints nonsenses...
>
> For example (copy & past from /var/log/messages):
>
> Jun 27 23:39:53 nb kernel: [50065.238635] PM: Syncing filesystems ... done.
> Jun 28 20:23:29 nb kernel: [50065.284226] Freezing user space processes ... (elapsed 0.09 seconds) done.
> ^^^^^
> The first line is before suspend and second is after resume. The time
> stamp [50065.xxxxxx] is still the same although the system was
> suspended for almost whole day.
>
> The same system, the latest kernel message:
>
> # date
> Wed Jun 29 16:29:28 CEST 2011
>
> # mount /dev/sdb1 /mnt/test
>
> # ./sys-utils/dmesg -H | tail -1
> [Tue Jun 28 11:10:41 2011] EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts: (null)
>
>
> Karel
>
Perhaps we could keep my patch and add a warning about "problem with suspend/resume" (both at first line when -H is used and in manpages).
Like "Warning timestamp could be inaccurate if you have used SUSPEND/RESUME"
If you are agree with that I will update my patch accordingly.
Bests regards
^ permalink raw reply
* Re: dmesg(1) changes
From: Thomas Bächler @ 2011-07-18 13:00 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110714115231.GF3486@nb.net.home>
Am 14.07.2011 13:52, schrieb Karel Zak:
>
> Hi,
>
> I did some changes to dmesg(1) in last days:
Thanks for these advances.
While we're making a wishlist, I always wanted a 'follow' option
(similar to tail -f/-F) for dmesg.
^ permalink raw reply
* Re: dmesg(1) changes
From: Karel Zak @ 2011-07-18 9:52 UTC (permalink / raw)
To: Lennart Poettering, Kay Sievers; +Cc: util-linux
In-Reply-To: <20110714124034.GB23998@tango.0pointer.de>
On Thu, Jul 14, 2011 at 02:40:34PM +0200, Lennart Poettering wrote:
> One last thing on my wishlist: "dmesg -k" as alias for "dmesg
> --facility=kern", just to make this presumably very often requested
> switch is easy to reach.
Added:
-u : userspace messages
-k : kernel messages
On Thu, Jul 14, 2011 at 03:45:30PM +0200, Kay Sievers wrote:
> People ask since a while for an option to suppress the kernel's [...]
> timestamp from the 'dmesg' output. Maybe you can make them happy too.
> :)
Added -t to suppress the timestamps.
$ dmesg -u -t
dracut: dracut-009-11.fc15
dracut: rd.luks=0: removing cryptoluks activation
dracut: rd.lvm=0: removing LVM activation
udev[111]: starting version 167
dracut: Starting plymouth daemon
dracut: rd.dm=0: removing DM RAID activation
dracut: rd.md=0: removing MD RAID activation
dracut: Checking filesystems
dracut: fsck -T -t noopts=_netdev -A -a
dracut: /dev/sda3: clean, 194520/1921360 files, 1601560/7680000
blocks
dracut: Remounting
/dev/disk/by-uuid/2cda1e08-1f22-490b-9101-c93d511bc9d9 with -o ro,
dracut: Mounted root filesystem /dev/sda3
dracut: Switching root
udev[451]: starting version 167
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] lscpu: add support for books
From: Karel Zak @ 2011-07-18 9:10 UTC (permalink / raw)
To: Heiko Carstens; +Cc: util-linux
In-Reply-To: <20110713034618.GA2968@osiris.boeblingen.de.ibm.com>
On Wed, Jul 13, 2011 at 09:16:18AM +0530, Heiko Carstens wrote:
> thanks. I updated the patch accordingly (see below).
Applied, thanks.
> Just another thing: there are more per cpu informations that are present
> on s390 that I would also like to the parseable output. However, somehow
> it won't fit to the current approach that lscpu -p prints everything
> with a unique id starting from zero.
> For example the cpus on s390 can be in any of one of the states
> horizontal,vertical:low,vertical:medium or vertical:high (that's just
> an information of how the hypervisor schedules the cpus).
> How is that supposed to be mapped to current approach?
> Map these simply to numbers? E.g. horizontal would be mapped to 0,
> vertical:low would be mapped to 1 and so on?
Probably, the most important is keep it backwardly compatible ;-)
> Also would I also need a new seperation character between caches and
> new information?
I'm not sure if the currently used extra separators (,,) for the
caches is a good idea. Maybe it would be better to force people to
parse the last comment line where is the header for the columns.
> I'm asking because the output of caches is optional and if something
> new would be added, it seem to get messy in the long term because of
> all seperation characters that may or may not be there. No?
I agree. Maybe you can add the new things before the caches (as you
already added 'Book' column).
The ideal solution is to extend the "-p" functionality and allow to
specify expected columns at command line, something like:
lscpu -p -o cpu,core,book,socket
We already use the same idea for findmnt and lscpu.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* [git pull] schedutils
From: Sami Kerola @ 2011-07-17 18:37 UTC (permalink / raw)
To: util-linux
The following changes since commit 64c9e22aa47ea262f8e01c2aff1d48890d6e4e8b:
lsblk: add queue request size attribute (2011-07-15 15:41:22 +0200)
are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit schedutils
Sami Kerola (10):
chrt: data type compiler warning fixed
chrt: coding style fix
ionice: add long options
ionice: coding style fixes
docs: mention long options in ionice.1
taskset: include-what-you-use header check
taskset: coding style fixes
chrt: change how min/max is expressed
chrt: add strings to use NLS
docs: update TODO file
TODO | 2 -
schedutils/chrt.c | 55 +++++++++++++++++++++++------------------
schedutils/ionice.1 | 51 +++++++++++++++++++-------------------
schedutils/ionice.c | 66 +++++++++++++++++++++++++++++++------------------
schedutils/taskset.c | 34 +++++++++++++------------
5 files changed, 116 insertions(+), 92 deletions(-)
diff --git a/TODO b/TODO
index 6fe25cc..e90c432 100644
--- a/TODO
+++ b/TODO
@@ -192,8 +192,6 @@ misc
* use TZ=UTC and LANG=en_US.UTF-8 for tests
- * add NLS and err.h stuff to schedutils (chrt.c, taskset.c)
-
* add mllockall() and SCHED_FIFO to hwclock,
see http://lkml.org/lkml/2008/10/12/132
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 6c2c6f2..effa302 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -117,7 +117,7 @@ static void show_rt_info(pid_t pid, int isnew)
printf("SCHED_FIFO\n");
break;
#ifdef SCHED_RESET_ON_FORK
- case SCHED_FIFO|SCHED_RESET_ON_FORK:
+ case SCHED_FIFO | SCHED_RESET_ON_FORK:
printf("SCHED_FIFO|SCHED_RESET_ON_FORK\n");
break;
#endif
@@ -130,7 +130,7 @@ static void show_rt_info(pid_t pid, int isnew)
printf("SCHED_RR\n");
break;
#ifdef SCHED_RESET_ON_FORK
- case SCHED_RR|SCHED_RESET_ON_FORK:
+ case SCHED_RR | SCHED_RESET_ON_FORK:
printf("SCHED_RR|SCHED_RESET_ON_FORK\n");
break;
#endif
@@ -140,7 +140,7 @@ static void show_rt_info(pid_t pid, int isnew)
break;
#endif
default:
- printf(_("unknown\n"));
+ printf(_("unknown scheduling policy\n"));
}
if (sched_getparam(pid, &sp))
@@ -156,37 +156,45 @@ static void show_rt_info(pid_t pid, int isnew)
static void show_min_max(void)
{
- int i;
- int policies[] = { SCHED_OTHER, SCHED_FIFO, SCHED_RR,
+ unsigned long i;
+ int policies[] = {
+ SCHED_OTHER,
+ SCHED_FIFO,
+ SCHED_RR,
#ifdef SCHED_BATCH
- SCHED_BATCH,
+ SCHED_BATCH,
#endif
#ifdef SCHED_IDLE
- SCHED_IDLE,
+ SCHED_IDLE,
#endif
- };
- const char *names[] = { "OTHER", "FIFO", "RR",
+ };
+ const char *names[] = {
+ "OTHER",
+ "FIFO",
+ "RR",
#ifdef SCHED_BATCH
- "BATCH",
+ "BATCH",
#endif
#ifdef SCHED_IDLE
- "IDLE",
+ "IDLE",
#endif
- };
+ };
+ printf(_("policy : min/max priority\n"
+ "----------------+-----------------\n"));
for (i = 0; i < ARRAY_SIZE(policies); i++) {
int max = sched_get_priority_max(policies[i]);
int min = sched_get_priority_min(policies[i]);
if (max >= 0 && min >= 0)
- printf(_("SCHED_%s min/max priority\t: %d/%d\n"),
+ printf(_("SCHED_%-10s: %d/%d\n"),
names[i], min, max);
else
printf(_("SCHED_%s not supported?\n"), names[i]);
}
}
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
{
int i, policy = SCHED_RR, priority = 0, verbose = 0, policy_flag = 0,
all_tasks = 0;
@@ -241,7 +249,7 @@ int main(int argc, char *argv[])
break;
case 'm':
show_min_max();
- return 0;
+ return EXIT_SUCCESS;
case 'o':
policy = SCHED_OTHER;
break;
@@ -257,7 +265,7 @@ int main(int argc, char *argv[])
break;
case 'V':
printf("chrt (%s)\n", PACKAGE_STRING);
- return 0;
+ return EXIT_SUCCESS;
case 'h':
ret = EXIT_SUCCESS;
default:
@@ -265,7 +273,8 @@ int main(int argc, char *argv[])
}
}
- if (((pid > -1) && argc - optind < 1) || ((pid == -1) && argc - optind < 2))
+ if (((pid > -1) && argc - optind < 1) ||
+ ((pid == -1) && argc - optind < 2))
show_usage(EXIT_FAILURE);
if ((pid > -1) && (verbose || argc - optind == 1)) {
@@ -274,7 +283,7 @@ int main(int argc, char *argv[])
struct proc_tasks *ts = proc_open_tasks(pid);
if (!ts)
- err(EXIT_FAILURE, "cannot obtain the list of tasks");
+ err(EXIT_FAILURE, _("cannot obtain the list of tasks"));
while (!proc_next_tid(ts, &tid))
show_rt_info(tid, FALSE);
proc_close_tasks(ts);
@@ -293,7 +302,7 @@ int main(int argc, char *argv[])
if ((policy_flag & SCHED_RESET_ON_FORK) &&
!(policy == SCHED_FIFO || policy == SCHED_RR))
errx(EXIT_FAILURE, _("SCHED_RESET_ON_FORK flag is suppoted for "
- "SCHED_FIFO and SCHED_RR policies only"));
+ "SCHED_FIFO and SCHED_RR policies only"));
#endif
policy |= policy_flag;
@@ -307,15 +316,13 @@ int main(int argc, char *argv[])
struct proc_tasks *ts = proc_open_tasks(pid);
if (!ts)
- err(EXIT_FAILURE, "cannot obtain the list of tasks");
+ err(EXIT_FAILURE, _("cannot obtain the list of tasks"));
while (!proc_next_tid(ts, &tid))
if (sched_setscheduler(tid, policy, &sp) == -1)
err(EXIT_FAILURE, _("failed to set tid %d's policy"), tid);
proc_close_tasks(ts);
- }
- else
- if (sched_setscheduler(pid, policy, &sp) == -1)
- err(EXIT_FAILURE, _("failed to set pid %d's policy"), pid);
+ } else if (sched_setscheduler(pid, policy, &sp) == -1)
+ err(EXIT_FAILURE, _("failed to set pid %d's policy"), pid);
if (verbose)
show_rt_info(pid, TRUE);
diff --git a/schedutils/ionice.1 b/schedutils/ionice.1
index 8e4e964..ed19fae 100644
--- a/schedutils/ionice.1
+++ b/schedutils/ionice.1
@@ -1,28 +1,17 @@
-.TH ionice "1" "August 2005" ionice
+.TH IONICE "1" "July 2011" "util-linux" "User Commands"
.SH NAME
-ionice \- get/set program io scheduling class and priority
+ionice \- sets or gets process io scheduling class and priority
.SH SYNOPSIS
.B ionice
-.RB [[ \-c
-.IR class ]
-.RB [ \-n
-.IR classdata ]
-.RB [ \-t ]]
-.BI \-p \ PID
-.RI [ PID ]...
+[OPTION] \fB\-p\fR PID [PID...]
.br
.B ionice
-.RB [ \-c
-.IR class ]
-.RB [ \-n
-.IR classdata ]
-.RB [ \-t ]
-.IR COMMAND\ [ ARG ]...
+[OPTION] COMMAND
.SH DESCRIPTION
This program sets or gets the io scheduling class and priority for a program.
If no arguments or just \fB\-p\fR is given, \fBionice\fR will query the current
io scheduling class and priority for that process.
-
+.PP
As of this writing, a process can be in one of three scheduling classes:
.IP "\fBIdle\fP"
A program running with idle io priority will only get disk time when no other
@@ -36,17 +25,17 @@ a specific io priority.
This class takes a priority argument from \fI0-7\fR, with lower
number being higher priority. Programs running at the same best effort
priority are served in a round-robin fashion.
-
+.PP
Note that before kernel 2.6.26 a process that has not asked for an io priority
formally uses "\fBnone\fP" as scheduling class, but the io scheduler will treat
such processes as if it were in the best effort class. The priority within the
best effort class will be dynamically derived from the cpu nice level of the
process: io_priority = (cpu_nice + 20) / 5.
-
+.PP
For kernels after 2.6.26 with CFQ io scheduler a process that has not asked for
an io priority inherits CPU scheduling class. The io priority is derived from
the cpu nice level of the process (same as before kernel 2.6.26).
-
+.PP
.IP "\fBReal time\fP"
The RT scheduling class is given first access to the disk, regardless of
what else is going on in the system. Thus the RT class needs to be used with
@@ -55,21 +44,31 @@ some care, as it can starve other processes. As
with the best effort class,
will receive on each scheduling window. This scheduling class is not
permitted for an ordinary (i.e., non-root) user.
.SH OPTIONS
-.IP "\fB-c \fIclass\fP"
+.TP
+\fB\-c\fR, \fB\-\-class\fR=\fINUM\fR
The scheduling class. \fI0\fR for none, \fI1\fR for real time, \fI2\fR for
best-effort, \fI3\fR for idle.
-.IP "\fB-n \fIclassdata\fP"
-The scheduling class data. This defines the class data, if the class
-accepts an argument. For real time and best-effort, \fI0-7\fR is valid
-data.
-.IP "\fB-p \fIpid\fP"
+.TP
+\fB\-n\fR, \fB\-\-priority\fR=\fINUM\fR
+The scheduling priority. This defines the priority, if the class accepts an
+argument. For real time and best-effort, arguments \fI0-7\fR are valid. 0 is
+the highest priority level, 7 is the lowest.
+.TP
+\fB\-p\fR, \fB\-\-pid\fR=\fIPID\fR
Pass in process PID(s) to view or change already running processes.
If this argument
is not given, \fBionice\fP will run the listed program with the given
parameters.
-.IP "\fB-t\fP"
+.TP
+\fB\-t\fR, \fB\-\-ignore\fR
Ignore failure to set requested priority. If COMMAND or PID(s) is
specified, run it
even in case it was not possible to set desired scheduling priority, what
can happen due to insufficient privileges or old kernel version.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Output version information and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help and exit.
.SH EXAMPLES
.LP
.TP 7
diff --git a/schedutils/ionice.c b/schedutils/ionice.c
index dc18add..17b735a 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -74,35 +74,52 @@ static void ioprio_setpid(pid_t pid, int ioprio,
int ioclass)
err(EXIT_FAILURE, _("ioprio_set failed"));
}
-static void usage(int rc)
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
- fprintf(stdout, _(
- "\nionice - sets or gets process io scheduling class and priority.\n"
- "\nUsage:\n"
- " ionice [ options ] -p <pid> [<pid> ...]\n"
- " ionice [ options ] <command> [<arg> ...]\n"
- "\nOptions:\n"
- " -n <classdata> class data (0-7, lower being higher prio)\n"
- " -c <class> scheduling class\n"
- " 0: none, 1: realtime, 2: best-effort, 3: idle\n"
- " -t ignore failures\n"
- " -h this help\n\n"));
- exit(rc);
+ fprintf(out,
+ _("\n"
+ "%1$s - sets or gets process io scheduling class and priority.\n"
+ "\n"
+ "Usage:\n"
+ " %1$s [OPTION] -p PID [PID...]\n"
+ " %1$s [OPTION] COMMAND\n"
+ "\n"
+ "Options:\n"
+ " -p, --pid=PID view or modify already running process\n"
+ " -n, --priority=NUM priority 0 to 7, where 0 is highest priority\n"
+ " -c, --class=NUM scheduling class\n"
+ " 0: none, 1: realtime, 2: best-effort, 3: idle\n"
+ " -t, --ignore ignore failures\n"
+ " -V, --version output version information and exit\n"
+ " -h, --help display this help and exit\n\n"),
+ program_invocation_short_name);
+
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
{
int ioprio = 4, set = 0, ioclass = IOPRIO_CLASS_BE, c;
pid_t pid = 0;
+ static const struct option longopts[] = {
+ {"pid", required_argument, NULL, 'p'},
+ {"priority", required_argument, NULL, 'n'},
+ {"class", required_argument, NULL, 'c'},
+ {"ignore", no_argument, NULL, 't'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
+ while ((c = getopt_long(argc, argv, "+n:c:p:tVh", longopts, NULL)) != EOF)
switch (c) {
case 'n':
- ioprio = strtol_or_err(optarg, _("failed to parse class data"));
+ ioprio = strtol_or_err(optarg, _("failed to parse priority"));
set |= 1;
break;
case 'c':
@@ -115,12 +132,15 @@ int main(int argc, char *argv[])
case 't':
tolerant = 1;
break;
+ case 'V':
+ printf(_("%s (%s)\n"),
+ program_invocation_short_name, PACKAGE_STRING);
+ return EXIT_SUCCESS;
case 'h':
- usage(EXIT_SUCCESS);
+ usage(stdout);
default:
- usage(EXIT_FAILURE);
+ usage(stderr);
}
- }
switch (ioclass) {
case IOPRIO_CLASS_NONE:
@@ -151,13 +171,11 @@ int main(int argc, char *argv[])
if (pid) {
ioprio_setpid(pid, ioprio, ioclass);
- for(; argv[optind]; ++optind)
- {
+ for(; argv[optind]; ++optind) {
pid = strtol_or_err(argv[optind], _("failed to parse pid"));
ioprio_setpid(pid, ioprio, ioclass);
}
- }
- else if (argv[optind]) {
+ } else if (argv[optind]) {
ioprio_setpid(0, ioprio, ioclass);
execvp(argv[optind], &argv[optind]);
/* execvp should never return */
@@ -165,5 +183,5 @@ int main(int argc, char *argv[])
}
}
- exit(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}
diff --git a/schedutils/taskset.c b/schedutils/taskset.c
index 6f0fbc9..a3dcf52 100644
--- a/schedutils/taskset.c
+++ b/schedutils/taskset.c
@@ -24,6 +24,9 @@
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
+#include <sched.h>
+#include <stddef.h>
+#include <string.h>
#include "cpuset.h"
#include "nls.h"
@@ -34,13 +37,10 @@
struct taskset {
pid_t pid; /* task PID */
-
cpu_set_t *set; /* task CPU mask */
size_t setsize;
-
char *buf; /* buffer for conversion from mask to string */
size_t buflen;
-
int use_list:1, /* use list rather than masks */
get_only:1; /* print the mask, but not modify */
};
@@ -104,7 +104,7 @@ static void do_taskset(struct taskset *ts, size_t
setsize, cpu_set_t *set)
if (ts->pid) {
if (sched_getaffinity(ts->pid, ts->setsize, ts->set) < 0)
err(EXIT_FAILURE, _("failed to get pid %d's affinity"),
- ts->pid);
+ ts->pid);
print_affinity(ts, FALSE);
}
@@ -113,33 +113,34 @@ static void do_taskset(struct taskset *ts,
size_t setsize, cpu_set_t *set)
/* set new mask */
if (sched_setaffinity(ts->pid, setsize, set) < 0)
- err(EXIT_FAILURE, _("failed to set pid %d's affinity"), ts->pid);
+ err(EXIT_FAILURE, _("failed to set pid %d's affinity"),
+ ts->pid);
/* re-read the current mask */
if (ts->pid) {
if (sched_getaffinity(ts->pid, ts->setsize, ts->set) < 0)
err(EXIT_FAILURE, _("failed to get pid %d's affinity"),
- ts->pid);
+ ts->pid);
print_affinity(ts, TRUE);
}
}
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
{
cpu_set_t *new_set;
pid_t pid = 0;
int c, all_tasks = 0;
- unsigned int ncpus;
+ unsigned int ncpus;
size_t new_setsize, nbits;
struct taskset ts;
static const struct option longopts[] = {
- { "all-tasks", 0, NULL, 'a' },
+ { "all-tasks", 0, NULL, 'a' },
{ "pid", 0, NULL, 'p' },
{ "cpu-list", 0, NULL, 'c' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
- { NULL, 0, NULL, 0 }
+ { NULL, 0, NULL, 0 }
};
setlocale(LC_ALL, "");
@@ -154,7 +155,8 @@ int main(int argc, char *argv[])
all_tasks = 1;
break;
case 'p':
- pid = strtol_or_err(argv[argc - 1], _("failed to parse pid"));
+ pid = strtol_or_err(argv[argc - 1],
+ _("failed to parse pid"));
break;
case 'c':
ts.use_list = 1;
@@ -172,7 +174,7 @@ int main(int argc, char *argv[])
}
if ((!pid && argc - optind < 2)
- || (pid && (argc - optind < 1 || argc - optind > 2)))
+ || (pid && (argc - optind < 1 || argc - optind > 2)))
usage(stderr);
ncpus = get_max_number_of_cpus();
@@ -207,18 +209,18 @@ int main(int argc, char *argv[])
else if (ts.use_list) {
if (cpulist_parse(argv[optind], new_set, new_setsize))
errx(EXIT_FAILURE, _("failed to parse CPU list: %s"),
- argv[optind]);
+ argv[optind]);
} else if (cpumask_parse(argv[optind], new_set, new_setsize)) {
errx(EXIT_FAILURE, _("failed to parse CPU mask: %s"),
- argv[optind]);
+ argv[optind]);
}
if (all_tasks) {
struct proc_tasks *tasks = proc_open_tasks(pid);
- while (!proc_next_tid(tasks, &ts.pid))
+ while (!proc_next_tid(tasks, &ts.pid))
do_taskset(&ts, new_setsize, new_set);
proc_close_tasks(tasks);
- } else {
+ } else {
ts.pid = pid;
do_taskset(&ts, new_setsize, new_set);
}
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply related
* Re: [PATCH] minix: v3 super-block does not have s_state field
From: Sami Kerola @ 2011-07-14 15:47 UTC (permalink / raw)
To: Karel Zak; +Cc: Davidlohr Bueso, util-linux
In-Reply-To: <20110714091829.GE3486@nb.net.home>
On Thu, Jul 14, 2011 at 11:18, Karel Zak <kzak@redhat.com> wrote:
> =A0Applied. It would be nice to clean up the superblocks definitions
> =A0(use POSIX int types), move it to include/minix.h and use it for
> =A0libblkid too.
By any change would the following be the 'nice to have' you referred to?
The following changes since commit 872a1575e81f5ed1e871d4ed9558f43effe96423=
:
dmesg: fix typo in usage() (2011-07-14 13:46:13 +0200)
are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit minix
Sami Kerola (7):
include: minix.h: use data types from stdint.h
include: remove kernel headers from minix.h
include: move minix.h to include directory
libblkid: use superblock structure from minix.h
libblkid: use BLOCK_SIZE from minix.h
include: minix.h use static variables
libblkid: move MINIX_MAXPARTITIONS to minix.h
disk-utils/Makefile.am | 4 +-
include/Makefile.am | 1 +
{disk-utils =3D> include}/minix.h | 100 ++++++++++++++++++--------------=
------
libblkid/src/partitions/minix.c | 6 +--
libblkid/src/superblocks/minix.c | 37 +-------------
5 files changed, 54 insertions(+), 94 deletions(-)
rename {disk-utils =3D> include}/minix.h (74%)
diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index 7d018b5..dc1b9c7 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -15,8 +15,8 @@ dist_man_MANS =3D isosize.8 mkfs.8 mkswap.8 \
sbin_PROGRAMS =3D mkfs mkswap fsck.minix mkfs.minix mkfs.bfs
-fsck_minix_SOURCES =3D fsck.minix.c minix.h $(top_srcdir)/lib/ismounted.c
-mkfs_minix_SOURCES =3D mkfs.minix.c minix.h mkfs.h $(utils_common)
$(top_srcdir)/lib/strutils.c
+fsck_minix_SOURCES =3D fsck.minix.c $(top_srcdir)/lib/ismounted.c
+mkfs_minix_SOURCES =3D mkfs.minix.c mkfs.h $(utils_common)
$(top_srcdir)/lib/strutils.c
mkfs_bfs_SOURCES =3D mkfs.bfs.c $(utils_common)
swaplabel_SOURCES =3D swaplabel.c $(utils_common)
diff --git a/include/Makefile.am b/include/Makefile.am
index b6d9bb1..acc0c1b 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -19,6 +19,7 @@ dist_noinst_HEADERS =3D \
mangle.h \
mbsalign.h \
md5.h \
+ minix.h \
nls.h \
pathnames.h \
procutils.h \
diff --git a/disk-utils/minix.h b/include/minix.h
similarity index 74%
rename from disk-utils/minix.h
rename to include/minix.h
index a13a2a4..e25946e 100644
--- a/disk-utils/minix.h
+++ b/include/minix.h
@@ -1,69 +1,65 @@
#ifndef __MINIX_H__
#define __MINIX_H__
-#ifdef KERNEL_INCLUDES_ARE_CLEAN
-
-#include <linux/fs.h>
-#include <linux/minix_fs.h>
-
-#else
-
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
+#include <stdint.h>
struct minix_inode {
- u16 i_mode;
- u16 i_uid;
- u32 i_size;
- u32 i_time;
- u8 i_gid;
- u8 i_nlinks;
- u16 i_zone[9];
+ uint16_t i_mode;
+ uint16_t i_uid;
+ uint32_t i_size;
+ uint32_t i_time;
+ uint8_t i_gid;
+ uint8_t i_nlinks;
+ uint16_t i_zone[9];
};
struct minix2_inode {
- u16 i_mode;
- u16 i_nlinks;
- u16 i_uid;
- u16 i_gid;
- u32 i_size;
- u32 i_atime;
- u32 i_mtime;
- u32 i_ctime;
- u32 i_zone[10];
+ uint16_t i_mode;
+ uint16_t i_nlinks;
+ uint16_t i_uid;
+ uint16_t i_gid;
+ uint32_t i_size;
+ uint32_t i_atime;
+ uint32_t i_mtime;
+ uint32_t i_ctime;
+ uint32_t i_zone[10];
};
struct minix_super_block {
- u16 s_ninodes;
- u16 s_nzones;
- u16 s_imap_blocks;
- u16 s_zmap_blocks;
- u16 s_firstdatazone;
- u16 s_log_zone_size;
- u32 s_max_size;
- u16 s_magic;
- u16 s_state;
- u32 s_zones;
+ uint16_t s_ninodes;
+ uint16_t s_nzones;
+ uint16_t s_imap_blocks;
+ uint16_t s_zmap_blocks;
+ uint16_t s_firstdatazone;
+ uint16_t s_log_zone_size;
+ uint32_t s_max_size;
+ uint16_t s_magic;
+ uint16_t s_state;
+ uint32_t s_zones;
};
/* V3 minix super-block data on disk */
struct minix3_super_block {
- u32 s_ninodes;
- u16 s_pad0;
- u16 s_imap_blocks;
- u16 s_zmap_blocks;
- u16 s_firstdatazone;
- u16 s_log_zone_size;
- u16 s_pad1;
- u32 s_max_size;
- u32 s_zones;
- u16 s_magic;
- u16 s_pad2;
- u16 s_blocksize;
- u8 s_disk_version;
+ uint32_t s_ninodes;
+ uint16_t s_pad0;
+ uint16_t s_imap_blocks;
+ uint16_t s_zmap_blocks;
+ uint16_t s_firstdatazone;
+ uint16_t s_log_zone_size;
+ uint16_t s_pad1;
+ uint32_t s_max_size;
+ uint32_t s_zones;
+ uint16_t s_magic;
+ uint16_t s_pad2;
+ uint16_t s_blocksize;
+ uint8_t s_disk_version;
};
+/*
+ * Minix subpartitions are always within primary dos partition.
+ */
+#define MINIX_MAXPARTITIONS 4
+
#define BLOCK_SIZE_BITS 10
#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
@@ -82,16 +78,14 @@ struct minix3_super_block {
#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
#define MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 fs (60 char names=
) */
-#endif /* KERNEL_INCLUDES_ARE_CLEAN */
-
#define Inode (((struct minix_inode *) inode_buffer)-1)
#define Inode2 (((struct minix2_inode *) inode_buffer)-1)
#define INODE_SIZE (sizeof(struct minix_inode))
#define INODE2_SIZE (sizeof(struct minix2_inode))
-int fs_version =3D 1; /* this default value needs to change in a near futu=
re */
-char *super_block_buffer, *inode_buffer =3D NULL;
+static int fs_version =3D 1; /* this default value needs to change in a
near future */
+static char *super_block_buffer, *inode_buffer =3D NULL;
static char *inode_map;
static char *zone_map;
diff --git a/libblkid/src/partitions/minix.c b/libblkid/src/partitions/mini=
x.c
index 0887d1a..b67d2c7 100644
--- a/libblkid/src/partitions/minix.c
+++ b/libblkid/src/partitions/minix.c
@@ -13,11 +13,7 @@
#include "partitions.h"
#include "dos.h"
-
-/*
- * Minix subpartitions are always within primary dos partition.
- */
-#define MINIX_MAXPARTITIONS 4
+#include "minix.h"
static int probe_minix_pt(blkid_probe pr, const struct blkid_idmag *mag)
{
diff --git a/libblkid/src/superblocks/minix.c b/libblkid/src/superblocks/mi=
nix.c
index 3290c27..e821ea7 100644
--- a/libblkid/src/superblocks/minix.c
+++ b/libblkid/src/superblocks/minix.c
@@ -11,38 +11,7 @@
#include <string.h>
#include "superblocks.h"
-
-struct minix_super_block {
- uint16_t s_ninodes;
- uint16_t s_nzones;
- uint16_t s_imap_blocks;
- uint16_t s_zmap_blocks;
- uint16_t s_firstdatazone;
- uint16_t s_log_zone_size;
- uint32_t s_max_size;
- uint16_t s_magic;
- uint16_t s_state;
- uint32_t s_zones;
-};
-
-struct minix3_super_block {
- uint32_t s_ninodes;
- uint16_t s_pad0;
- uint16_t s_imap_blocks;
- uint16_t s_zmap_blocks;
- uint16_t s_firstdatazone;
- uint16_t s_log_zone_size;
- uint16_t s_pad1;
- uint32_t s_max_size;
- uint32_t s_zones;
- uint16_t s_magic;
- uint16_t s_pad2;
- uint16_t s_blocksize;
- uint8_t s_disk_version;
-};
-
-#define MINIX_BLOCK_SIZE_BITS 10
-#define MINIX_BLOCK_SIZE (1 << MINIX_BLOCK_SIZE_BITS)
+#include "minix.h"
static int probe_minix(blkid_probe pr, const struct blkid_idmag *mag)
{
@@ -76,9 +45,9 @@ static int probe_minix(blkid_probe pr, const struct
blkid_idmag *mag)
zones =3D version =3D=3D 2 ? sb->s_zones : sb->s_nzones;
/* sanity checks to be sure that the FS is really minix */
- if (sb->s_imap_blocks * MINIX_BLOCK_SIZE * 8 < sb->s_ninodes + 1)
+ if (sb->s_imap_blocks * BLOCK_SIZE * 8 < sb->s_ninodes + 1)
return -1;
- if (sb->s_zmap_blocks * MINIX_BLOCK_SIZE * 8 < zones -
sb->s_firstdatazone + 1)
+ if (sb->s_zmap_blocks * BLOCK_SIZE * 8 < zones - sb->s_firstdatazone + 1=
)
return -1;
} else if (version =3D=3D 3) {
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply related
* Re: dmesg(1) changes
From: Kay Sievers @ 2011-07-14 13:45 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Lennart Poettering
In-Reply-To: <20110714115231.GF3486@nb.net.home>
On Thu, Jul 14, 2011 at 13:52, Karel Zak <kzak@redhat.com> wrote:
> I did some changes to dmesg(1) in last days:
>
> =C2=A0* \x<hex> encoding is used for non-printable chars and invalid
> =C2=A0 multibyte sequences
>
> =C2=A0* add --decode option to decode facility and level (priotity) numbe=
r to
> =C2=A0 human readable prefixes, for example:
>
> =C2=A0 =C2=A0$ dmesg --decode
> =C2=A0 =C2=A0kern =C2=A0:info =C2=A0: [53335.593617] ata1.00: configured =
for UDMA/100
> =C2=A0 =C2=A0kern =C2=A0:info =C2=A0: [53335.743185] PM: resume of device=
s complete after 2496.795 msecs
> =C2=A0 =C2=A0kern =C2=A0:debug : [53335.743593] PM: Finishing wakeup.
> =C2=A0 =C2=A0kern =C2=A0:warn =C2=A0: [53335.743595] Restarting tasks ...=
done.
> =C2=A0 =C2=A0kern =C2=A0:info =C2=A0: [53335.790452] video LNXVIDEO:00: R=
estoring backlight state
>
> =C2=A0* add --facility=3D<LIST> option to filter out messages, for exampl=
e:
>
> =C2=A0 =C2=A0$ dmesg --facility=3Ddaemon,user
> =C2=A0 =C2=A0[ =C2=A0 =C2=A01.802065] dracut: dracut-009-11.fc15
> =C2=A0 =C2=A0[ =C2=A0 =C2=A01.811267] dracut: rd.luks=3D0: removing crypt=
oluks activation
> =C2=A0 =C2=A0[ =C2=A0 =C2=A01.813913] dracut: rd.lvm=3D0: removing LVM ac=
tivation
> =C2=A0 =C2=A0[ =C2=A0 =C2=A01.819348] udev[111]: starting version 167
>
> =C2=A0* add --level=3D<LIST> option to filter out messages, for example:
>
> =C2=A0 =C2=A0$ dmesg --level=3Ddebug,info
>
> =C2=A0 =C2=A0$ dmesg --facility=3Dkern --level=3Dwarn,err
>
> =C2=A0* add --clear option to clear the kernel ring buffer
>
> =C2=A0* add --read-clear to read and clear the kernel ring buffer
>
> =C2=A0* add --console-off and --console-on to control output to console
>
> =C2=A0* -n <LEVEL> (--console-level) supports human readable level names,
> =C2=A0 for example:
>
> =C2=A0 =C2=A0$ dmesg --console-level=3Demerg,alert
>
> Comments & suggestions?
Sounds all great. Thanks for adding this before people start
complaining that we fill the kernel log with 'userspace crap'. I
actually removed all syslog daemons from my systems, and use only
'dmesg' these days, and no log is stored on disk, I just don't need
it.
People ask since a while for an option to suppress the kernel's [...]
timestamp from the 'dmesg' output. Maybe you can make them happy too.
:)
Thanks,
Kay
^ permalink raw reply
* Re: dmesg(1) changes
From: Lennart Poettering @ 2011-07-14 12:40 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110714115231.GF3486@nb.net.home>
On Thu, 14.07.11 13:52, Karel Zak (kzak@redhat.com) wrote:
> * add --facility=<LIST> option to filter out messages, for example:
>
> $ dmesg --facility=daemon,user
> [ 1.802065] dracut: dracut-009-11.fc15
> [ 1.811267] dracut: rd.luks=0: removing cryptoluks activation
> [ 1.813913] dracut: rd.lvm=0: removing LVM activation
> [ 1.819348] udev[111]: starting version 167
>
>
> Comments & suggestions?
This is really cool! Thanks a lot for implementing this!
One last thing on my wishlist: "dmesg -k" as alias for "dmesg
--facility=kern", just to make this presumably very often requested
switch is easy to reach.
Lennart
--
Lennart Poettering - Red Hat, Inc.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox