Skip to content

Commit fcaef0a

Browse files
committed
[demo.c] Fix silent app failures due to zero exit code even on failures
By convention, an exit status of 0 signifies successful completion, while any non-zero value typically indicates an error or a specific condition. In shell scripting, the exit status of the last executed command can be accessed using the special variable $?. Signed-off-by: Imran Desai <[email protected]>
1 parent c639af2 commit fcaef0a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

demo.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static int keygen(const char *keyname, const char *parm_set) {
388388
if (!aux_filename) {
389389
fprintf( stderr, "Warning: malloc failure writing to aux file\n" );
390390
free(aux);
391-
return 1;
391+
return 0;
392392
}
393393
sprintf( aux_filename, "%s.aux", keyname );
394394

@@ -885,15 +885,15 @@ int main(int argc, char **argv) {
885885
if ((s = check_prefix( argv[i], "seed=" ))) {
886886
if (seedbits) {
887887
printf( "Error: seed specified twice\n" );
888-
return 0;
888+
return 1;
889889
}
890890
seedbits = s;
891891
continue;
892892
}
893893
if ((s = check_prefix( argv[i], "i=" ))) {
894894
if (i_value) {
895895
printf( "Error: i specified twice\n" );
896-
return 0;
896+
return 1;
897897
}
898898
i_value = s;
899899
continue;
@@ -908,53 +908,57 @@ int main(int argc, char **argv) {
908908
}
909909
printf( "Error: unexpected argument after parmset\n" );
910910
usage(argv[0]);
911-
return 0;
911+
return 1;
912912
}
913913
if (!keyname) {
914914
printf( "Error: missing keyname argument\n" );
915915
usage(argv[0]);
916-
return 0;
916+
return 1;
917917
}
918918
if (!seedbits != !i_value) {
919919
printf( "Error: must either specified both seed and i, or neither\n" );
920-
return 0;
920+
return 1;
921921
}
922922

923923
if (!keygen( keyname, parmname )) {
924924
printf( "Error creating keys\n" );
925+
return 1;
925926
}
926927
return 0;
927928
}
928929
if (0 == strcmp( argv[1], "sign" )) {
929930
if (argc < 4) {
930931
printf( "Error: mssing keyname and file argument\n" );
931932
usage(argv[0]);
932-
return 0;
933+
return 1;
933934
}
934935
if (!sign( argv[2], &argv[3] )) {
935936
printf( "Error signing\n" );
937+
return 1;
936938
}
937939
return 0;
938940
}
939941
if (0 == strcmp( argv[1], "verify" )) {
940942
if (argc < 4) {
941943
printf( "Error: mssing keyname and file argument\n" );
942944
usage(argv[0]);
943-
return 0;
945+
return 1;
944946
}
945947
if (!verify( argv[2], &argv[3] )) {
946948
printf( "Error verifying\n" );
949+
return 1;
947950
}
948951
return 0;
949952
}
950953
if (0 == strcmp( argv[1], "advance" )) {
951954
if (argc != 4) {
952955
printf( "Error: mssing amount to device the file\n" );
953956
usage(argv[0]);
954-
return 0;
957+
return 1;
955958
}
956959
if (!advance( argv[2], argv[3] )) {
957960
printf( "Error advancing\n" );
961+
return 1;
958962
}
959963
return 0;
960964
}

0 commit comments

Comments
 (0)