Commit graph

217 commits

Author SHA1 Message Date
Lennart Poettering 0bee65f062 shutdown: during final killing spree also send SIGHUP in addition to SIGTERM to deal with shells
This makes shutdown a bit faster if debug-shell.service is enabled.
2013-11-25 22:10:22 +01:00
Lennart Poettering 28383ba189 bus: add API calls to escape string components of objects paths 2013-11-21 01:03:26 +01:00
Karel Zak 4561be3a64 Remove duplicate includes 2013-11-18 20:28:55 -05:00
Olivier Brunel 8aa5429a4a Resolve /dev/console to the active tty instead of just "tty0"
When resolving /dev/console one would often get "tty0" meaning the active VT.
Resolving to the actual tty (e.g. "tty1") will notably help on boot when
determining whether or not PID1 can output to the console.
2013-11-13 23:22:30 -05:00
Lennart Poettering 477def8097 shutdown: unify handling of reboot() syscall a bit 2013-11-08 19:32:45 +01:00
Lennart Poettering 9588bc3209 Remove dead code and unexport some calls
"make check-api-unused" informs us about code that is not used anymore
or that is exported but only used internally. Fix these all over the
place.
2013-11-08 18:12:45 +01:00
Lennart Poettering 3deadb918f util: add circle to special chars we can draw 2013-11-07 16:53:25 +01:00
Lennart Poettering 74df0fca09 util: unify reading of /proc/cmdline
Instead of individually checking for containers in each user do this
once in a new call proc_cmdline() that read the file only if we are not
in a container.
2013-11-06 03:15:16 +01:00
Tom Gundersen daeb71a36a udev: link-config - move naming policy from udev rules
This introduces a new key NamePolicy, which takes an ordered list of naming
policies. The first successful one is applide. If all fail the value of Name
(if any) is used.

The possible policies are 'onboard', 'slot', 'path' and 'mac'.

This patch introduces a default link file, which replaces the equivalent udev
rule.
2013-10-28 01:18:04 +01:00
Thomas Hindoe Paaboel Andersen 7d9cb4229c typo fix in comment 2013-10-26 22:38:41 +02:00
Tom Gundersen 295edddf5a kerne-command-line: introduce option 'systemd.restore_state'
When set to 0 this will stop tools like the backlight and rfkill tools to
restore state from previous boot. This is useful in case the stored state
is bogus to the extent that it is preventing you from resetting it (e.g.,
the backlight settings cause the screen to be off on boot on a system where
the backlight can not be adjusted directly from the keyboard).
2013-10-19 00:46:10 +02:00
Bastien Nocera a8ccacf534 shared/util: Fix glob_extend() argument
glob_extend() would completely fail to work, or return incorrect
data if it wasn't being passed the current getopt "optarg" variable
as it used the global variable, instead of the passed parameters.
2013-10-14 10:11:33 -04:00
Zbigniew Jędrzejewski-Szmek b47d419c25 Modernization
Fixes minor leak in error path in device.c.
2013-10-13 17:56:54 -04:00
Shawn Landden f405e86de3 util, utf8: make ellipsize take multi-byte characters into account
rename old versions to ascii_*

Do not take into account zerowidth characters, but do consider double-wide characters.
Import needed utf8 helper code from glib.

v3: rebase ontop of utf8 restructuring work

[zj: tweak the algorithm a bit, move new code to separate file]
2013-10-13 17:56:54 -04:00
Dave Reisner 1d5989fd80 shared/util: fix off-by-one error in tag_to_udev_node
Triggered false negatives when encoding a string which needed every
character to be escaped, e.g. "LABEL=/".
2013-10-06 18:29:12 -04:00
Lennart Poettering 51045322c4 nspawn: always copy /etc/resolv.conf rather than bind mount
We were already creating the file if it was missing, and this way
containers can reconfigure the file without running into problems.

This also makes resolv.conf handling more alike to handling of
/etc/localtime, which is also not a bind mount.
2013-10-02 19:45:12 +02:00
Lennart Poettering a3b6fafed4 hashmap: randomize hash functions a bit 2013-10-01 23:11:49 +02:00
Chen Jie c22ceead43 util.c: ignore pollfd.revent for loop_read/loop_write
Let read()/write() report any error/EOF.
2013-10-01 04:49:59 +02:00
Zbigniew Jędrzejewski-Szmek 893fa014de Fix buffer overrun when enumerating files
https://bugs.freedesktop.org/show_bug.cgi?id=69887

Based-on-a-patch-by: Hans Petter Jansson <hpj@copyleft.no>
2013-09-29 15:28:35 +02:00
Dave Reisner 8f6ce71fe7 device-nodes: move device node specific code to own file
In the process, rename udev_encode_string which is poorly named for what
it does. It deals specifically with encoding names that udev creates and
has its own rules: utf8 is valid but some ascii is not (e.g. path
separators), and everything else is simply escaped. Rename it to
encode_devnode_name.
2013-09-19 11:50:34 -04:00
Dave Reisner 22f5f6281f Use udev_encode_string in fstab_node_to_udev_node
Resolves a longstanding bug which caused this function to wrongly
handle (escape) valid utf8 characters.
2013-09-17 16:31:32 -04:00
Zbigniew Jędrzejewski-Szmek 69ab808815 Advertise hibernation only if there's enough free swap
Condition that is checked is taken from upower:
  active(anon) < free swap * 0.98

This is really stupid, because the kernel knows the situation better,
e.g. there could be two swap files, and then hibernation would be
impossible despite passing this check, or the kernel could start
supporting compressed swap and/or compressed hibernation images, and
then this this check would be too stringent. Nevertheless, until
we have something better, this should at least return a true negative
if there's no swap.

Logging of capabilities in the journal is changed to not strip leading
zeros. I consider this more readable anyway.

http://cgit.freedesktop.org/upower/tree/src/up-daemon.c#n613
https://bugzilla.redhat.com/show_bug.cgi?id=1007059
2013-09-13 19:41:52 -04:00
Zbigniew Jędrzejewski-Szmek da2620a5f8 Actually allow tabs in environment files
Fixup for ac4c8d6da8.
2013-09-12 10:03:16 -04:00
Zbigniew Jędrzejewski-Szmek ac4c8d6da8 Allow tabs in environment files
bash allows them, and so should we.

string_has_cc is changed to allow tabs, and if they are not wanted,
they must be now checked for explicitly. There are two other callers,
apart from the env file loaders, and one already checked anyway, and
the other is changed to check.

https://bugs.freedesktop.org/show_bug.cgi?id=68592
https://bugs.gentoo.org/show_bug.cgi?id=481554
2013-09-11 21:58:22 -04:00
Kay Sievers df89481a35 Optimize startswith() to macro
I guess it's easier and cleaner anyway to use simple static inline
functions instead of defines.
2013-08-22 00:52:14 -04:00
Zbigniew Jędrzejewski-Szmek c51cf05646 Rename F_TYPE_CMP() to F_TYPE_EQUAL() 2013-08-20 21:18:43 -04:00
Zbigniew Jędrzejewski-Szmek a6f0104a16 logs-show: limit to 3 lines and use dots if not showing full message
So far, we would show up to 128 bytes from a message, simply
cutting of the rest. With multiline messages, it is quite common
for a message to be longer than that, and this model doesn't really
work anymore.

A new limit is added: up to 3 lines will be shown, unless --full is
used (c.f. first line below).  The limit for bytes is extended to 300
bytes. An ellipsis will always be used, if some form of truncation
occurs. If the tail of the message is cut off, either because of
length or line limit, dots will be shown at the end of the last
line. If this last line is short, the dots will be simply appended. If
the last line is too long for that, it will be ellipsized with dots at
the very end.

Note that the limits are in bytes, not characters, and we suck at
outputting unicode strings (c.f. last three lines below).

Aug 11 10:46:21 fedora python[67]: test message
                                   line
                                   line...
Aug 11 10:50:47 fedora python[76]: test message word word word word word word word word word word word wor...
Aug 11 10:55:11 fedora python[83]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
Aug 11 11:03:21 fedora python[90]: ąąąąąąąąąąąąąąąąąąąąąąąąąąąąąą...
Aug 11 11:03:53 fedora python[97]: aąąąąąąąąąąąąąąąąąąąąąąąąąąąąąą...
Aug 11 11:25:45 fedora python[121]: aąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąąą�...
2013-08-11 18:10:34 -04:00
Lennart Poettering d4ac85c6f6 util: add split_pair() for splitting foo=bar strings 2013-07-18 20:22:29 +02:00
Lennart Poettering dd94c17e7d util: make gcc shut up by passing a 0 mode param to open()
If we pass a variable to open()'s flags parameter it really wants a mode
parameter too, otherwise some gcc version whine. Hence, pass 0 in that
case.
2013-07-17 02:52:41 +02:00
Lennart Poettering 32b2634edf util: make some gcc versions shut up regarding unintialized variable access 2013-07-17 02:48:53 +02:00
Harald Hoyer 6cf2f1d94d util.c:is_locale_utf8(): check, if "C" was set on purpose
If you have a ASCII only terminal, there is no way to set the charmap to
ANSI_X3.4-1968, other than using LC_CTYPE=C.

We don't want to assume a UTF-8 capable terminal in this case and only
do so, if LANG, LC_ALL and LC_CTYPE are unset.
2013-07-16 19:03:23 +02:00
Shawn Landden 3a83211689 journal: add logging of effective capabilities _CAP_EFFECTIVE
I think this is the most important of the capabilities bitmasks to log.
2013-07-16 04:27:04 +02:00
Frederic Crozat dac70dc777 util: recognize 'ncp' as an alias to 'ncpfs'
ncp is also used for Netware mount point, recognize it as such. Fixes
https://bugzilla.novell.com/show_bug.cgi?id=828905.
2013-07-16 00:10:48 +02:00
Zbigniew Jędrzejewski-Szmek e79f68d11d journald: drop (deleted) from _EXE= fields
The kernel adds those when the file is deleted,
but we don't really care if the file is still there
or not. The downside is that if the filename ends
in ' (deleted)', this part of the filename will be
removed. Too bad.
2013-07-02 23:06:22 -04:00
Zbigniew Jędrzejewski-Szmek 8d98da3f11 journalctl: allow the user to specify the file(s) to use
This is useful for debugging and feels pretty natural. For example
answering the question "is this big .journal file worth keeping?"
is made easier.
2013-06-10 10:10:07 -04:00
Zbigniew Jędrzejewski-Szmek b32ff51219 Properly check for overflow in offsets 2013-06-10 10:10:06 -04:00
Daniel Wallace 7085053a43 Allow for the use of @ in remote host calls
Without this you have to use %40 with the -H flag because dbus doesn't
like the @ sign being unescaped.
2013-06-09 18:26:41 -04:00
Zbigniew Jędrzejewski-Szmek 1058cbf2ad systemctl: suggest 'systemctl daemon-reload' without --system
--system is default anyway, and some poor user might type 9
characters without needing to.
2013-05-30 20:44:41 -04:00
Lennart Poettering e724b0639c hostname: only suppress setting of pretty hostname if it is non-equal to the static hostname and if the static hostname is set, too
https://bugzilla.redhat.com/show_bug.cgi?id=957814
2013-05-07 20:56:41 +02:00
Zbigniew Jędrzejewski-Szmek 19adb8a320 systemd-sleep: add support for freeze and standby
A new config file /etc/systemd/sleep.conf is added.
It is parsed by systemd-sleep and logind. The strings written
to /sys/power/disk and /sys/power/state can be configured.
This allows people to use different modes of suspend on
systems with broken or special hardware.

Configuration is shared between systemd-sleep and logind
to enable logind to answer the question "can the system be
put to sleep" as correctly as possible without actually
invoking the action. If the user configured systemd-sleep
to only use 'freeze', but current kernel does not support it,
logind will properly report that the system cannot be put
to sleep.

https://bugs.freedesktop.org/show_bug.cgi?id=57793
https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=7e73c5ae6e7991a6c01f6d096ff8afaef4458c36
http://lists.freedesktop.org/archives/systemd-devel/2013-February/009238.html

SYSTEM_CONFIG_FILE and USER_CONFIG_FILE defines were removed
since they were used in only a few places and with the
addition of /etc/systemd/sleep.conf it becomes easier to just
append the name of each file to the dir name.
2013-05-06 22:51:57 +02:00
Zbigniew Jędrzejewski-Szmek 44a6b1b680 Add __attribute__((const, pure, format)) in various places
I'm assuming that it's fine if a _const_ or _pure_ function
calls assert. It is assumed that the assert won't trigger,
and even if it does, it can only trigger on the first call
with a given set of parameters, and we don't care if the
compiler moves the order of calls.
2013-05-02 22:52:09 -04:00
Lennart Poettering aa96c6cb44 id128: when taking user input for a 128bit ID, validate syntax
Also, always accept both our simple hexdump syntax and UUID syntax.
2013-04-30 08:36:01 -03:00
Lennart Poettering d6dd604b55 util: rework safe_atod() to be locale-independent
This adds some syntactic sugar with a macro RUN_WITH_LOCALE() that reset
the thread-specific locale temporarily.
2013-04-25 00:05:14 -03:00
Zbigniew Jędrzejewski-Szmek 31885cd5e3 core/killall: use procfs_file_alloca 2013-04-19 10:10:41 -04:00
Harald Hoyer bdd29249a8 Reintroduce f_type comparison macro
This reverts commit 4826f0b7b5.

Because statfs.t_type can be int on some architecures, we have to cast
the const magic to the type, otherwise the compiler warns about
signed/unsigned comparison, because the magic can be 32 bit unsigned.

statfs(2) man page is also wrong on some systems, because
f_type is not __SWORD_TYPE on some architecures.

The following program:

int main(int argc, char**argv)
{
        struct statfs s;
        statfs(argv[1], &s);

	printf("sizeof(f_type) = %d\n", sizeof(s.f_type));
	printf("sizeof(__SWORD_TYPE) = %d\n", sizeof(__SWORD_TYPE));
	printf("sizeof(long) = %d\n", sizeof(long));
	printf("sizeof(int) = %d\n", sizeof(int));
	if (sizeof(s.f_type) == sizeof(int)) {
		printf("f_type = 0x%x\n", s.f_type);
	} else {
                printf("f_type = 0x%lx\n", s.f_type);
	}
        return 0;
}

executed on s390x gives for a btrfs:

sizeof(f_type) = 4
sizeof(__SWORD_TYPE) = 8
sizeof(long) = 8
sizeof(int) = 4
f_type = 0x9123683e
2013-04-19 13:59:07 +02:00
Harald Hoyer 4826f0b7b5 Revert f_type fixups
This reverts commit a858b64ddd.
This reverts commit aea275c431.
This reverts commit fc6e6d245e.
This reverts commit c4073a27c5.
This reverts commit cddf148028.
This reverts commit 8c68a70170.

The constants are now casted to __SWORD_TYPE, which should resolve the
compiler warnings about signed vs unsigned.

After talking to Kay, we concluded:

This should be fixed in the kernel, not worked around in userspace tools.

Architectures cannot use int and expect magic constants lager than INT_MAX
to work correctly. The kernel header needs to be fixed.

Even coreutils cannot handle it:
  #define RAMFS_MAGIC  0x858458f6
  # stat -f -c%t /
  ffffffff858458f6

  #define BTRFS_SUPER_MAGIC 0x9123683E
  # stat -f -c%t /mnt
  ffffffff9123683e

Although I found the perfect working macro to fix the thing :)

        __extension__ ({                                                \
                        bool _ret = false;                              \
                        switch(f) { case c: _ret=true; };               \
                        ( _ret );                                       \
                })
2013-04-18 15:01:55 +02:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Harald Hoyer aea275c431 rename CMP_F_TYPE to F_TYPE_CMP 2013-04-18 08:06:55 +02:00
Harald Hoyer fc6e6d245e Add ugly CMP_F_TYPE() macro
On some architectures (like s390x) the kernel has the type int for
f_type, but long in userspace.
Assigning the 32 bit magic constants from linux/magic.h to the 31 bit
signed f_type in the kernel, causes f_type to be negative for some
constants.
glibc extends the int to long for those architecures in 64 bit mode, so
the negative int becomes a negative long, which cannot be simply
compared to the original magic constant, because the compiler would
automatically cast the constant to long.
To workaround this issue, we also compare to the (int)MAGIC value in a
macro. Of course, we could do #ifdef with the architecure, but it has to
be maintained, and the magic constants are 32 bit anyway.

Someday, when the int is unsigned or long for all architectures, we can
remove this macro again. Until then, keep it as simple as it can be.
2013-04-18 07:34:25 +02:00
Harald Hoyer c4073a27c5 fixup for cddf148028
Instead of making a type up, just use __SWORD_TYPE, after reading
statfs(2).

Too bad, this does not fix s390x because __SWORD_TYPE is (long int) and
the kernel uses (int) to fill in the field!!!!!!
2013-04-17 19:00:50 +02:00