All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Kralevich <nnk@google.com>
To: selinux@tycho.nsa.gov
Subject: [PATCH 2/2] secilc: better error handling
Date: Mon, 24 Sep 2018 11:10:52 -0700	[thread overview]
Message-ID: <20180924181052.130507-2-nnk@google.com> (raw)
In-Reply-To: <20180924181052.130507-1-nnk@google.com>

Fix a situation where the secilc command line tool could return success
even though the compilation failed.

  $ secilc /dev/null -o /dev/null -f /dev/null
  Failure reading file: /dev/null
  $ echo $?
  0

Signed-off-by: Nick Kralevich <nnk@google.com>
---
 secilc/secilc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/secilc/secilc.c b/secilc/secilc.c
index e1347205..ad6862ba 100644
--- a/secilc/secilc.c
+++ b/secilc/secilc.c
@@ -257,6 +257,7 @@ int main(int argc, char *argv[])
 		rc =3D stat(argv[i], &filedata);
 		if (rc =3D=3D -1) {
 			fprintf(stderr, "Could not stat file: %s\n", argv[i]);
+			rc =3D SEPOL_ERR;
 			goto exit;
 		}
 		file_size =3D filedata.st_size;
@@ -265,6 +266,7 @@ int main(int argc, char *argv[])
 		rc =3D fread(buffer, file_size, 1, file);
 		if (rc !=3D 1) {
 			fprintf(stderr, "Failure reading file: %s\n", argv[i]);
+			rc =3D SEPOL_ERR;
 			goto exit;
 		}
 		fclose(file);
@@ -345,11 +347,13 @@ int main(int argc, char *argv[])
=20
 	if (file_contexts =3D=3D NULL) {
 		fprintf(stderr, "Failed to open file_contexts file\n");
+		rc =3D SEPOL_ERR;
 		goto exit;
 	}
=20
 	if (fwrite(fc_buf, sizeof(char), fc_size, file_contexts) !=3D fc_size) =
{
 		fprintf(stderr, "Failed to write file_contexts file\n");
+		rc =3D SEPOL_ERR;
 		goto exit;
 	}
=20
--=20
2.19.0.444.g18242da7ef-goog

  reply	other threads:[~2018-09-24 18:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-24 18:10 [PATCH 1/2] whitespace and spelling cleanup Nick Kralevich
2018-09-24 18:10 ` Nick Kralevich [this message]
2018-09-24 18:58   ` [PATCH 2/2] secilc: better error handling William Roberts
2018-09-24 18:55 ` [PATCH 1/2] whitespace and spelling cleanup William Roberts
2018-09-25 15:05   ` William Roberts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180924181052.130507-2-nnk@google.com \
    --to=nnk@google.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.