Commit Graph
24 Commits
Author SHA1 Message Date
Joachim Wiberg fcb8ec9967 Refactor, factor out and export memsz() util function
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:30:52 +01:00
Joachim Wiberg 6e24f2ff13 echo(): refactor and rename helper function -> fnwrite()
More often than not, the file to write to in sysfs changes rather than
the value.  This patch changes echo() into a fnwrite(), flipping what
is vsnprintf()'ed, and adds a stupid str() function that converts any
value (float/int/double/uint64_t) to a static string buffer.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-18 18:25:11 +01:00
Joachim Wiberg 74d715243c sanitize(): avoid strlen() to check string for NUL termination
The strlen() function can easiliy go out of bounds.  Use memchr()
instead, we have the max buffer len as argument anyway.

Also fix call to sanitize() which used wrong length.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-18 18:23:50 +01:00
Joachim Wiberg 4bcfd606b4 Refactor screen_init(), use methods developed in pimd project
- Refactor screen_init()
  - use native impl. of TTY probing from pimd project
    - check if TIOCWINSZ works
    - check if we're running in watch(1), for initctl
  - check if ANSI goto(999,999) escape seq. works (invasive)
  - fallback to 80x24
- Drop screen_exit()
- Rename screen_init() to get_width(), for now, matching pimd
- Relocate call in main() to banner(), first fn to write to TTY

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:23:31 +01:00
Joachim Wiberg d9b705ab98 Runtime detection of working UTMP/WTMP support in system
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:17:15 +01:00
Joachim Wiberg a5714a058c Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:07:03 +01:00
Joachim Wiberg 24a78d3246 Update copyright years and author last name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2020-09-02 23:38:11 +02:00
Jacques de Laval 920382518f Switch to using nanosleep in favour of sleep
The remaining sleep time returned by sleep is not accurate enough to be
used as a means to achieve "signal safe"-sleep. nanosleep can be used
in similar fashion instead and is granular enough for our purposes.

This issue was identified during reboot, when Finit is bombarded with
SIGCHLD, aborting the sleep that we do to give daemons a chance to shut
down gracefully. The total delay ended up being less than a second when
in fact two seconds were the intended delay.
2020-01-30 15:39:46 +01:00
Joachim Nilsson 55c49a0bf0 Sanitize job[:id] tuple read from UNIX socket using a regex
This is a really tight check for a single "job[:id]" tuple, not much
escapes it, Coverity should be a lot more happy about our addressing
CWE-20 with this one.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson 338c358a75 Defensive programming, check bounds of loop variable first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson 6a1082a947 New helper function: echo(), like shell echo but for C
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 10:33:00 +01:00
Joachim Nilsson ddf1bce642 Add screen_exit() fn to restore screen defaults in debug mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 09:31:44 +01:00
Joachim Nilsson f11ebb0046 New function, strtobytes(), allows k/M/G ISO size modifiers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 19:42:33 +01:00
Joachim Nilsson b5e260b9e0 Minor refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 18:30:41 +01:00
Joachim Nilsson dc5b1a5980 Increase size of intermediate buffers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 12:19:51 +01:00
Joachim Nilsson f6fa576270 New functions: jiffies() and uptime(), implemented with sysinfo()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 18:28:29 +01:00
Joachim Nilsson 44007c86f2 initctl: Fix problem with start/stop using job ID
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-24 08:51:50 +01:00
Joachim Nilsson 6a2911223d Fix screen_init() regression introduced in a6290da
A simple missing semicolon caused initscr() to not be called properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:26:45 +01:00
Joachim Nilsson a6290da210 screen_init(): Verify that STDOUT is a TTY
Before we call screen_init(), which in turn calls libite:initscr(),
which in turn does a lot of tcgetattr() and termios to STDOUT to figure
out the size, we need to check that we're not backgrounded, or don't
actually have a TTY.  Problem reported by @wkz

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:16:51 +02:00
Joachim Nilsson 14ee218443 Refactor, use libite (-lite) version of initscr()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 16:25:22 +02:00
Joachim Nilsson 0b43d0dc70 Refactor screen_init(), preparing for migration to libite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:00:27 +02:00
Joachim Nilsson be6f0de0df Add util.c:screen_init() to probe screen size once per boot
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 20:58:43 +02:00
Joachim Nilsson 90793c71a2 util: Import screen_width() developed for the SMCRoute project
This patch introduces the screen_width() method from the SMCRoute
project.  The code is hereby also available under MIT/X11.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:53:19 +02:00
Joachim Nilsson fff68b7b06 Relocate source files to an src/ subdirectory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:31:02 +01:00