@@ -152,37 +152,28 @@ static const gchar description[] =
152
152
static int
153
153
__open_unix_client (const char * path )
154
154
{
155
- int sock ;
156
- struct sockaddr_un local = {};
155
+ struct sockaddr_un local = {0 };
157
156
158
157
if (!path || strlen (path ) >= sizeof (local .sun_path )) {
159
158
errno = EINVAL ;
160
159
return -1 ;
161
160
}
161
+ local .sun_family = AF_UNIX ;
162
+ g_strlcpy (local .sun_path , path , sizeof (local .sun_path ));
162
163
163
- /* Create ressources to monitor */
164
- sock = socket (PF_UNIX , SOCK_STREAM , 0 );
164
+ int sock = socket (PF_UNIX , SOCK_STREAM , 0 );
165
165
if (sock < 0 )
166
166
return -1 ;
167
167
168
- /* Bind to file */
169
- local .sun_family = AF_UNIX ;
170
- g_strlcpy (local .sun_path , path , sizeof (local .sun_path )- 1 );
171
-
172
- if (-1 == connect (sock , (struct sockaddr * )& local , sizeof (local )))
173
- goto label_error ;
174
-
175
- errno = 0 ;
176
- return sock ;
177
-
178
- label_error :
179
- if (sock >= 0 ) {
180
- typeof (errno ) errsav ;
181
- errsav = errno ;
168
+ if (-1 == connect (sock , (struct sockaddr * )& local , sizeof (local ))) {
169
+ int errsav = errno ;
182
170
close (sock );
183
171
errno = errsav ;
172
+ return -1 ;
184
173
}
185
- return -1 ;
174
+
175
+ errno = 0 ;
176
+ return sock ;
186
177
}
187
178
188
179
static gint
@@ -223,8 +214,7 @@ static size_t
223
214
get_longest_key (GList * all_jobs )
224
215
{
225
216
size_t maxlen = 4 ;
226
- GList * l ;
227
- for (l = all_jobs ; l ;l = l -> next ) {
217
+ for (GList * l = all_jobs ; l ;l = l -> next ) {
228
218
struct child_info_s * ci = l -> data ;
229
219
size_t len = strlen (ci -> key );
230
220
if (len > maxlen )
@@ -233,36 +223,18 @@ get_longest_key(GList *all_jobs)
233
223
return maxlen ;
234
224
}
235
225
236
- static size_t
237
- my_chomp (gchar * str )
238
- {
239
- gchar c ;
240
- size_t len ;
241
-
242
- len = strlen (str );
243
- while (len && (c = str [len - 1 ]) && g_ascii_isspace (c ))
244
- str [-- len ] = '\0' ;
245
- return len ;
246
- }
247
-
248
226
static void
249
227
unpack_line (gchar * str , gchar * * start , int * code )
250
228
{
251
- gchar c , * p = NULL ;
252
-
253
229
* start = str ;
254
230
* code = EINVAL ;
255
- if (!str || !* str )
256
- return ;
257
- if (!my_chomp (str ))
231
+ if (!str )
258
232
return ;
233
+ str = g_strstrip (str );
234
+ gchar * p = NULL ;
259
235
* code = g_ascii_strtoll (str , & p , 10 );
260
-
261
- if (p ) {
262
- while ((c = * p ) && g_ascii_isspace (c ))
263
- p ++ ;
264
- * start = p ;
265
- }
236
+ if (p )
237
+ * start = g_strchug (p );
266
238
}
267
239
268
240
static GList *
@@ -272,10 +244,8 @@ read_services_list(FILE *in_stream)
272
244
273
245
while (!feof (in_stream ) && !ferror (in_stream )) {
274
246
if (NULL != fgets (line , sizeof (line ), in_stream )) {
275
-
276
- (void ) my_chomp (line );
277
-
278
- gchar * * tokens = g_strsplit_set (line , " \t\r\n" , 15 );
247
+ gchar * l = g_strstrip (line );
248
+ gchar * * tokens = g_strsplit_set (l , " \t\r\n" , 15 );
279
249
if (tokens ) {
280
250
if (g_strv_length (tokens ) == 15 ) {
281
251
struct child_info_s ci ;
@@ -309,10 +279,8 @@ read_services_list(FILE *in_stream)
309
279
static void
310
280
dump_as_is (FILE * in_stream , void * udata )
311
281
{
312
- int code ;
313
- gchar * start ;
314
282
gboolean first = TRUE;
315
- struct dump_as_is_arg_s * dump_args ;
283
+ struct dump_as_is_arg_s * dump_args = udata ;
316
284
317
285
FORMAT format_t = parse_format (format );
318
286
@@ -324,16 +292,14 @@ dump_as_is(FILE *in_stream, void *udata)
324
292
else
325
293
kw = & KEYWORDS_NORMAL ;
326
294
327
-
328
- dump_args = udata ;
329
-
330
295
print_header (format_t );
331
296
332
297
while (!feof (in_stream ) && !ferror (in_stream )) {
333
298
bzero (line , sizeof (line ));
334
299
if (NULL != fgets (line , sizeof (line ), in_stream )) {
335
- start = NULL ;
336
- (void )unpack_line (line , & start , & code );
300
+ int code = 0 ;
301
+ gchar * start = NULL ;
302
+ unpack_line (line , & start , & code );
337
303
338
304
if (dump_args ) {
339
305
if (code == 0 || code == EALREADY )
0 commit comments