mirror of
https://github.com/troglobit/finit.git
synced 2026-10-11 17:02:42 +07:00
Refactor, wrap write() syscall in new dprint() function
Fixes the GCC warning for unchecked return value from write(): ... ignoring return value of ‘write’, declared with attribute warn_unused_result The new dprint() function wraps write() in a bounded retry-loop that catches EINTR. The length argument is optional computed with strlen() if omitted (zero). Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+5
-5
@@ -316,7 +316,7 @@ static int activate_console(int noclear, int nowait)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!noclear)
|
if (!noclear)
|
||||||
(void)write(STDERR_FILENO, "\e[r\e[H\e[J", 9);
|
dprint(STDERR_FILENO, "\e[r\e[H\e[J", 9);
|
||||||
|
|
||||||
/* Disable ECHO, XON/OFF while waiting for <CR> */
|
/* Disable ECHO, XON/OFF while waiting for <CR> */
|
||||||
if (!tcgetattr(STDIN_FILENO, &orig)) {
|
if (!tcgetattr(STDIN_FILENO, &orig)) {
|
||||||
@@ -340,16 +340,16 @@ static int activate_console(int noclear, int nowait)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)write(STDERR_FILENO, clr, strlen(clr));
|
dprint(STDERR_FILENO, clr, strlen(clr));
|
||||||
(void)write(STDERR_FILENO, msg, strlen(msg));
|
dprint(STDERR_FILENO, msg, strlen(msg));
|
||||||
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\r')
|
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\r')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (fexist(SYNC_STOPPED))
|
if (fexist(SYNC_STOPPED))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
(void)write(STDERR_FILENO, clr, strlen(clr));
|
dprint(STDERR_FILENO, clr, strlen(clr));
|
||||||
(void)write(STDERR_FILENO, cup, strlen(cup));
|
dprint(STDERR_FILENO, cup, strlen(cup));
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-15
@@ -41,9 +41,6 @@
|
|||||||
#define _PATH_LOGIN "/bin/login"
|
#define _PATH_LOGIN "/bin/login"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define print(s) (void)write(STDOUT_FILENO, s, strlen(s))
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read one character from stdin.
|
* Read one character from stdin.
|
||||||
*/
|
*/
|
||||||
@@ -54,7 +51,7 @@ static int readch(char *tty)
|
|||||||
|
|
||||||
st = read(STDIN_FILENO, &ch1, 1);
|
st = read(STDIN_FILENO, &ch1, 1);
|
||||||
if (st == 0) {
|
if (st == 0) {
|
||||||
print("\n");
|
dprint(STDOUT_FILENO, "\n", 0);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,31 +71,31 @@ static void do_parse(char *line, struct utsname *uts, char *tty)
|
|||||||
s0 = line;
|
s0 = line;
|
||||||
for (s = line; *s != 0; s++) {
|
for (s = line; *s != 0; s++) {
|
||||||
if (*s == '\\') {
|
if (*s == '\\') {
|
||||||
(void)write(1, s0, s - s0);
|
dprint(STDOUT_FILENO, s0, s - s0);
|
||||||
s0 = s + 2;
|
s0 = s + 2;
|
||||||
switch (*++s) {
|
switch (*++s) {
|
||||||
case 'l':
|
case 'l':
|
||||||
print(tty);
|
dprint(STDOUT_FILENO, tty, 0);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
print(uts->machine);
|
dprint(STDOUT_FILENO, uts->machine, 0);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
print(uts->nodename);
|
dprint(STDOUT_FILENO, uts->nodename, 0);
|
||||||
break;
|
break;
|
||||||
#ifdef _GNU_SOURCE
|
#ifdef _GNU_SOURCE
|
||||||
case 'o':
|
case 'o':
|
||||||
print(uts->domainname);
|
dprint(STDOUT_FILENO, uts->domainname, 0);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'r':
|
case 'r':
|
||||||
print(uts->release);
|
dprint(STDOUT_FILENO, uts->release, 0);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
print(uts->sysname);
|
dprint(STDOUT_FILENO, uts->sysname, 0);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
print(uts->version);
|
dprint(STDOUT_FILENO, uts->version, 0);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
goto leave;
|
goto leave;
|
||||||
@@ -109,7 +106,7 @@ static void do_parse(char *line, struct utsname *uts, char *tty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
(void)write(1, s0, s - s0);
|
dprint(STDOUT_FILENO, s0, s - s0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -159,7 +156,7 @@ static void do_getty(char *tty, char *name, size_t len)
|
|||||||
while ((ch = readch(tty)) != '\n') {
|
while ((ch = readch(tty)) != '\n') {
|
||||||
if (ch == CTRL('U')) {
|
if (ch == CTRL('U')) {
|
||||||
while (np > name) {
|
while (np > name) {
|
||||||
(void)write(1, "\b \b", 3);
|
dprint(STDOUT_FILENO, "\b \b", 3);
|
||||||
np--;
|
np--;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -215,7 +212,7 @@ int getty(char *tty, speed_t speed, char *term, char *user)
|
|||||||
|
|
||||||
/* Set up TTY, re-enabling ISIG et al. */
|
/* Set up TTY, re-enabling ISIG et al. */
|
||||||
stty(STDIN_FILENO, speed);
|
stty(STDIN_FILENO, speed);
|
||||||
(void)write(STDERR_FILENO, cln, strlen(cln));
|
dprint(STDERR_FILENO, cln, strlen(cln));
|
||||||
|
|
||||||
/* The getty process is responsible for the UTMP login record */
|
/* The getty process is responsible for the UTMP login record */
|
||||||
utmp_set_login(tty, NULL);
|
utmp_set_login(tty, NULL);
|
||||||
|
|||||||
+1
-1
@@ -170,7 +170,7 @@ ssize_t cprintf(const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
for (i = 0; i < num_cons; i++)
|
for (i = 0; i < num_cons; i++)
|
||||||
(void)write(fds[i], buf, size);
|
dprint(fds[i], buf, size);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-1
@@ -70,7 +70,7 @@ void show_progress (pstyle_t style);
|
|||||||
int getty (char *tty, speed_t speed, char *term, char *user);
|
int getty (char *tty, speed_t speed, char *term, char *user);
|
||||||
int sh (char *tty);
|
int sh (char *tty);
|
||||||
|
|
||||||
int stty (int fd, speed_t speed);
|
void stty (int fd, speed_t speed);
|
||||||
speed_t stty_parse_speed(char *baud);
|
speed_t stty_parse_speed(char *baud);
|
||||||
|
|
||||||
void print_banner (const char *heading);
|
void print_banner (const char *heading);
|
||||||
@@ -109,6 +109,24 @@ static inline int create(char *path, mode_t mode, uid_t uid, gid_t gid)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int dprint(int fd, const char *s, size_t len)
|
||||||
|
{
|
||||||
|
size_t loop = 3;
|
||||||
|
int rc = -1;
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
len = strlen(s);
|
||||||
|
|
||||||
|
while (loop--) {
|
||||||
|
rc = write(fd, s, len);
|
||||||
|
if (rc == -1 && errno == EINTR)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
int ismnt (char *file, char *dir, char *mode);
|
int ismnt (char *file, char *dir, char *mode);
|
||||||
int fismnt (char *dir);
|
int fismnt (char *dir);
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -27,6 +27,8 @@
|
|||||||
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
|
#include <helpers.h>
|
||||||
|
|
||||||
/* B0 means; keep kernel default */
|
/* B0 means; keep kernel default */
|
||||||
speed_t stty_parse_speed(char *baud)
|
speed_t stty_parse_speed(char *baud)
|
||||||
{
|
{
|
||||||
@@ -123,10 +125,10 @@ void stty(int fd, speed_t speed)
|
|||||||
tcsetattr(fd, TCSAFLUSH, &term);
|
tcsetattr(fd, TCSAFLUSH, &term);
|
||||||
|
|
||||||
/* Show cursor again, if it was hidden previously */
|
/* Show cursor again, if it was hidden previously */
|
||||||
write(fd, "\033[?25h", 6);
|
dprint(fd, "\033[?25h", 6);
|
||||||
|
|
||||||
/* Enable line wrap, if disabled previously */
|
/* Enable line wrap, if disabled previously */
|
||||||
write(fd, "\033[7h", 4);
|
dprint(fd, "\033[7h", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user