diff mbox series

[29/41] http-backend.c: use the stdlib EXIT_SUCCESS or EXIT_FAILURE exit status

Message ID 20220321225523.724509-30-gitter.spiros@gmail.com (mailing list archive)
State New, archived
Headers show
Series use the stdlib EXIT_SUCCESS or EXIT_FAILURE exit status | expand

Commit Message

Elia Pinto March 21, 2022, 10:55 p.m. UTC
The C standard specifies two constants, EXIT_SUCCESS and  EXIT_FAILURE, that may
be  passed  to exit() to indicate successful or unsuccessful termination,
respectively. The value of status in exit(status) may be EXIT_SUCCESS,
EXIT_FAILURE, or any other value, though only the least significant 8 bits (that
is, status & 0377) shall be available to a waiting parent proces. So exit(-1)
return 255.

Use the C standard EXIT_SUCCESS and EXIT_FAILURE to indicate the program exit
status instead of "0" or "1", respectively. In <stdlib.h> EXIT_FAILURE has the
value "1": use EXIT_FAILURE even if the program uses exit(-1), ie 255, for
consistency.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 http-backend.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/http-backend.c b/http-backend.c
index 81a7229ece..932d92d70b 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -137,7 +137,7 @@  static NORETURN void not_found(struct strbuf *hdr, const char *err, ...)
 	if (err && *err)
 		vfprintf(stderr, err, params);
 	va_end(params);
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 
 __attribute__((format (printf, 2, 3)))
@@ -153,7 +153,7 @@  static NORETURN void forbidden(struct strbuf *hdr, const char *err, ...)
 	if (err && *err)
 		vfprintf(stderr, err, params);
 	va_end(params);
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 
 static void select_getanyfile(struct strbuf *hdr)
@@ -488,7 +488,7 @@  static void run_service(const char **argv, int buffer_input)
 	cld.clean_on_exit = 1;
 	cld.wait_after_clean = 1;
 	if (start_command(&cld))
-		exit(1);
+		exit(EXIT_FAILURE);
 
 	close(1);
 	if (gzipped_request)
@@ -501,7 +501,7 @@  static void run_service(const char **argv, int buffer_input)
 		close(0);
 
 	if (finish_command(&cld))
-		exit(1);
+		exit(EXIT_FAILURE);
 }
 
 static int show_text_ref(const char *name, const struct object_id *oid,
@@ -628,7 +628,7 @@  static void check_content_type(struct strbuf *hdr, const char *accepted_type)
 			"Expected POST with Content-Type '%s',"
 			" but received '%s' instead.\n",
 			accepted_type, actual_type);
-		exit(0);
+		exit(EXIT_SUCCESS);
 	}
 }
 
@@ -668,7 +668,7 @@  static NORETURN void die_webcgi(const char *err, va_list params)
 		hdr_nocache(&hdr);
 		end_headers(&hdr);
 	}
-	exit(0); /* we successfully reported a failure ;-) */
+	exit(EXIT_SUCCESS); /* we successfully reported a failure ;-) */
 }
 
 static int die_webcgi_recursing(void)