* Re: [git pull] hwclock fixes
From: Karel Zak @ 2011-07-27 9:16 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk3x9Oab431BM-+AnjQHYc5cwuDeho3ufzz46PpN_uJ5=Q@mail.gmail.com>
On Tue, Jul 26, 2011 at 06:38:26PM +0200, Sami Kerola wrote:
> All is pushed to my repo with force. Let me know if there is something
> other that needs nudging.
Merged.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: Can't remount loopback ext4 without /etc/mtab
From: Daniel Drake @ 2011-07-26 19:29 UTC (permalink / raw)
To: Karel Zak; +Cc: Ted Ts'o, util-linux
In-Reply-To: <20110725094638.GV22568@nb.net.home>
On 25 July 2011 10:46, Karel Zak <kzak@redhat.com> wrote:
> =A0F-15 uses 2.6.38, the patches are in kernel >=3D v2.6.39-rc7
> =A0(according to git describe --contains).
Indeed. I'm hoping they will include the patches in 2.6.38 for the
next F15 kernel update.
https://bugzilla.redhat.com/show_bug.cgi?id=3D725867
Daniel
^ permalink raw reply
* Re: [git pull] hwclock fixes
From: Sami Kerola @ 2011-07-26 16:38 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110726142212.GB14764@nb.net.home>
On Tue, Jul 26, 2011 at 16:22, Karel Zak <kzak@redhat.com> wrote:
> On Tue, Jul 26, 2011 at 12:42:46AM +0200, Sami Kerola wrote:
>> are available in the git repository at:
>> =A0 https://github.com/kerolasa/lelux-utiliteetit hwclock
>> =A0 =A0 =A0 hwclock: include-what-you-use header check
>
> =A0Hmm.. I see something completely different in the patch:
>
> =A0 =A0Showing 5 changed files with 171 additions and 216 deletions.
>
> =A0it seems like "use libc error facilities".
Do'h. One of my rebase fix something etc had lead to accidental
squash. The commit is split to two as it was meant to be.
>> =A0 =A0 =A0 hwclock: remove inb & outb functions
>
> Are you really sure? I think it depends on the header files, for
> example it seems GNU Hurd reads information from cmos
>
> http://www.spinics.net/lists/util-linux-ng/msg04179.html
>
> and we already talked about it:
>
> http://www.spinics.net/lists/util-linux-ng/index.html#04673
I did not study history well enough before proposing this. The commit
is thrown away.
>> =A0 =A0 =A0 hwclock: fix compiler warnings
>
> This is wrong for __alpha__ code where the variables are used.
>
> Move the comment before the function and the begin of the function to
> the #ifndef __alpha_ block, then you can use __unused__ for non-aplha
> only.
I changed the commit to have complete functions in precompiler if
statements. To me it looks most readable way of doing what you seem to
mean.
>> =A0 =A0 =A0 hwclock: move long options away from global scope
>
> But the enum {} does not have to be in the main().
Moved to the beginning of the file.
All is pushed to my repo with force. Let me know if there is something
other that needs nudging.
--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/
^ permalink raw reply
* Re: [git pull] cramfs fixes
From: Karel Zak @ 2011-07-26 14:25 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk2eA7gypziZ7RSD=CR_XiYvQvGEz-AGq_aYHGe++sZuhw@mail.gmail.com>
On Fri, Jul 22, 2011 at 09:56:24AM +0200, Sami Kerola wrote:
> The fixed & few new patches are available in the git repository at:
> https://github.com/kerolasa/lelux-utiliteetit cramfs
Merged. Thanks.
Note that I'll freeze the code this week, then nothing invasive will be
accepted until the stable release.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [git pull] hwclock fixes
From: Karel Zak @ 2011-07-26 14:22 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
In-Reply-To: <CAG27Bk0EkOe=dbt88PFtDKwyo9+0mZPaysVh0eM9BjWu4X8+vQ@mail.gmail.com>
On Tue, Jul 26, 2011 at 12:42:46AM +0200, Sami Kerola wrote:
> are available in the git repository at:
> https://github.com/kerolasa/lelux-utiliteetit hwclock
>
> hwclock: remove clock-ppc.c
OK
> hwclock: remove misleading information
OK
> hwclock: coding style clean up
OK
> hwclock: include-what-you-use header check
Hmm.. I see something completely different in the patch:
Showing 5 changed files with 171 additions and 216 deletions.
it seems like "use libc error facilities".
> hwclock: move path definitions to pathnames.h
OK
> hwclock: remove inb & outb functions
Are you really sure? I think it depends on the header files, for
example it seems GNU Hurd reads information from cmos
http://www.spinics.net/lists/util-linux-ng/msg04179.html
and we already talked about it:
http://www.spinics.net/lists/util-linux-ng/index.html#04673
> hwclock: fix compiler warnings
This is wrong for __alpha__ code where the variables are used.
Move the comment before the function and the begin of the function to
the #ifndef __alpha_ block, then you can use __unused__ for non-aplha
only.
> hwclock: remove goto statement
OK
> hwclock: add variable initialization
Good catch.
> hwclock: move long options away from global scope
But the enum {} does not have to be in the main().
> hwclock: validate numeric option arguments
OK
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: hwclock's ADJPATH
From: Karel Zak @ 2011-07-26 10:46 UTC (permalink / raw)
To: Tom Gundersen; +Cc: util-linux
In-Reply-To: <CAG-2HqUu6BduqDkja7-T67CJNYRKZWBbOQA29O3HaR=092bKaA@mail.gmail.com>
On Tue, Jul 26, 2011 at 02:06:20AM +0200, Tom Gundersen wrote:
> These are the constraints we have:
>
> /etc could possibly be mounted read-only.
> /var might not be mounted at early boot.
>
> This is the usage we have (in the cases where a machine does not use ntp):
>
> 1) At early boot we call "hwclock --systz", which require us to read
> ADJPATH to determine if RTC is in UTC/LOCAL (so ADJTIME can not be in
> /var).
>
> 2) From time to time (typically at shutdown), we call "hwclock
> --adjust", which require us to write to ADJPATH (so ADJPATH can not be
> in /etc).
> 3) The administrator should manually call "hwclock --set" and make
> sure ADJPATH is writeable when this is done (for this, ADJPATH could
> be either in /etc or /var).
>
>
>
> Are these reasonable constraints and a reasonable usecase? If so, it
> seems to me that the only way to make this work is to split ADJPATH
> into two files, /etc/adjtime containing UTC/LOCAL and
> /var/lib/hwclock/adjtime containing everything else. Or am I missing
> something?
You're probably right. Note that you can use:
hwclock --systz $(CLOCK_ZONE_OPTION)
where the CLOCK_ZONE_OPTION will be --utc or --local from some extra
file (e.g. /etc/sysconfig/hwclock), then /etc/adjtime will be
unnecessary for --systz.
And for hwclock --set or --adjust you can use
--adjfile=/var/lib/hwclock/adjtime or so.
Note that systemd will probably not call hwclock at all, it will read
only /etc/adjtime to get UTC/LOCAL setting and call settimeofday().
The --adjust is somehow unexpected on systems with systemd.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] whereis: update coding style
From: Karel Zak @ 2011-07-26 10:17 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311548793.3367.15.camel@offbook>
On Sun, Jul 24, 2011 at 07:06:33PM -0400, Davidlohr Bueso wrote:
> misc-utils/whereis.c | 360 ++++++++++++++++++++++++--------------------------
> 1 files changed, 170 insertions(+), 190 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] whereis: remove find()
From: Karel Zak @ 2011-07-26 10:16 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311548748.3367.14.camel@offbook>
On Sun, Jul 24, 2011 at 07:05:48PM -0400, Davidlohr Bueso wrote:
> misc-utils/whereis.c | 14 +++-----------
> 1 files changed, 3 insertions(+), 11 deletions(-)
Applied, thanks.
> + findv(srcdirs, ARRAY_SIZE(srcdirs)-1, cp);
Please, use space around operators
findv(srcdirs, ARRAY_SIZE(srcdirs) - 1, cp);
:-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] lscpu: use xalloc
From: Karel Zak @ 2011-07-26 10:15 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311547951.3367.5.camel@offbook>
On Sun, Jul 24, 2011 at 06:52:31PM -0400, Davidlohr Bueso wrote:
> sys-utils/lscpu.c | 34 ++++++++++------------------------
> 1 files changed, 10 insertions(+), 24 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] partx: use sysfs_deinit
From: Karel Zak @ 2011-07-26 10:14 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311547876.3367.3.camel@offbook>
On Sun, Jul 24, 2011 at 06:51:16PM -0400, Davidlohr Bueso wrote:
> partx/partx.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] [LIB] sysfs: free used resources
From: Karel Zak @ 2011-07-26 10:13 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: util-linux
In-Reply-To: <1311547838.3367.2.camel@offbook>
On Sun, Jul 24, 2011 at 06:50:38PM -0400, Davidlohr Bueso wrote:
> lib/sysfs.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] scriptreplay: fscanf portability fix
From: Karel Zak @ 2011-07-26 9:58 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
In-Reply-To: <1311365740-6251-1-git-send-email-kerolasa@iki.fi>
On Fri, Jul 22, 2011 at 10:15:40PM +0200, Sami Kerola wrote:
> This is a fix to an issue with llvm clang which I reported
> earlier.
>
> http://www.spinics.net/lists/util-linux-ng/msg04331.html
>
> When compiling with clang fscanf format string %[\n] will not
> work.
Sure, read scanf man page. The %[] format expects string +
null byte. The bug is in the scriptreplay.c code where
we don't have room for the null byte :-(
I really don't think that this a llvm bug.
> --- a/term-utils/scriptreplay.c
> +++ b/term-utils/scriptreplay.c
> @@ -203,7 +203,7 @@ main(int argc, char *argv[])
> size_t blk;
> char nl;
^^^^^^^^
>
> - if ((fscanf(tfile, "%lf %zd%[\n]\n", &delay, &blk, &nl) != 3) ||
> + if ((fscanf(tfile, "%lf %zd%c\n", &delay, &blk, &nl) != 3) ||
> (nl != '\n')) {
Yep, it seems usable.
Anyway, it's usually better to use fgets() + sscanf() to read and
parse lines from files. The fscanf() could be tricky if your format
depends on whitespaces.
Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* hwclock's ADJPATH
From: Tom Gundersen @ 2011-07-26 0:06 UTC (permalink / raw)
To: util-linux
Hi guys,
Sami's latest hwclock patches reminded me of something I have long
been meaning to bring up:
I have been unable to figure out how to use hwclock in such a way that
we (Arch Linux) can set a reasonable ADJPATH.
These are the constraints we have:
/etc could possibly be mounted read-only.
/var might not be mounted at early boot.
This is the usage we have (in the cases where a machine does not use ntp):
1) At early boot we call "hwclock --systz", which require us to read
ADJPATH to determine if RTC is in UTC/LOCAL (so ADJTIME can not be in
/var).
2) From time to time (typically at shutdown), we call "hwclock
--adjust", which require us to write to ADJPATH (so ADJPATH can not be
in /etc).
3) The administrator should manually call "hwclock --set" and make
sure ADJPATH is writeable when this is done (for this, ADJPATH could
be either in /etc or /var).
Are these reasonable constraints and a reasonable usecase? If so, it
seems to me that the only way to make this work is to split ADJPATH
into two files, /etc/adjtime containing UTC/LOCAL and
/var/lib/hwclock/adjtime containing everything else. Or am I missing
something?
Cheers,
Tom
^ permalink raw reply
* [git pull] hwclock fixes
From: Sami Kerola @ 2011-07-25 22:42 UTC (permalink / raw)
To: util-linux
The following changes since commit 63de90d44f4f05a1f48942148edcf1740ba4a623:
libmount: cleanup docs (2011-07-23 01:27:39 +0200)
are available in the git repository at:
https://github.com/kerolasa/lelux-utiliteetit hwclock
Sami Kerola (11):
hwclock: remove clock-ppc.c
hwclock: remove misleading information
hwclock: coding style clean up
hwclock: include-what-you-use header check
hwclock: move path definitions to pathnames.h
hwclock: remove inb & outb functions
hwclock: fix compiler warnings
hwclock: remove goto statement
hwclock: add variable initialization
hwclock: move long options away from global scope
hwclock: validate numeric option arguments
configure.ac | 2 -
hwclock/Makefile.am | 4 +-
hwclock/README.hwclock | 10 -
hwclock/clock-ppc.c | 459 ---------
hwclock/clock.h | 20 +-
hwclock/cmos.c | 936 +++++++++---------
hwclock/hwclock.c | 2654 ++++++++++++++++++++++++------------------------
hwclock/kd.c | 239 +++---
hwclock/rtc.c | 565 ++++++-----
include/pathnames.h | 9 +
10 files changed, 2223 insertions(+), 2675 deletions(-)
delete mode 100644 hwclock/clock-ppc.c
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply
* Re: Can't remount loopback ext4 without /etc/mtab
From: Karel Zak @ 2011-07-25 9:46 UTC (permalink / raw)
To: Daniel Drake; +Cc: Ted Ts'o, util-linux
In-Reply-To: <CAGq3pz4PH-MK5+AgBTnq03atWUxMEdVreUtoVeqrkOkcc+8DZQ@mail.gmail.com>
On Mon, Jul 25, 2011 at 10:20:55AM +0100, Daniel Drake wrote:
> On 25 July 2011 10:06, Karel Zak <kzak@redhat.com> wrote:
> > mount(8) "bug"
> >
> > The kernel does not accept any SELinux specific mount options for
> > MS_REMOUNT. We already have exception for this in mount(8) ... and I
> > hate it, but our SELunux kernel guys are happy with this strange
> > behavior:
> >
> > https://bugzilla.redhat.com/show_bug.cgi?id=563267#c9
>
> That view might have changed, I found these commits:
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=ff36fe2c845cab2102e4826c1ffa0a6ebf487c65
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=026eb167ae77244458fa4b4b9fc171209c079ba7
> (from https://bugzilla.redhat.com/show_bug.cgi?id=676630 )
WOW...
> I'm going to test them against F15 kernel later today.
F-15 uses 2.6.38, the patches are in kernel >= v2.6.39-rc7
(according to git describe --contains).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: Can't remount loopback ext4 without /etc/mtab
From: Daniel Drake @ 2011-07-25 9:20 UTC (permalink / raw)
To: Karel Zak; +Cc: Ted Ts'o, util-linux
In-Reply-To: <20110725090624.GU22568@nb.net.home>
On 25 July 2011 10:06, Karel Zak <kzak@redhat.com> wrote:
> =A0mount(8) "bug"
>
> =A0The kernel does not accept any SELinux specific mount options for
> =A0MS_REMOUNT. We already have exception for this in mount(8) ... and I
> =A0hate it, but our SELunux kernel guys are happy with this strange
> =A0behavior:
>
> =A0https://bugzilla.redhat.com/show_bug.cgi?id=3D563267#c9
That view might have changed, I found these commits:
http://git.kernel.org/?p=3Dlinux/kernel/git/torvalds/linux-2.6.git;a=3Dcomm=
itdiff;h=3Dff36fe2c845cab2102e4826c1ffa0a6ebf487c65
http://git.kernel.org/?p=3Dlinux/kernel/git/torvalds/linux-2.6.git;a=3Dcomm=
itdiff;h=3D026eb167ae77244458fa4b4b9fc171209c079ba7
(from https://bugzilla.redhat.com/show_bug.cgi?id=3D676630 )
I'm going to test them against F15 kernel later today.
Thanks,
Daniel
^ permalink raw reply
* Re: Can't remount loopback ext4 without /etc/mtab
From: Karel Zak @ 2011-07-25 9:06 UTC (permalink / raw)
To: Ted Ts'o; +Cc: Daniel Drake, util-linux
In-Reply-To: <20110724195713.GH3469@thunk.org>
On Sun, Jul 24, 2011 at 03:57:13PM -0400, Ted Ts'o wrote:
> On Sun, Jul 24, 2011 at 07:09:47PM +0100, Daniel Drake wrote:
> >
> > When the error occurs, dmesg says:
> > [ 5495.860391] EXT4-fs (loop0): Unrecognized mount option "seclabel"
> > or missing value
> >
> > Here is the corresponding entry from /proc/mounts:
> > /dev/loop0 /home/dsd/tmpdisk/mountpt ext4
> > rw,seclabel,relatime,barrier=1,data=ordered 0 0
> >
> > Is this a util-linux bug? Or an ext4 issue?
mount(8) "bug"
The kernel does not accept any SELinux specific mount options for
MS_REMOUNT. We already have exception for this in mount(8) ... and I
hate it, but our SELunux kernel guys are happy with this strange
behavior:
https://bugzilla.redhat.com/show_bug.cgi?id=563267#c9
> Personally, I find my life has been much happier since I gave up on
> SELinux as being too complicated to be secure.
+1
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* [PATCH] whereis: update coding style
From: Davidlohr Bueso @ 2011-07-24 23:06 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 24 Jul 2011 11:11:19 -0400
Like most 20th century Berkeley code, it's horrible:
- declare global variables in only one place
- add static attribute where it belongs
- move funcion declarations so that it doesn't require defining them
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
misc-utils/whereis.c | 360 ++++++++++++++++++++++++--------------------------
1 files changed, 170 insertions(+), 190 deletions(-)
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index a331f45..08b62e6 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -48,16 +48,6 @@
#include "nls.h"
#include "c.h"
-void zerof(void);
-void getlist(int *, char ***, char ***, int *);
-void lookup(char *);
-void looksrc(char *);
-void lookbin(char *);
-void lookman(char *);
-void findv(char **, int, char *);
-void findin(char *, char *);
-int itsit(char *, char *);
-
static char *bindirs[] = {
"/bin",
"/usr/bin",
@@ -133,16 +123,9 @@ static char *srcdirs[] = {
0
};
-char sflag = 1;
-char bflag = 1;
-char mflag = 1;
-char **Sflag;
-int Scnt;
-char **Bflag;
-int Bcnt;
-char **Mflag;
-int Mcnt;
-char uflag;
+static char sflag = 1, bflag = 1, mflag = 1, uflag;
+static char **Sflag, **Bflag, **Mflag;
+static int Scnt, Bcnt, Mcnt, count, print;
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -164,77 +147,125 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-/*
- * whereis name
- * look for source, documentation and binaries
- */
-int
-main(int argc, char **argv)
+static int
+itsit(char *cp, char *dp)
{
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- argc--, argv++;
- if (argc == 0)
- usage(stderr);
+ int i = strlen(dp);
- do
- if (argv[0][0] == '-') {
- register char *cp = argv[0] + 1;
- while (*cp) switch (*cp++) {
+ if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp + 2))
+ return 1;
+ if (!strcmp(dp + i - 2, ".Z"))
+ i -= 2;
+ else if (!strcmp(dp + i - 3, ".gz"))
+ i -= 3;
+ else if (!strcmp(dp + i - 4, ".bz2"))
+ i -= 4;
+ while (*cp && *dp && *cp == *dp)
+ cp++, dp++, i--;
+ if (*cp == 0 && *dp == 0)
+ return 1;
+ while (isdigit(*dp))
+ dp++;
+ if (*cp == 0 && *dp++ == '.') {
+ --i;
+ while (i > 0 && *dp)
+ if (--i, *dp++ == '.')
+ return (*dp++ == 'C' && *dp++ == 0);
+ return 1;
+ }
+ return 0;
+}
- case 'f':
- break;
+static void
+findin(char *dir, char *cp)
+{
+ DIR *dirp;
+ struct dirent *dp;
+ char *d, *dd;
+ size_t l;
+ char dirbuf[1024];
+ struct stat statbuf;
- case 'S':
- getlist(&argc, &argv, &Sflag, &Scnt);
- break;
+ dd = strchr(dir, '*');
+ if (!dd) {
+ dirp = opendir(dir);
+ if (dirp == NULL)
+ return;
+ while ((dp = readdir(dirp)) != NULL) {
+ if (itsit(cp, dp->d_name)) {
+ count++;
+ if (print)
+ printf(" %s/%s", dir, dp->d_name);
+ }
+ }
+ closedir(dirp);
+ return;
+ }
- case 'B':
- getlist(&argc, &argv, &Bflag, &Bcnt);
- break;
+ l = strlen(dir);
+ if (l < sizeof(dirbuf)) {
+ /* refuse excessively long names */
+ strcpy(dirbuf, dir);
+ d = strchr(dirbuf, '*');
+ *d = 0;
+ dirp = opendir(dirbuf);
+ if (dirp == NULL)
+ return;
+ while ((dp = readdir(dirp)) != NULL) {
+ if (!strcmp(dp->d_name, ".") ||
+ !strcmp(dp->d_name, ".."))
+ continue;
+ if (strlen(dp->d_name) + l > sizeof(dirbuf))
+ continue;
+ sprintf(d, "%s", dp->d_name);
+ if (stat(dirbuf, &statbuf))
+ continue;
+ if (!S_ISDIR(statbuf.st_mode))
+ continue;
+ strcat(d, dd + 1);
+ findin(dirbuf, cp);
+ }
+ closedir(dirp);
+ }
+ return;
- case 'M':
- getlist(&argc, &argv, &Mflag, &Mcnt);
- break;
+}
- case 's':
- zerof();
- sflag++;
- continue;
+static void
+findv(char **dirv, int dirc, char *cp)
+{
+ while (dirc > 0)
+ findin(*dirv++, cp), dirc--;
+}
- case 'u':
- uflag++;
- continue;
+static void
+looksrc(char *cp)
+{
+ if (Sflag == 0)
+ findv(srcdirs, ARRAY_SIZE(srcdirs)-1, cp);
+ else
+ findv(Sflag, Scnt, cp);
+}
- case 'b':
- zerof();
- bflag++;
- continue;
+static void
+lookbin(char *cp)
+{
+ if (Bflag == 0)
+ findv(bindirs, ARRAY_SIZE(bindirs)-1, cp);
+ else
+ findv(Bflag, Bcnt, cp);
+}
- case 'm':
- zerof();
- mflag++;
- continue;
- case 'V':
- printf(_("%s from %s\n"),
- program_invocation_short_name,
- PACKAGE_STRING);
- return EXIT_SUCCESS;
- case 'h':
- usage(stdout);
- default:
- usage(stderr);
- }
- argv++;
- } else
- lookup(*argv++);
- while (--argc > 0);
- return EXIT_SUCCESS;
+static void
+lookman(char *cp)
+{
+ if (Mflag == 0)
+ findv(mandirs, ARRAY_SIZE(mandirs)-1, cp);
+ else
+ findv(Mflag, Mcnt, cp);
}
-void
+static void
getlist(int *argcp, char ***argvp, char ***flagp, int *cntp)
{
(*argvp)++;
@@ -246,17 +277,14 @@ getlist(int *argcp, char ***argvp, char ***flagp, int *cntp)
(*argvp)--;
}
-void
+static void
zerof()
{
if (sflag && bflag && mflag)
sflag = bflag = mflag = 0;
}
-int count;
-int print;
-
-int
+static int
print_again(char *cp)
{
if (print)
@@ -287,7 +315,7 @@ print_again(char *cp)
return 0;
}
-void
+static void
lookup(char *cp)
{
register char *dp;
@@ -316,120 +344,72 @@ lookup(char *cp)
printf("\n");
}
-void
-looksrc(char *cp)
+/*
+ * whereis name
+ * look for source, documentation and binaries
+ */
+int
+main(int argc, char **argv)
{
- if (Sflag == 0)
- findv(srcdirs, ARRAY_SIZE(srcdirs)-1, cp);
- else
- findv(Sflag, Scnt, cp);
-}
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
-void
-lookbin(char *cp)
-{
- if (Bflag == 0)
- findv(bindirs, ARRAY_SIZE(bindirs)-1, cp);
- else
- findv(Bflag, Bcnt, cp);
-}
+ argc--, argv++;
+ if (argc == 0)
+ usage(stderr);
-void
-lookman(char *cp)
-{
- if (Mflag == 0)
- findv(mandirs, ARRAY_SIZE(mandirs)-1, cp);
- else
- findv(Mflag, Mcnt, cp);
-}
+ do
+ if (argv[0][0] == '-') {
+ register char *cp = argv[0] + 1;
+ while (*cp) switch (*cp++) {
-void
-findv(char **dirv, int dirc, char *cp)
-{
- while (dirc > 0)
- findin(*dirv++, cp), dirc--;
-}
+ case 'f':
+ break;
-void
-findin(char *dir, char *cp)
-{
- DIR *dirp;
- struct dirent *dp;
- char *d, *dd;
- size_t l;
- char dirbuf[1024];
- struct stat statbuf;
+ case 'S':
+ getlist(&argc, &argv, &Sflag, &Scnt);
+ break;
- dd = strchr(dir, '*');
- if (!dd) {
- dirp = opendir(dir);
- if (dirp == NULL)
- return;
- while ((dp = readdir(dirp)) != NULL) {
- if (itsit(cp, dp->d_name)) {
- count++;
- if (print)
- printf(" %s/%s", dir, dp->d_name);
- }
- }
- closedir(dirp);
- return;
- }
+ case 'B':
+ getlist(&argc, &argv, &Bflag, &Bcnt);
+ break;
- l = strlen(dir);
- if (l < sizeof(dirbuf)) {
- /* refuse excessively long names */
- strcpy(dirbuf, dir);
- d = strchr(dirbuf, '*');
- *d = 0;
- dirp = opendir(dirbuf);
- if (dirp == NULL)
- return;
- while ((dp = readdir(dirp)) != NULL) {
- if (!strcmp(dp->d_name, ".") ||
- !strcmp(dp->d_name, ".."))
- continue;
- if (strlen(dp->d_name) + l > sizeof(dirbuf))
- continue;
- sprintf(d, "%s", dp->d_name);
- if (stat(dirbuf, &statbuf))
- continue;
- if (!S_ISDIR(statbuf.st_mode))
+ case 'M':
+ getlist(&argc, &argv, &Mflag, &Mcnt);
+ break;
+
+ case 's':
+ zerof();
+ sflag++;
continue;
- strcat(d, dd + 1);
- findin(dirbuf, cp);
- }
- closedir(dirp);
- }
- return;
-}
+ case 'u':
+ uflag++;
+ continue;
-int
-itsit(char *cp, char *dp)
-{
- int i = strlen(dp);
+ case 'b':
+ zerof();
+ bflag++;
+ continue;
- if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp + 2))
- return 1;
- if (!strcmp(dp + i - 2, ".Z"))
- i -= 2;
- else if (!strcmp(dp + i - 3, ".gz"))
- i -= 3;
- else if (!strcmp(dp + i - 4, ".bz2"))
- i -= 4;
- while (*cp && *dp && *cp == *dp)
- cp++, dp++, i--;
- if (*cp == 0 && *dp == 0)
- return 1;
- while (isdigit(*dp))
- dp++;
- if (*cp == 0 && *dp++ == '.') {
- --i;
- while (i > 0 && *dp)
- if (--i, *dp++ == '.')
- return (*dp++ == 'C' && *dp++ == 0);
- return 1;
- }
- return 0;
+ case 'm':
+ zerof();
+ mflag++;
+ continue;
+ case 'V':
+ printf(_("%s from %s\n"),
+ program_invocation_short_name,
+ PACKAGE_STRING);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
+ default:
+ usage(stderr);
+ }
+ argv++;
+ } else
+ lookup(*argv++);
+ while (--argc > 0);
+ return EXIT_SUCCESS;
}
--
1.7.4.1
^ permalink raw reply related
* [PATCH] whereis: remove find()
From: Davidlohr Bueso @ 2011-07-24 23:05 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 24 Jul 2011 10:59:25 -0400
Because findv() can do the same job find() does, we can simply remove it and call findv() with the size of each array.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
misc-utils/whereis.c | 14 +++-----------
1 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 4f841f9..a331f45 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -55,7 +55,6 @@ void looksrc(char *);
void lookbin(char *);
void lookman(char *);
void findv(char **, int, char *);
-void find(char **, char *);
void findin(char *, char *);
int itsit(char *, char *);
@@ -321,7 +320,7 @@ void
looksrc(char *cp)
{
if (Sflag == 0)
- find(srcdirs, cp);
+ findv(srcdirs, ARRAY_SIZE(srcdirs)-1, cp);
else
findv(Sflag, Scnt, cp);
}
@@ -330,7 +329,7 @@ void
lookbin(char *cp)
{
if (Bflag == 0)
- find(bindirs, cp);
+ findv(bindirs, ARRAY_SIZE(bindirs)-1, cp);
else
findv(Bflag, Bcnt, cp);
}
@@ -339,7 +338,7 @@ void
lookman(char *cp)
{
if (Mflag == 0)
- find(mandirs, cp);
+ findv(mandirs, ARRAY_SIZE(mandirs)-1, cp);
else
findv(Mflag, Mcnt, cp);
}
@@ -352,13 +351,6 @@ findv(char **dirv, int dirc, char *cp)
}
void
-find(char **dirs, char *cp)
-{
- while (*dirs)
- findin(*dirs++, cp);
-}
-
-void
findin(char *dir, char *cp)
{
DIR *dirp;
--
1.7.4.1
^ permalink raw reply related
* Re: [PATCH] whereis: search in path variable
From: Davidlohr Bueso @ 2011-07-24 23:01 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
In-Reply-To: <20110721165141.GG22568@nb.net.home>
On Thu, 2011-07-21 at 18:51 +0200, Karel Zak wrote:
> On Wed, Jul 20, 2011 at 12:46:25AM -0400, Davidlohr Bueso wrote:
> > 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.
>
> Finally someone who is not lazy to implement it correctly :-)
...
> man getenv, you should not modify the result from getenv().
ouch, sorry!
>
> > + 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;
> > + }
>
> here is bug, see below to gdb backtrace...
>
> > +
> > 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);
>
> ... this code expects that the array is terminated by zero.
>
> Note that find() is called always for all dir lists.
>
> Maybe it would be better to add lookpathenv() and call it from
> print_again(). You can also add -p options to control this behavior.
> See how {s,b,m}flags work.
That was my initial design, however since src, bin and man are _types_
of files, it seems that adding a similar behavior for search _paths_ is
like mixing apples and pears.
Something I am thinking of, but won't do it quite yet, is to simply
rewrite whereis and, instead of hardcoding paths, recursively search
from / and use stat + heuristics to differentiate the different files.
>
> BTW, the whole whereis code is horrible,
Like most BSD '80s code is. I was hoping you weren't going to ask for
cleanups :)
> for example find() is completely
> unnecessary if there is also findv() and all lists of the directories are
> static. It should be possible to use
>
> findv(ary, ARRAY_SIZE(ary), str);
>
> everywhere instead of find(ary, str);
>
> Karel
>
> Starting program: /home/projects/util-linux/util-linux/misc-utils/whereis lsblk
>
> Program received signal SIGSEGV, Segmentation fault.
That'll teach me not to code half asleep. I'm sending you some cleanup
patches and then I'll add these fixes to the program.
> 0x0000003cbae7edfa in __strchr_sse2 () from /lib64/libc.so.6
> Missing separate debuginfos, use: debuginfo-install glibc-2.14-4.x86_64
> (gdb) bt
> #0 0x0000003cbae7edfa in __strchr_sse2 () from /lib64/libc.so.6
> #1 0x00000000004013c8 in findin (dir=0x1ff41 <Address 0x1ff41 out of bounds>,
> cp=0x7fffffffe477 "lsblk") at whereis.c:434
> #2 0x0000000000401623 in find (dirs=<optimized out>,
> cp=0x7fffffffe477 "lsblk") at whereis.c:421
> #3 0x00000000004017a8 in print_again (cp=0x7fffffffe477 "lsblk")
> at whereis.c:327
> #4 0x0000000000401870 in lookup (cp=0x7fffffffe477 "lsblk") at whereis.c:374
> #5 0x0000000000400c9b in main (argc=1, argv=0x7fffffffe148) at whereis.c:242
- Davidlohr
^ permalink raw reply
* [PATCH] lscpu: use xalloc
From: Davidlohr Bueso @ 2011-07-24 22:52 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 24 Jul 2011 14:39:15 -0400
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
sys-utils/lscpu.c | 34 ++++++++++------------------------
1 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 6fa7daf..9d3d3cb 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -622,17 +622,11 @@ read_topology(struct lscpu_desc *desc, int num)
*/
if (!desc->nthreads)
desc->nthreads = nsockets * ncores * nthreads;
- if (book_siblings) {
- desc->bookmaps = calloc(nbooks, sizeof(cpu_set_t *));
- if (!desc->bookmaps)
- err(EXIT_FAILURE, _("error: calloc failed"));
- }
- desc->socketmaps = calloc(nsockets, sizeof(cpu_set_t *));
- if (!desc->socketmaps)
- err(EXIT_FAILURE, _("error: calloc failed"));
- desc->coremaps = calloc(ncores * nsockets, sizeof(cpu_set_t *));
- if (!desc->coremaps)
- err(EXIT_FAILURE, _("error: calloc failed"));
+ if (book_siblings)
+ desc->bookmaps = xcalloc(nbooks, sizeof(cpu_set_t *));
+
+ desc->socketmaps = xcalloc(nsockets, sizeof(cpu_set_t *));
+ desc->coremaps = xcalloc(ncores * nsockets, sizeof(cpu_set_t *));
}
add_cpuset_to_array(desc->socketmaps, &desc->nsockets, core_siblings);
@@ -664,9 +658,7 @@ read_cache(struct lscpu_desc *desc, int num)
if (!desc->ncaches)
return;
- desc->caches = calloc(desc->ncaches, sizeof(*desc->caches));
- if (!desc->caches)
- err(EXIT_FAILURE, _("calloc failed"));
+ desc->caches = xcalloc(desc->ncaches, sizeof(*desc->caches));
}
for (i = 0; i < desc->ncaches; i++) {
struct cpu_cache *ca = &desc->caches[i];
@@ -707,12 +699,8 @@ read_cache(struct lscpu_desc *desc, int num)
map = path_cpuset(_PATH_SYS_CPU "/cpu%d/cache/index%d/shared_cpu_map",
num, i);
- if (!ca->sharedmaps) {
- ca->sharedmaps = calloc(desc->ncpus, sizeof(cpu_set_t *));
- if (!ca->sharedmaps)
- err(EXIT_FAILURE, _("error: calloc failed"));
- }
-
+ if (!ca->sharedmaps)
+ ca->sharedmaps = xcalloc(desc->ncpus, sizeof(cpu_set_t *));
add_cpuset_to_array(ca->sharedmaps, &ca->nsharedmaps, map);
}
}
@@ -729,10 +717,8 @@ read_nodes(struct lscpu_desc *desc)
if (!desc->nnodes)
return;
- desc->nodemaps = calloc(desc->nnodes, sizeof(cpu_set_t *));
- if (!desc->nodemaps)
- err(EXIT_FAILURE, _("error: calloc failed"));
-
+ desc->nodemaps = xcalloc(desc->nnodes, sizeof(cpu_set_t *));
+
/* information about how nodes share different CPUs */
for (i = 0; i < desc->nnodes; i++)
desc->nodemaps[i] = path_cpuset(
--
1.7.4.1
^ permalink raw reply related
* [PATCH] partx: use sysfs_deinit
From: Davidlohr Bueso @ 2011-07-24 22:51 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 24 Jul 2011 11:29:23 -0400
Commit a88268b8cc124b6f721ba17ab01a3f6d5800c749 (get partition number with sysfs lib) recently added the sysfs library to partx without freeing resources once finished.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
partx/partx.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/partx/partx.c b/partx/partx.c
index e29e50d..4f827a8 100644
--- a/partx/partx.c
+++ b/partx/partx.c
@@ -137,8 +137,10 @@ static int get_partno_from_device(char *partition, dev_t devno)
struct sysfs_cxt cxt;
sysfs_init(&cxt, devno, NULL);
- if (sysfs_read_int(&cxt, "partition", &partno) >= 0)
+ if (sysfs_read_int(&cxt, "partition", &partno) >= 0) {
+ sysfs_deinit(&cxt);
return partno;
+ }
}
sz = strlen(partition);
--
1.7.4.1
^ permalink raw reply related
* [PATCH] [LIB] sysfs: free used resources
From: Davidlohr Bueso @ 2011-07-24 22:50 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Date: Sun, 24 Jul 2011 11:22:52 -0400
In the sysfs lib example, we should be using sysfs_deinit() to free used resources and for correct usage.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
lib/sysfs.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/sysfs.c b/lib/sysfs.c
index b9ddc67..7bcdaba 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -488,6 +488,7 @@ int main(int argc, char *argv[])
printf("DEVNAME: %s\n", sysfs_get_devname(&cxt, path, sizeof(path)));
+ sysfs_deinit(&cxt);
return EXIT_SUCCESS;
}
#endif
--
1.7.4.1
^ permalink raw reply related
* Re: Can't remount loopback ext4 without /etc/mtab
From: Davidlohr Bueso @ 2011-07-24 22:46 UTC (permalink / raw)
To: Ted Ts'o; +Cc: Daniel Drake, util-linux
In-Reply-To: <20110724195713.GH3469@thunk.org>
On Sun, 2011-07-24 at 15:57 -0400, Ted Ts'o wrote:
> On Sun, Jul 24, 2011 at 07:09:47PM +0100, Daniel Drake wrote:
> >
> > When the error occurs, dmesg says:
> > [ 5495.860391] EXT4-fs (loop0): Unrecognized mount option "seclabel"
> > or missing value
> >
> > Here is the corresponding entry from /proc/mounts:
> > /dev/loop0 /home/dsd/tmpdisk/mountpt ext4
> > rw,seclabel,relatime,barrier=1,data=ordered 0 0
> >
> > Is this a util-linux bug? Or an ext4 issue?
>
> Or a selinux thing; "seclabel" seems to be SELinux's fault:
>
It would seem so, I can't reproduce this issue on a "normal", non
SELinux box.
> % git grep LABELSUPP_STR
> security/selinux/hooks.c: {Opt_labelsupport, LABELSUPP_STR},
> security/selinux/hooks.c: seq_puts(m, LABELSUPP_STR);
> security/selinux/hooks.c: match_prefix(LABELSUPP_STR, sizeof(LABEL
> security/selinux/include/security.h:#define LABELSUPP_STR "seclabel"
>
> Personally, I find my life has been much happier since I gave up on
> SELinux as being too complicated to be secure.
+1!!
- Davidlohr
^ permalink raw reply
* Re: Can't remount loopback ext4 without /etc/mtab
From: Ted Ts'o @ 2011-07-24 19:57 UTC (permalink / raw)
To: Daniel Drake; +Cc: util-linux
In-Reply-To: <CAGq3pz7FctJcUsO-1FmFmV=EW0N=n_ZYBCHGcyXQMr1CJ24zRA@mail.gmail.com>
On Sun, Jul 24, 2011 at 07:09:47PM +0100, Daniel Drake wrote:
>
> When the error occurs, dmesg says:
> [ 5495.860391] EXT4-fs (loop0): Unrecognized mount option "seclabel"
> or missing value
>
> Here is the corresponding entry from /proc/mounts:
> /dev/loop0 /home/dsd/tmpdisk/mountpt ext4
> rw,seclabel,relatime,barrier=1,data=ordered 0 0
>
> Is this a util-linux bug? Or an ext4 issue?
Or a selinux thing; "seclabel" seems to be SELinux's fault:
% git grep LABELSUPP_STR
security/selinux/hooks.c: {Opt_labelsupport, LABELSUPP_STR},
security/selinux/hooks.c: seq_puts(m, LABELSUPP_STR);
security/selinux/hooks.c: match_prefix(LABELSUPP_STR, sizeof(LABEL
security/selinux/include/security.h:#define LABELSUPP_STR "seclabel"
Personally, I find my life has been much happier since I gave up on
SELinux as being too complicated to be secure.
- Ted
^ 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