UPSCLI_READLINE(3)

πŸ“¦
version 2.8.5 Β· 4 versions
, in arch rolling

πŸ’œ UPSCLI_READLINE β€” bestie edition πŸ’œ

okay so this is a page from the NUT Manual, and it's literally all about your new fave trio of functions: upscli_readline, upscli_readline_timeout, and upscli_readline_timeout_may_disconnect 🫢


✨ NAME ✨

upscli_readline, upscli_readline_timeout, upscli_readline_timeout_may_disconnect β€” the girlies that read a single response from a UPS πŸ’… like, one (1) line, that's the whole job, and they ate.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <upsclient.h>
#include <time.h> /* or <sys/time.h> on some platforms */

int upscli_readline(UPSCONN_t *ups, char *buf, size_t buflen);

int upscli_readline_timeout(UPSCONN_t *ups, char *buf, size_t buflen,
        const time_t timeout);

int upscli_readline_timeout_may_disconnect(UPSCONN_t *ups,
        char *buf, size_t buflen, const time_t timeout,
        int may_disconnect);

just look at them. iconic signatures. no notes πŸ’–


🌸 DESCRIPTION 🌸

okay so picture this: upscli_readline() and upscli_readline_timeout() both take the pointer ups, which points at a UPSCONN_t state structure β€” that's your connection's whole vibe holder β€” and then they receive a single line from the server, and copy up to buflen bytes of that response into the buffer buf. lowkey simple, highkey important πŸ”₯

ngl some parsing happens during reception, like while the string is coming in. in particular, ERR messages from upsd(8) get detected, and when that happens this function will return -1. so yeah, error energy detected = -1, periodt πŸ’€

now the tea on the difference between the three functions πŸŽ€ upscli_readline_timeout() lets the caller decide the amount of time (timeout seconds) after which it should give up and return β€” you're the main character, you pick the number, slay. whereas upscli_readline() does not offer this freedom 😭 and instead uses the NUT default network timeout, which is 5 seconds. both of these disconnect upon errors, no cap.

and then upscli_readline_timeout_may_disconnect() further allows you to enable or disable such disconnections, so it's giving "options, options, options" ✨ iykyk.


⭐ RETURN VALUE ⭐

  • upscli_readline() and upscli_readline_timeout() return 0 on success πŸ’–
  • or -1 if an error occurs πŸ™ˆ

that's it, that's the whole glow-up.


🌈 SEE ALSO 🌈

go read those next bestie, they're all lowkey connected 🧚


a lil warning-aside from me to you: remember that upscli_readline() has zero timeout freedom (5 sec default, forever, always) and that both it and upscli_readline_timeout() disconnect upon errors β€” if you don't want the disconnect, upscli_readline_timeout_may_disconnect() is your girl πŸ’…

omg and before i forget β€” this whole page is from Network UPS Tools 2.8.5, dated 06/21/2026, and that's the official NUT Manual energy right there πŸ‘‘ stay safe out there, keep your connections ssl'd and your buffers sized πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: nut 2.8.5-2 Β· GPL-2.0-or-later AND GPL-3.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms