Commit Graph
82 Commits
Author SHA1 Message Date
Joachim Wiberg c1f7bc2bbb Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 11:56:26 +02:00
Joachim Wiberg 92bb0ca399 runbg: new helper function inspired by the Infix project
The runbg() function is a delayed execvp() that has double-forked to the
background (to not create zombies).  It is useful for running commands
in the background for APIs that need to return a reply, e.g. a NETCONF
RPC to reboot the system.

Compared to the original in Infix, this version double forks to reparent
itself to PID 1 (init), closes all open files, including stdio.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 11:00:09 +02:00
Joachim Wiberg 921afdecb4 Minor, indent
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 10:49:25 +02:00
Joachim Wiberg 47b02df823 Minor, spellcheck
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 10:49:13 +02:00
Joachim Wiberg 4dd14dac42 New helper functions to read/write /proc and /sys style files
From the Infix project.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 13:19:05 +02:00
Joachim Wiberg 784a667584 New helper function, fexistf(), made for the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:18:45 +02:00
Joachim Wiberg 1f6ff90d9e New helper function, vfopenf(), inspired by the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:16:58 +02:00
Joachim Wiberg 9eb847e56c New helper function, popenf(), from the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:03:24 +02:00
Joachim Wiberg ac7b4194cf Fix copyfile() regression introduced in 4e9b5c13
Caught in release cycle.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 05:55:48 +02:00
Joachim Wiberg 4e9b5c13c1 copyfile: allow copying empty files to non-existing destination dirs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:17:47 +02:00
Joachim Wiberg d61b847e55 rsync: fix check for missing dst when dst is a directory
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:17:09 +02:00
Joachim Wiberg 90fdcdeb39 rsync: fix return value when copying a single file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:16:50 +02:00
Joachim Wiberg eb3bb94cfa Update changelog and bump version for v2.5.2 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-17 14:19:11 +02:00
Joachim Wiberg 11b9c88732 Add printf format attribute to all vararg functions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-17 14:11:31 +02:00
yangfl 5cdc5736f3 Replace mknod() with creat()
For mknod(), mode must be S_IFIFO otherwise the behaviour is unspecified
according to SUS, and apparently Debian/kFreeBSD is in the hater list.
2022-01-27 00:11:00 +08:00
yangfl 0cda6339a4 Fix fisdir sigfault on Hurd
Apparently Hurd's stat() does not like NULL and will sigfault, this patch takes
care of it.
2022-01-26 02:11:08 +08:00
Joachim Wiberg 67a9b379ba Update comments, also namespace is one word
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:22:38 +01:00
Joachim Wiberg 1c0988b8e2 Fix #18: optional compat symlink lite -> libite/
Default is to create the symlink, to facilitate upgrades.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:22:45 +01:00
Joachim Wiberg 407b8f6dbf Prefix include guards with LIBITE_ to safe guard name space
The tree.h and queue.h include guards must remain so users don't
accidentally get their system queue.h included as well.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:20:53 +01:00
Joachim Wiberg bc72e1c3ad Change -lite include path/name space; lite/*.h -> libite/*.h
First step in fixing issue #18.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:09:55 +01:00
Joachim Wiberg a4ff8cce01 strnlen(): defensive programming, check limit before indexing array
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 16:36:43 +01:00
Joachim Wiberg 12b9196c65 Bump ABI version 5.3.0 -> 5.3.1 according to doc/HACKING.md
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-09 09:21:41 +02:00
Joachim Wiberg a712364d49 tempfile(): use same fallback also when O_TMPFILE is missing
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-06 18:05:45 +02:00
Joachim Wiberg fae83c9be3 Use mkostemp() instead of insecure tmpfile() as fallback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-06 17:51:07 +02:00
Joachim Wiberg 970fa47ecf Update code docs for string functions and macros as well
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 22:30:20 +02:00
Joachim Wiberg 6537b11e34 doc: initial effort to enable doxygen
Framework from libuEv.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 19:08:40 +02:00
Joachim Wiberg 3d2a975f11 Fix issue with tempfile() returning EOPNOTSUPP on Azure
Turns out O_TMPFILE can fail in interesting ways when the underlying
filesystem doesn't support unnamed inodes, e.g. Azure used by GitHub
Actions.  Here's the exact qoute from open(2):

  "O_TMPFILE requires support by the underlying filesystem; only a
  subset of Linux filesystems provide that support.  In the initial
  implementation, support was provided in the ext2, ext3, ext4, UDF,
  Minix, and shmem filesystems.  Support for other filesystems has
  subsequently been added as follows: XFS (Linux 3.15); Btrfs (Linux
  3.16); F2FS (Linux 3.16); and ubifs (Linux 4.9)"

This patch adds a silent fallback to tmpfile() in these cases.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:55:01 +02:00
Joachim Wiberg 990ee6874c Relocate libite.pc.in to src/
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 8e69676943 Increment ABI version 5.2.0 -> 5.3.0
The GNU libtool numbers are just SO confusing.

 - New interfaces (new functions) added/removed/changed: 7 -> 8
 - Interfaces added: 2 -> 3

End result, steps 5.2.0 to 5.3.0, which makes sense.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 09:26:04 +01:00
Joachim Wiberg dc5c4ae36c systemf(): simplify further, exited OK or was signaled
Coverity highlighted a problem with logically dead code from the change
prior that triggered this refactor.  When system() returns we may have
exited either normally or due to a signal.

My reasoning behind systemf() is to allow users to treat external calls
as any other syscall, abstracting away the WIFFOO() macros.  This leaves
us with either the return value of the external program >= 0, or -1 and
errno for everything else.  I.e., if fork() or alloca() fails we may get
ENOMEM and if the program doesn't catch signals properly, EINTR.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:48:09 +01:00
Joachim Wiberg d5c5996f03 Minor, whitespace
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:06:17 +01:00
Joachim Wiberg f5808e557e Add strtrim(), trims leading and trailing white-space from a string
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:05:36 +01:00
Joachim Wiberg d4b554ccdc Add erasef(), formatted version of erase()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 07:08:49 +01:00
Joachim Wiberg 2040569f0a Add touchf(), formatted version of touch()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:39:32 +01:00
Joachim Wiberg 733a7062e9 Minor, whitespace
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:37:05 +01:00
Joachim Wiberg 7ad11a31df touch(): behavioral change, call utimensat() first, then mknod()
Optimize for the case the file exists already.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:35:41 +01:00
Joachim Wiberg 8ce46eb439 systemf(): fix improper handling of WEXITSTATUS()
The call to system() may return -1, e.g. if fork() fails or return
status from execl() cannot be read.  In these cases we should end
immediately and not call WIFEXITED() et al.

Also, WEXITSTATUS() should only be called if WEXITED() returns true.

For details, see system(3) and wait(2).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:32:43 +01:00
Joachim Wiberg 3d695eede5 Update copyright years and author surname
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 09:28:41 +01:00
Joachim Wiberg 9c89daf770 Update changelogs and bump version for v2.3.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:24:30 +01:00
Joachim Nilsson 044c2621ac Add support for truncatef(), formatted truncate() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-06-02 06:56:02 +02:00
Joachim Nilsson d2d0792c06 telnet_open(): Handle ETIMEDOUT in connect()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:20:55 +02:00
Joachim Nilsson 711c59e3a6 telnet: Refactor, rename local variable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:20:55 +02:00
Joachim Nilsson 16ea69adb4 Add support for fremove(), formatted remove() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:18:10 +02:00
Joachim Nilsson d16385415c Simplify va_start/_end handling and return ENOMEM if alloca() fails
Be consistent with errno codes from libite, we already have other APIs
that return ENOMEM if alloca() fails, so let's do the same for these
new ones as well.

Also, simplify va_start()/va_end() handling in these APIs, no point
in the extra complexity before this patch.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:14:56 +02:00
Joachim Nilsson b65175782d Bump ABI version, new APIs added
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 17:38:25 +01:00
Joachim Nilsson c716cc5835 copyfile(): Check return value of fstat(), prevent faulty futimens()
Found by Coverity Scan

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:31:50 +01:00
Joachim Nilsson e81ce85867 rsync(): Fix possible memory leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:31:50 +01:00
Joachim Nilsson 549f325c21 rsync(): Fix variable shadowing, found by clang-tidy
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:31:46 +01:00
Joachim Nilsson f1a1a21569 Add support for systemf(), formatted system() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:32:52 +01:00
Joachim Nilsson 7f3f4df9e9 Add support for fmkpath(), formatted string mkpath()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-11 20:03:03 +01:00