Commit Graph

381 Commits

Author SHA1 Message Date
Karel Zak 68f7b572ba lib/color: add colorscheme parser 2014-02-10 14:50:12 +01:00
Karel Zak 663bf04061 losetup: wait for udev
On system with /dev/lop-control the udevd creates /dev/loopN nodes.
It seems better to wait a moment after unsuccessful open(/dev/loopN)
and try it to open again.

The problem is pretty visible on systems where udevd also modifies
permission for loopN devices, then open() fails with EACCES when
losetup executed by non-root user (but user who is in "disk" group).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1045432
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:58:40 +01:00
Karel Zak a5bd793996 include/c.h: prefer nanosleep() over usleep()
Let's use nanosleep() although if usleep() exists. The nanosleep
function does no interact with signals and other timers.

The patch introduces xusleep() as replacement to libc (or our fallback)
usleep(). Yes, we don't want to use struct timespec + nanosleep()
everywhere in code as nano-time resolution is useless for us.

The patch also enlarges delays in some busy wait loops. It seems
enough to try read/write 4x per second.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:04:14 +01:00
Lubomir Rintel 4da21e374e unshare: Add possibility to add mapping into root user in user namespace
This makes it very convenient to use make use of privileged actions
on CONFIG_USER_NS enabled kernels, without having to manually tinker
with uid_map and gid_map to obtain required credentials (as those
given upon unshare() vanish with call to execve() and lot of userspace
checks for euid==0 anyway).

Usage example:

$ unshare --uts
unshare: unshare failed: Operation not permitted

$ unshare --user --uts
[nfsnobody@odvarok ~]$ hostname swag
hostname: you must be root to change the host name

$ unshare -r --uts
[root@odvarok util-linux]# hostname swag
[root@odvarok util-linux]#

[kzak@redhat.com: - move code to map_id()
                  - use all-io.h
                  - add paths to pathnames.h]

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-07 11:04:42 +01:00
Karel Zak dd3bc51a53 lib/path: add path_strdup()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-06 16:48:13 +01:00
Sami Kerola d8a9b90756 docs: update links to http://git.kernel.org/ web repository views
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-11-12 11:47:57 +01:00
Ondrej Oprala 675de3f5c1 strutils: add skip_space() function
[kzak@redhat.com: - add also skip_blank(),
                  - remove duplicate implementation from libmount]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-08 14:14:34 +01:00
Michael Forney 00c505d9cf include: Add missing includes
sys/types.h: For u_char typedef
sys/params.h: For MAXNAMLEN
sys/ttydefaults.h: For various tty definitions (also add configure check)

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-04 11:51:21 +02:00
Karel Zak 88407b9321 nologin: add new command
Currently it's maintained as distro specific (or people use impolite
/bin/false way).

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-30 13:36:26 +02:00
Karel Zak e93d5475fe build-sys: fix include Makemodule.am
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-26 10:41:18 +02:00
Karel Zak 80a1712f54 fdisk: add -L to colorize output
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:09 +02:00
Karel Zak 0dd3dfb8e3 fdisk: (bsd) write/read PT code cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:06 +02:00
Karel Zak cc3d127e4c libblkid: move bsd definitions to pt-bsd.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:04 +02:00
Karel Zak 5099226711 libfdisk: move mbr code to the library
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:04 +02:00
Karel Zak e8bf93ded2 fdisk: add mbr_get_partition()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:02 +02:00
Karel Zak b44244cb98 fdisk: use functions from pt-mbr.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:02 +02:00
Karel Zak 71ade4da58 libblkid: rename sys_type to sys_ind
This makes struct dos_partition more compatible with the current fdisk
code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:02 +02:00
Karel Zak b198111523 include/pt-mbr: add functio to store le
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:47:02 +02:00
Karel Zak f917738efa libblkid: move MBR definitions to include/pt-mbr.h 2013-09-16 16:47:02 +02:00
Karel Zak d4caf70067 fdisk: (sgi) fix checksum calculation
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:58 +02:00
Karel Zak 7e5f8f3824 libblkid: move MBR partition types to include/
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:58 +02:00
Karel Zak 9fc1f5d809 fdisk: (sgi) cleanup devparams flags
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:58 +02:00
Karel Zak 1a9889ad7f fdisk: (sgi) cleanu sgi_info stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:57 +02:00
Karel Zak 5105f75f67 fdisk: (sgi) remove magic strings
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:57 +02:00
Karel Zak a78651d778 fdisk: (sgi) share disk label definition with libblkid
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:57 +02:00
Karel Zak 1c314b3183 libblkid: move SGI disklabel definitions to include/
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:57 +02:00
Karel Zak f234cc3b51 lib/tt: add TT_FL_FREEDATA
... to call free() for line data.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:53 +02:00
Karel Zak b34f097e75 agetty: add \S to output /etc/os-release data
This patch allows to use a new \S or \S{VARNAME} sequence in the
/etc/issue file. The sequence prints data from /etc/os-release.  The
reason is to keep /etc/issue file distribution and release
independent.

The \S{ANSI_COLOR} is converted to the real terminal escape seq.

For example:

   \S
   Kernel \r on an \m (\l)

or more complex example:

   Welcome to \S{ANSI_COLOR}\S{NAME}0m \S{VERSION}
   Report bugs at \S{BUG_REPORT_URL}.

See http://www.freedesktop.org/software/systemd/man/os-release.html
fr more details about /etc/issue.

Based on patch from Bill Nottingham <notting@redhat.com>.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-12 12:44:09 +02:00
Karel Zak db2a3dda74 lib: add crc64()
Based on bcache code from Rolf Fokkens.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-11 16:40:06 +02:00
Karel Zak 60f25deae7 lib: rename time-util.c to timeutils.c, fix headers
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 13:11:02 +02:00
Karel Zak 646e159aa9 lib/strutils: optimalize {starts,ends}with()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 12:18:20 +02:00
Sami Kerola 199e939d88 lib/strutils: move *swith() functions to private library
Avoid code dublication in libmount and time-util.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: http://markmail.org/message/h7zexvqsieqngtmx
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 2659a49ef0 lib/time-util: copy time parsing functions from systemd
The functions are copied nearly as-is.  Coding style has been modified to
match with util-linux project, while the functionality remains untouched.

CC: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola ada6c48f06 include: carefulput: print determined char when unprintable char is found
This is done to allow reuse of the functin in last(1).

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:48 +02:00
Karel Zak 3cb2413b02 losetup: use loop-control to explicitly ask for device
Now we use LOOP_CTL_GET_FREE ioctl to ask for free device, for example

  losetup -f foo.img

Unfortunately, losetup(8) allows to ask for specified device

  losetup /dev/loop100 foo.img

and in this case we assume that the device already exists in the
system. This is incorrect, we should be able to use loop-control
LOOP_CTL_ADD ioctl to ask for the specified device.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-06 11:04:35 +02:00
Karel Zak c9678832b1 include/xalloc: add warn_unused_result to allocation functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-09 10:44:06 +02:00
Karel Zak b8b8e76806 agetty: don't remove ECHOCTL from c_lflag
It's really unexpected that arrows keys move cursor when agetty/login
asks for login name or password.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=969458
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-06-03 14:06:18 +02:00
Ondrej Oprala fb2627cec4 lscpu: detect more hypervisor vendors
[kzak@redhat.com: - cleanup coding style,
                  - use path_exist()]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-20 16:30:23 +02:00
Karel Zak 507341f832 lib/tty: don't hardcode terminal fd in get_terminal_name()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 15:40:57 +02:00
Karel Zak b7faf99128 lib/colors: add colormode_or_err()
... to make the code easy to use in utils.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-07 09:09:35 +02:00
Karel Zak a10c043493 lib/colors: add support for auto, always and never modes
... to implement --color[=<when>]

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-06 19:07:23 +02:00
Sami Kerola f416563b28 include: add close_fd() for noticing write errors before close()
Essentially this helper function is similar to close_stream(), but for
file descriptors.

When a file descriptors are close()'d status of write is often
overlooked.  The close_fd() will try to determine what happen to writes
with fsync() before closing the file descriptor.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:26:06 +02:00
Karel Zak 6d791b4cc0 include: fix SYS_{unshare,nsenter} usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-17 16:58:00 +02:00
Karel Zak 09daba4069 libblkid: arch independent minix detection
It seems that on-disk MINIX FS superblock is native-endian.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=833841
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-15 15:14:33 +02:00
Karel Zak 2b88d3d72b lib/xalloc: add xstrndup()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-10 17:16:01 +02:00
Jeff Mahoney 293714c0d1 loopdev: sync capacity after setting it
I recently tried to mount an hfsplus file system from an image file with
a partition table by using the loop offset and sizelimit options to specify
the location of the file system.

hfsplus stores some metadata at a set offset from the end of the partition,
so it's sensitive to the device size reported by the kernel.

It worked with this:

But failed with this:

/dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000

/proc/partitions shows the correct number of blocks to match the sizelimit.

But if I set a breakpoint in mount before the mount syscall, I could see:
102400000
102432768

The kernel loop driver will set the gendisk capacity of the device at
LOOP_SET_STATUS64 but won't sync it to the block device until one of two
conditions are met: All open file descriptors referring to the device are
closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl
is called to sync it. Since mount opens the device and passes it directly
to the mount syscall after LOOP_SET_STATUS64 without closing and reopening
it, the sizelimit argument is effectively ignroed. The capacity needs to
be synced immediately for it to work as expected.

This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since
the device isn't yet released to the user, so it's safe to sync the capacity
immediately.

[kzak@redhat.com: - port to the current git HEAD,
                  - use uint64_t]

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-09 14:32:50 +02:00
Karel Zak 7e3729e750 include/fileutils: use O_CLOEXEC for mktemp stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:12:34 +02:00
Karel Zak 2ffad204c0 include/c: add macro UL_CLOEXECSTR
... to make "e" for fopen() portable to systems without O_CLOEXEC.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:11:19 +02:00
Karel Zak 8362545b4a lib/xalloc: fix mamory leak in xgethostname() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 16:08:47 +01:00
Karel Zak 7528fae9e9 include/pathnames: rename _PATH_ADJPATH to _PATH_ADJTIME
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-26 11:45:45 +01:00