1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
From edb01af9b4789b9c3b908329f6be5819e2cfe954 Mon Sep 17 00:00:00 2001
From: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Date: Mon, 25 Apr 2022 10:59:42 +0300
Subject: [PATCH 03/17] Fix 'unused-result' warnings
This fixes warnings such as:
ignoring return value of 'chdir', declared with attribute warn_unused_result [-Wunused-result]
drm-backend backport from:
https://patchwork.yoctoproject.org/project/yocto/cover/20220425075954.10427-1-vasyl.vavrychuk@opensynergy.com/
Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
---
psplash-systemd.c | 36 +++++++++++++++++++++++++++++++++---
psplash-write.c | 23 ++++++++++++++++++-----
psplash.c | 5 ++++-
3 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/psplash-systemd.c b/psplash-systemd.c
index 840bd4e..dcf7e61 100644
--- a/psplash-systemd.c
+++ b/psplash-systemd.c
@@ -32,6 +32,7 @@ int get_progress(void)
int r;
char buffer[20];
int len;
+ ssize_t written;
/* Connect to the system bus */
r = sd_bus_new(&bus);
@@ -71,11 +72,36 @@ int get_progress(void)
current_progress = progress;
len = snprintf(buffer, 20, "PROGRESS %d", (int)(current_progress * 100));
- write(pipe_fd, buffer, len + 1);
+ written = write(pipe_fd, buffer, len + 1);
+ if (written == -1) {
+ /* EPIPE could mean that psplash detected boot complete sooner
+ then psplash-systemd and exited */
+ if (errno != EPIPE) {
+ perror("write");
+ r = -1;
+ goto finish;
+ }
+ } else if (written < len + 1) {
+ fprintf(stderr, "Wrote %zd bytes, less then expected %d bytes\n",
+ written, len + 1);
+ r = -1;
+ goto finish;
+ }
if (progress == 1.0) {
printf("Systemd reported progress of 1.0, quit psplash.\n");
- write(pipe_fd, "QUIT", 5);
+ written = write(pipe_fd, "QUIT", 5);
+ if (written == -1) {
+ /* EPIPE could mean that psplash detected boot complete
+ sooner then psplash-systemd and exited */
+ if (errno != EPIPE) {
+ perror("write");
+ r = -1;
+ goto finish;
+ }
+ } else if (written < 5)
+ fprintf(stderr, "Wrote %zd bytes, less then expected 5 bytes\n",
+ written);
r = -1;
}
@@ -123,7 +149,11 @@ int main()
if (!rundir)
rundir = "/run";
- chdir(rundir);
+ r = chdir(rundir);
+ if (r < 0) {
+ perror("chdir");
+ goto finish;
+ }
if ((pipe_fd = open (PSPLASH_FIFO,O_WRONLY|O_NONBLOCK)) == -1) {
fprintf(stderr, "Error unable to open fifo");
diff --git a/psplash-write.c b/psplash-write.c
index eee0ea3..16b87e1 100644
--- a/psplash-write.c
+++ b/psplash-write.c
@@ -21,8 +21,10 @@
int main(int argc, char **argv)
{
- char *rundir;
- int pipe_fd;
+ char *rundir;
+ int pipe_fd;
+ size_t count;
+ ssize_t written;
rundir = getenv("PSPLASH_FIFO_DIR");
@@ -35,7 +37,10 @@ int main(int argc, char **argv)
exit(-1);
}
- chdir(rundir);
+ if (chdir(rundir)) {
+ perror("chdir");
+ exit(-1);
+ }
if ((pipe_fd = open (PSPLASH_FIFO,O_WRONLY|O_NONBLOCK)) == -1)
{
@@ -45,8 +50,16 @@ int main(int argc, char **argv)
exit (-1);
}
- write(pipe_fd, argv[1], strlen(argv[1])+1);
+ count = strlen(argv[1]) + 1;
+ written = write(pipe_fd, argv[1], count);
+ if (written == -1) {
+ perror("write");
+ exit(-1);
+ } else if ((size_t)written < count) {
+ fprintf(stderr, "Wrote %zd bytes, less then expected %zu bytes\n",
+ written, count);
+ exit(-1);
+ }
return 0;
}
-
diff --git a/psplash.c b/psplash.c
index 838ac13..62244ba 100644
--- a/psplash.c
+++ b/psplash.c
@@ -264,7 +264,10 @@ main (int argc, char** argv)
if (!rundir)
rundir = "/run";
- chdir(rundir);
+ if (chdir(rundir)) {
+ perror("chdir");
+ exit(-1);
+ }
if (mkfifo(PSPLASH_FIFO, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))
{
--
2.25.1
|