summaryrefslogtreecommitdiff
path: root/src/shared/util.c
AgeCommit message (Collapse)Author
2015-02-11Minor cleanupsAnthony G. Basile
2015-02-11udev: event - move renaming of udev_device to libudevTom Gundersen
This is not exposed in the public API. We want to simplify the internal libudev-device API as much as possible so that it will be simpler to rip the whole thing out in the future. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2015-01-25util: Add some missing hidden_file() suffixesMartin Pitt
dpkg itself also uses *.dpkg-dist, while .dpkg-{bak,backup,remove} are being used by dpkg-maintscript-helper. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2015-01-25src/shared/util.{c,h}: fix build when mkostemp is not supportedPeter Seiderer
Not all instance of mkostemp were protected with #ifndef HAVE_DECL_MKOSTEMP. We fix this for the definition of the wrapper mkostemp_safe() in the c file and in the header. Signed-off-by: Peter Seiderer <ps.report@gmx.net> Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-29util: fix strict aliasing violations in use of struct inotify_event v5Shawn Paul Landden
There is alot of cleanup that will have to happen to turn on -fstrict-aliasing, but I think our code should be "correct" to the rule. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20util: rename ignore_file() to hidden_file()Lennart Poettering
hidden_file() is a bit more precise, since dot files usually shouldn't be ignored, but certainly be considered hidden. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20util: when creating temporary filename for atomic creation of files, add an ↵Lennart Poettering
extra "#" to the name That way, we have a simple, somewhat reliable way to detect such temporary files, by simply checking if they start with ".#". Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20Treat a trailing backslash as an errorZbigniew Jędrzejewski-Szmek
Commit a2a5291b3f5 changed the parser to reject unfinished quoted strings. Unfortunately it introduced an error where a trailing backslash would case an infinite loop. Of course this must fixed, but the question is what to to instead. Allowing trailing backslashes and treating them as normal characters would be one option, but this seems suboptimal. First, there would be inconsistency between handling of quoting and of backslashes. Second, a trailing backslash is most likely an error, at it seems better to point it out to the user than to try to continue. Updated rules: ExecStart=/bin/echo \\ → OK, prints a backslash ExecStart=/bin/echo \ → error ExecStart=/bin/echo "x → error ExecStart=/bin/echo "x"y → error Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20src/shared/util.c: fix tempfn_xxxxxx()Anthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20src/shared/util.c: follow upstream on tempfn_xxxxxx()Lennart Poettering
Upstream change the behaviour of tempfn_xxxxxx() to make the following work: # systemd-nspawn -xb -D / -M foobar in commit c4e34a612c81266773cf8358cb38a43d2e43474e. We have no reason not to follow that change even though eudev has nothing to do with nspawn. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20util: minor simplification for loop_write() and loop_read()Lennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-20util: when using basename() for creating temporary files, verify the ↵Lennart Poettering
resulting name is actually valid Also, rename filename_is_safe() to filename_is_valid(), since it actually does a full validation for what the kernel will accept as file name, it's not just a heuristic. NOTE: eudev doesn't have filename_is_safe() -- AGB Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-04util: don't shadow variableThomas Hindoe Paaboel Andersen
environ is already defined in unistd.h Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-01treewide: introduce UID_INVALID (and friends) as macro for (uid_t) -1Lennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-12-01treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt
If the format string contains %m, clearly errno must have a meaningful value, so we might as well use log_*_errno to have ERRNO= logged. Using: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/' Plus some whitespace, linewrap, and indent adjustments. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-11-28util: add function getting proc environJakub Filak
On the contrary of env, the added function returns all characters cescaped, because it improves reproducibility. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-11-28util: skip incomplete ucred information in getpeersec()Lennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-11-14src/shared/util.{c,h}: import needed functions from upstreamAnthony G. Basile
2014-11-14util: simplify proc_cmdline() to reuse get_process_cmdline()Lennart Poettering
Also, make all parsing of the kernel cmdline non-fatal. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-11-14condition: unify condition logic in one fileLennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-31util: don't block on getrandom()Lennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-31util: make use of the new getrandom() syscall if it is available when ↵Lennart Poettering
needing entropy Doesn't require an fd, and could be a bit faster, so let's make use of it, if it is available. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-30util: unify how we see srand()Lennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-26label: move is_dir() to util.cLennart Poettering
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-13src/shared/util.c: remove unneeded error check, following upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-13src/shared/util.c: final cosmetic changeAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-13src/shared/util.c: more cosmetic changesAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-10-13src/shared/util.c: cosmetic changes to more easily follow upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-09-18src/shared: import upstream code needed for recent commitsAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-22util: change return value of startswith() to non-constLennart Poettering
This way we can use it on non-const strings, and don't end up with a const'ified result. This is similar to libc's strstr() which also takes a const string but returns a non-const one. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-14src/shared: import more code cleanups from upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-14src/shared: import many code cleanups from upstreamAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2014-08-05src/shared: refactor shared codeAnthony G. Basile
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
2012-11-15Isolation of udev code from remaining systemdAnthony G. Basile
This commit is a first attempt to isolate the udev code from the remaining code base. It intentionally does not modify any files but purely delete files which, on a first examination, appear to not be needed. This is a sweeping commit which may easily have missed needed code. Files can be retrieved by doing a checkout from the previous commit: git checkout 2944f347d0 -- <filename>
2012-11-14util: add strreplace() to replace a substring by another stringLennart Poettering
2012-11-12util: nicer tree drawingsMichal Schmidt
Draw trees more similar to pstree/findmnt/lsblk/...
2012-11-04shared: add is_efiboot()Kay Sievers
2012-11-02util : fallback to plain ASCII drawing if locale is not UTF-8Michal Schmidt
When printing cgroup and sysfs hierarchies, avoid using UTF-8 box drawing characters if the locale is not UTF-8. https://bugzilla.redhat.com/show_bug.cgi?id=871153
2012-11-02util: add is_locale_utf8()Michal Schmidt
journalctl and vconsole-setup both implement utf8 locale detection. Let's have a common function for it. The next patch will add another use.
2012-10-30shared, core: do not always accept numbers in string lookupsMichal Schmidt
The behaviour of the common name##_from_string conversion is surprising. It accepts not only the strings from name##_table but also any number that falls within the range of the table. The order of items in most of our tables is an internal affair. It should not be visible to the user. I know of a case where the surprising numeric conversion leads to a crash. We will allow the direct numeric conversion only for the tables where the mapping of strings to numeric values has an external meaning. This holds for the following lookup tables: - netlink_family, ioprio_class, ip_tos, sched_policy - their numeric values are stable as they are defined by the Linux kernel interface. - log_level, log_facility_unshifted - the well-known syslog interface. We allow the user to use numeric values whose string names systemd does not know. For instance, the user may want to test a new kernel featuring a scheduling policy that did not exist when his systemd version was released. A slightly unpleasant effect of this is that the name##_to_string conversion cannot return pointers to constant strings anymore. The strings have to be allocated on demand and freed by the caller.
2012-10-30shared, libsystemd-daemon: check for empty strings in strto*l conversionsMichal Schmidt
strtol() and friends may set EINVAL if no conversion was performed, but they are not required to do so. In practice they don't. We need to check for it. https://bugzilla.redhat.com/show_bug.cgi?id=870577
2012-10-29util: improve overflow checksMichal Schmidt
commit 49371bb fixed the observed division by zero, but missed another occurrence of the same bug. It was also not the optimal fix. We can simply make the divisor a constant by swapping it with the compared value.
2012-10-29util: avoid divide by zero FPEDave Reisner
In early userspace, if kernel initialization happens extremely quickly, a call to systemd-timestamp can potentially result in division by zero. Ensure that the check in timespec_load, which only makes sense if tv_sec is greater than zero, is guarded by this condition.
2012-10-28util: fix possible integer overflowsMichal Sekletar
2012-10-28logind: support for hybrid sleep (i.e. suspend+hibernate at the same time)Lennart Poettering
2012-10-27util: return the remaining string in startswith()Lennart Poettering
2012-10-25udev: hwdb - remove run_onceKay Sievers
2012-10-22util: add (x)bsearch_r(), the missing counterpart of qsort_r()Kay Sievers
2012-10-19util: change endswith() to return a pointer to the suffixLennart Poettering
2012-10-19util: unify line caching and column cachingLennart Poettering